html5写骰子 css
要使用HTML5和CSS创建一个骰子,你可以使用HTML定义结构,CSS进行样式设计。以下是一个简单的例子:
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dice with HTML5 and CSS</title>
<style>
.dice {
width: 100px;
height: 100px;
background-color: #f7f7f7;
border: 1px solid #ccc;
border-radius: 50%;
box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
position: relative;
}
.dice::before, .dice::after {
content: '';
position: absolute;
width: 50%;
height: 50%;
background: #fff;
border: 1px solid #ccc;
top: 25%;
left: 25%;
border-radius: 50%;
}
.dice::before {
border-top: none;
border-left: none;
transform: rotate(45deg);
}
.dice::after {
border-bottom: none;
border-right: none;
transform: rotate(-45deg);
}
</style>
</head>
<body>
<div class="dice"></div>
</body>
</html>
CSS:
.dice {
width: 100px;
height: 100px;
background-color: #f7f7f7;
border: 1px solid #ccc;
border-radius: 50%;
box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
position: relative;
}
.dice::before, .dice::after {
content: '';
position: absolute;
width: 50%;
height: 50%;
background: #fff;
border: 1px solid #ccc;
top: 25%;
left: 25%;
border-radius: 50%;
}
.dice::before {
border-top: none;
border-left: none;
transform: rotate(45deg);
}
.dice::after {
border-bottom: none;
border-right: none;
transform: rotate(-45deg);
}
这段代码创建了一个简单的骰子形状,使用了CSS伪元素 ::before
和 ::after
来创建骰子的两个面。通过调整CSS属性,你可以进一步美化这个骰子。
评论已关闭