我计划创建一个非常简单的网页,显示所有的多米尼克0-12,然后将允许用户悬停并单击每个多米诺骨牌,以隐藏或更改其透明度。这个想法是为了显示基于已经播放的内容的剩余内容。我正在为我的妻子做这个项目,以帮助我更好地理解html/css,以及我最近获得的jquery和javascript知识。
在这一点上,我的问题只是关于使用CSS将这些多米诺骨牌打印到页面的最佳方法。我可以使用下面的代码创建0,1-0和1-1块,但我很头疼,试图弄清楚如何才能对角定位0-2的点。如果任何人有耐心在这里用最好的方法帮助我,我将非常感激:)
<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
发布于 2013-05-06 11:09:46
,appropriate)
解决方案在这里: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;
}另外,如果你想要水平的domino而不是垂直的,你可以在你的CSS中添加这个:
.horizontal {
transform: rotate(90deg);
-webkit-transform: rotate(90deg);
-o-transform: rotate(90deg);
-moz-transform: rotate(90deg);
}并简单地将“horizontal”类添加到dominoe div中。
发布于 2014-06-07 01:48:33
我知道这是你一年多前就在看的东西,但我今天看到了你的帖子。
几个月前,我试图使用HTML和CSS创建一个拼图。
我看到了这个页面:
http://sergeylukin.com/css-jigsaw-puzzle-piece/
当我研究所用的方法时,我受到启发,使用卢金先生在拼图上使用的相同技术,使用css和html创建了一个domino。在我弄清楚一张多米诺骨牌后,其他27张很容易。
结果是这样的:
http://dominocodes.net
我为瓦片创建了一个类选择器,它会给人一种3D的感觉。
.domino {
float: left;
font-size: 20px;
width: 6em;
height: 12em;
margin: 40px;
position: relative;
-webkit-border-radius: .8em;
-moz-border-radius: .8em;
border-radius: .8em;
-moz-box-shadow: .3em .3em 0em .2em #333;
-webkit-box-shadow: .3em .3em 0em .2em #333;
box-shadow: .3em .3em 0em .2em #333;
}然后是一个分组的类选择器,用于处理.domino类的背景色和圆点所在的跨度。
.domino, .domino span {
background-color:#000
}另一组用于在瓷砖上放置线条:
.domino .line {
width: 5.5em;
height: .2em;
position: absolute;
top: 5.7em;
left: .25em;
background-color: #fff;
}然后,我为domino上的每个可能的pip提供了一个类选择器,顶部是7个,底部是7个,总共有14个类选择器。我不会在这里列出每一个的css。一旦您研究了这里的两个示例,您就可以推断并弄清楚其余的是如何完成的。(或者,您可以直接转到我的页面,使用浏览器中的Inspect Element工具查看或抓取css。)
我为每个pip的类选择器使用了以下命名约定:
名称中的第一个字母指定pip是用于拼贴的(T)op还是(B)另一半。第二个字母指定它是在(L)eft侧、(C)enter侧还是(R)右侧。剩余的数字确定pip将是哪些数字组合的一部分。此命名约定适用于垂直平铺。
例如:位于瓷砖顶部中心的管道名为TC135,这意味着TC135是参与瓷砖的中心管道,瓷砖的上半部分为1、3或5。BR23456将是下半部分的圆点,显示2、3、4、5或6。
每个管子都有相同的宽度、高度、半径和颜色。每个类选择器中唯一的区别是顶部和左侧的值。
您会注意到,我没有使用px表示宽度、高度、顶部和左侧,而是像Lukin先生在拼图块示例中那样使用em。这允许您只更改domino类选择器的font-size属性中的一个值,结果是页面上的所有domino都将按比例重新调整大小。有了一个小的jquery和一个微调元素,我可以让访问者只需一行代码就可以动态地调整tiles的大小。我还是一个jquery新手,所以我还没有尝试过。
下面是用于TC135、BL23456和BR23456类选择器的css:
.domino .TC135 {
width: 1.2em;
height: 1.2em;
position: absolute;
top: 2.4em;
left: 2.5em;
-webkit-border-radius: 4em;
-moz-border-radius: 4em;
border-radius: 4em;
background-color: #fff;
}
.domino .BL23456 {
width: 1.2em;
height: 1.2em;
position: absolute;
top: 9.6em;
left: 1.0em;
-webkit-border-radius: 4em;
-moz-border-radius: 4em;
border-radius: 4em;
background-color: #fff;
}
.domino .BR23456 {
width: 1.2em;
height: 1.2em;
position: absolute;
top: 6.4em;
left: 4.0em;
-webkit-border-radius: 4em;
-moz-border-radius: 4em;
border-radius: 4em;
background-color: #fff;
}这是您将用来构建一个顶部为一个点点,底部为两个点点的图块的HTML。
<div class="domino">
<span class="TC135"></span>
<span class="line"></span>
<span class="BL23456"></span>
<span class="BR23456"></span>
</div>发布于 2013-05-06 11:32:37
您可以简单地将Unicode字符用于domino tiles。有一套完整的,既垂直又水平的,从U+1F030开始,到U+1F093结束。
例如,2-3水平多米诺骨牌位于U+1F042,如下所示:
显示完整的domino磁贴范围的Here's a chart。
https://stackoverflow.com/questions/16386749
复制相似问题