flex 弹性盒布局——骰子

本文通过纯CSS代码展示了如何实现六个不同面的骰子效果。从简单的单点到复杂的六点排列,利用了CSS的flex布局特性,使得整个骰子的设计既美观又易于理解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


 

<!DOCTYPE html>

<html>



<head lang="en">

<meta charset="UTF-8">

<title>骰子</title>

<style>

* {

margin: 0;

padding: 0;

}



body {

width: 100%;

height: 100%;

display: flex;

padding: 200px;

box-sizing: border-box;

justify-content: space-between;

}



ul,

li {

list-style: none;

}



ul {

width: 150px;

height: 150px;

border-radius: 10px;

background: #eee;

display: flex;

padding: 10px;

box-sizing: border-box;

}



li,

.fiv>li:nth-of-type(2) {

width: 30px;

height: 30px;

background: #333;

border-radius: 50%;

}



.for>li,

.fiv>li {

width: 100%;

height: 30px;

border-radius: 0;

background: none;

}



.six>li {

height: 100%;

width: 30px;

border-radius: 0;

background: none;

}



.for>li>div,

.fiv>li>div,

.six>li>div {

width: 30px;

height: 30px;

background: #333;

border-radius: 50%;

}



/* 一 */



.one>li {

margin: auto;

/* 水平垂直居中 */

}



/* 二 */



.two {

flex-direction: column;

/*改变弹性盒布局轴向*/

}



.two>li {

margin: auto;

}



/* 三 */



.tre>li:nth-of-type(2) {

margin: auto;

}



.tre>li:last-child {

align-self: flex-end;

/*元素单独对其方式*/

}



/* 四 */



.for {

flex-direction: column;

justify-content: space-around;

}



.for>li {

display: flex;

justify-content: space-around;

}



/* 五 */



.fiv {

flex-direction: column;

justify-content: space-between;

}



.fiv>li {

display: flex;

justify-content: space-between;

}



.fiv>li:nth-of-type(2) {

margin: auto;

}



/* 六 */



.six {

flex-direction: row;

justify-content: space-between;

}



.six>li {

display: flex;

flex-direction: column;

justify-content: space-between;

}

</style>

</head>



<body>

<!-- 一 -->

<ul class="one">

<li></li>

</ul>

<ul class="two">

<li></li>

<li></li>

</ul>

<ul class="tre">

<li></li>

<li></li>

<li></li>

</ul>

<ul class="for">

<li>

<div></div>

<div></div>

</li>

<li>

<div></div>

<div></div>

</li>

</ul>

<ul class="fiv">

<li>

<div></div>

<div></div>

</li>

<li></li>

<li>

<div></div>

<div></div>

</li>

</ul>

<ul class="six">

<li>

<div></div>

<div></div>

<div></div>

</li>

<li>

<div></div>

<div></div>

<div></div>

</li>

</ul>

</body>

<script>

</script>



</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

孙华鹏

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值