gpt4 book ai didi

javascript - 使用 HTML/CSS 和 Javascript 的 Domino's Tracker

转载 作者:太空宇宙 更新时间:2023-11-03 21:52:33 25 4
gpt4 key购买 nike

我打算创建一个非常简单的网页,显示所有多米诺骨牌 0-12,然​​后允许用户悬停并单击每个多米诺骨牌以隐藏或更改其透明度。这个想法是根据已播放的内容显示剩余的内容。我正在为我的妻子做这个元素,以帮助我更好地理解 html/css 以及我最近获得的 jquery 和 javascript 知识。

此时我的问题只是关于使用 CSS 将这些多米诺骨牌打印到页面的最佳方法。我可以使用下面的代码创建 0、1-0 和 1-1 片段,但我很头疼地想弄清楚如何为 0-2 对 Angular 定位点。如果有人有耐心在这里用最好的方法帮助我,将不胜感激:)

<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="dominoe">
<span class="one">
<div class="circle"> </div>
</span>
<div class="line"> </div>
<span class="one">
<div class="circle"> </div>
</span>
</div>
</body>
</html>

* {
border: 0.50px dashed blue; /*guide rulers*/
}

.dominoe {
/* Dominoe shape */
position: relative;
height:76px;
width:40px;
background-color:white;
border: 1px solid black;

/* Rounded Corners
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
padding:2px;
*/
}

.circle {
border-radius: 50%;
width: 5px; /* width and height can be anything, as long as they're equal */
height: 5px;
background-color:black;
position: relative;
margin:auto;

}

.line {
position:relative;
width:90%;
height:2%;
background-color:black;
display:block;
margin:auto;
}

.one {
height:5px;
width: 5px;
display: block;
margin:auto;
margin-top:5%;
margin-bottom:5%;
padding:34%;
}

我尝试使用 CSS 创建的多米诺骨牌示例: http://i.stack.imgur.com/Rfwrf.jpg

最佳答案

  1. 使用 div 而不是 span,默认情况下它们是更适合 block 显示的元素(在这种情况下是合适的)
  2. 从逻辑上重新格式化您的多米诺骨牌结构,即使用嵌套的 div。
  3. 为每个点位置创建 3 个类:左、中、右

解决方案在这里:http://jsbin.com/ikurip/2/edit

引用代码:

HTML:正如您在下方所见,多米诺骨牌首先分为两半,然后分为三部分。在此之后,水平定位点是小菜一碟。

<div class="dominoe"> 
<div class="half">
<div class="part">
<div class="left"></div>
<div class="right"></div>
</div>
<div class="part">
<div class="middle"></div>
</div>
<div class="part">
<div class="left"></div>
<div class="right"></div>
</div>
</div>
<div class="line"></div>
<div class="half"></div>
</div>

CSS:如您所见,我用 .part > div 选择器替换了 circle 类;所以你不必创建另一个类。

* {  
border: 0.50px dashed blue; /*guide rulers*/
}

.dominoe {
/* Dominoe shape */
position: relative;
height:76px;
width:40px;
background-color:white;
border: 1px solid black;

/* Rounded Corners
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
padding:2px;
*/
}

.part > div {
border-radius: 50%;
width: 5px; /* width and height can be anything, as long as they're equal */
height: 5px;
background-color:black;
margin-top: 1px;
}

.line {
width:90%;
height:2%;
background-color:black;
margin-left: 5%;
}
/* Added CSS */
.dominoe { margin-right: 10px; float: left; }
.half {
width: 70%;
height: 32%;
padding: 14%;
}
/* setting padding removes the need to position the top-left, top-right, bottom-left and bottom-right elements */

.part {
width: 100%;
height: 21.333%;
padding: 8% 0% 8% 0%;
/* eliminates need for vertical positioning */
}
.part:first-child {
padding-top: 0%;
}
.part:last-child {
padding-bottom: 0%;
}
.right {
float: right;
}
.left {
float: left;
}
.middle {
margin: auto;
}

此外,如果您想要水平多米诺骨牌而不是垂直多米诺骨牌,您可以将其添加到您的 CSS 中:

.horizontal {
transform: rotate(90deg);
-webkit-transform: rotate(90deg);
-o-transform: rotate(90deg);
-moz-transform: rotate(90deg);
}

只需将“水平”类添加到多米诺骨牌 div。

关于javascript - 使用 HTML/CSS 和 Javascript 的 Domino's Tracker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16386749/

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