gpt4 book ai didi

javascript - 使卡片样式引用 javascript 出现问题

转载 作者:行者123 更新时间:2023-11-28 02:44:51 26 4
gpt4 key购买 nike

我在为数组设置样式时遇到了麻烦,

这是我的代码:

这是我的 HTML:

<!DOCTYPE HTML>
<html>
<head>
<title>test</title>
<script src="card.js"></script>
<script src="Deck.js"></script>
<link rel="stylesheet" href="card.css">
</head>
<body onload = "addCard()">
</body>
</html>

这是我的第一个带有数组 (Deck) 的 JavaScript 文件,它引用了我的第二个带有卡片的 JavaScript 文件:

var Deck = new Array();
function addCard(){
Deck[0] = new Card("test");
Deck[1] = new Card("1234");
}

这是我的第二个带有卡片的 JavaScript 文件:

class Card{
constructor(myText){
document.write("<div class = \"card\">");
document.write("<div class = \"back\">");
document.write("<div class = \"up\"><\/div>");
document.write("<div class=\"down\"><\/div>");
document.write("<hr class = \"arrowUpLeft\">");
document.write("<hr class = \"arrowDownRight\">");
document.write("<hr class = \"arrowUpRight\">");
document.write("<hr class = \"arrowDownLeft\">");
document.write("<div class = \"front\">");
document.write("<p id =\"text_card\">");
document.write(myText);
document.write("<\/p>");
document.write("<\/div>");
document.write("<\/div>");
document.write("<\/div>");
}
}

这是我的 CSS:

.card{
height: 336px;
width: 240px;
border: 4px solid transparent;
border-radius: 50px;
box-sizing: border-box;
z-index: 2;
position: relative;
bottom: 100%;
}

.card:hover > .back{
animation: cardturn 1s;
background-color: blue;
}

.card:hover>.back :not(.front), .card:hover>.back :not(.front)>*{
animation: cardturn 1s;
animation: setvisibilityBackInvisible 1s;
visibility: hidden;
}

.card:hover>.back>.front, .card:hover>.back>.front>*{
animation: setvisibilityBackVisible 1s;
visibility: visible;
}

.back{
height: 328px;
width: 232px;
background-color: red;
border-radius:46px;
z-index: 2;
border: 4px solid black;
animation: cardturn2 1s;
}

.front, .front>*{
animation: setvisibilityBackInvisible 1s;
visibility: hidden;
}

.back>:not(.front), .back>:not(.front)>*{
animation: setvisibilityBackVisible 1s;
visibility: visible;
}

.up{
position: relative;
top: 114px;
left: 66px;
height: 0px;
width: 0px;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 50px solid blue;
background-color: transparent;
}

.down{
position: relative;
top: 114px;
left: 66px;
height: 0px;
width: 0px;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-top: 50px solid blue;
background-color: transparent;
}

.arrowUpLeft{
position: relative;
top: -22px;
left:-25px;
width: 214px;
transform: rotate(45deg);
border: 2px solid black;
}

.arrowDownRight{
position: relative;
top: 118px;
left:25px;
width: 214px;
transform: rotate(45deg);
border: 2px solid black;
}

.arrowUpRight{
position: relative;
top: 4px;
left:-25px;
width: 70px;
transform: rotate(-45deg);
border: 2px solid black;
}

.arrowDownLeft{
position: relative;
top: 44px;
left:25px;
width: 70px;
transform: rotate(-45deg);
border: 2px solid black;
}

@keyframes cardturn{
0%,100%{
transform: scale(1,1);
}
50%{
transform: scale(0,1);
background-color: red;
}
51%{
background-color: blue;
}
0%{
background-color: red;
}
100%{
background-color:blue;
}
}

@keyframes cardturn2{
0%,100%{
transform: scale(1,1);
}
50%{
transform: scale(0,1);
background-color: blue;
}
51%{
background-color: red;
}
100%{
background-color: red;
}
0%{
background-color: blue;
}
}

@keyframes cardturn3{
0%,100%{
transform: scale(1,1);
}
50%{
transform: scale(0,1);
}
}

@keyframes setvisibilityBackInvisible{
0%,50%{
visibility: visible;
}
51%,100%{
visibility: hidden;
}
}

@keyframes setvisibilityBackVisible{
0%,50%{
visibility: hidden;
}
100%{
visibility: visible;
}
}

希望大家帮帮我,万分感谢。即使你只能解释为什么 CSS 不起作用,我实际上也会很高兴,因为我知道该怎么做。

最佳答案

您需要删除空格:

"<div class = \"card\">"

应该是:

"<div class=\"card\">"

关于javascript - 使卡片样式引用 javascript 出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46974509/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com