display:line-block;标签四周间隔的处理方法

display:line-block;标签是个好东西,在有多个同级display:line-block;标签时,可以实现自动换行。

但是可恨的是,四周总是有非margin、padding、left、top、right、bottom属性的空白空间。

网上有很多解决办法,但是没有找到只用CSS就可以解决的办法,今天突发奇想竟然成功了。(写完才发现14年就有解决的文章了,为毛17年我没有找到发火,我那通找啊大哭死的心都有了!)

我把未解决和已解决的相关代码发写在下面了,附带效果截图,就差几行CSS代码,我就不多说,自己对比看吧。

没有进行处理的相关代码和效果图:

html:

<div class="div">
    <div class="block">1</div>
    <div class="block">2</div>
    <div class="block">3</div>
    <div class="block">4</div>
    <div class="block">5</div>
</div>

CSS:

.div{
    width: 100px;
    height: 100px;
    background-color: blue;
}
.block{
    display: inline-block;
    width: 30px;
    background-color: red;
    font-size: 12px;
}

效果图:


进行处理之后的相关代码和效果图:

CSS:

.div{
    width: 100px;
    height: 100px;
    font-size: 0px;
    background-color: blue;
}
.block{
    display: inline-block;
    width: 30px;
    background-color: red;
    font-size: 12px;
}

效果图


修改这段代码,实现图片点击切换效果@charset "utf-8";* { margin: 0; padding: 0; list-style: none; }html { height: 100%;}body { width: 100%; height: 100%; margin: 0; display: flex; flex-direction: column;}.class1 { height: 70px; width: 100%; background: #ccc; }.class2 { height: 50px; width: 100%; background: #ffaa00;}.class3 { width: 100%; }header{ background-color: #00ffff; height: 70px; width: 1200px; margin: 0 auto; }.logo{ width: 200px; height: 65px; background-color: #16A1E7; float: left; padding-top: 5px; } .logo.p{ line-height: 10px; } .search{ width: 800px; height: 70px; float: left; } /* 搜索框在导航中居中 */ header .search form{ margin-left: 150px; margin-top: 20px; } /* 输入框样式 */ header .search input{ height:36px; border:none; float:left; } header .search input[type=text]{ width:300px; border:0.5px solid #999; padding:0px 5px; } /* 输入框 */ header .search input[type=submit]{ background-color:#16A1E7; color:#fff; width:100px; font-size:14px; font-family:"微软雅黑";} .reg{ width: 200px; height: 70px; background-color: #ffaa7f; float: left; } .reg a{ text-decoration: none; } .delu{ margin: 25px 0px 0px 120px; } .nav{ width: 100%; height: 50px; border-bottom: 2px solid #0099CC; display: flex; } ul{ background-color: #ffffff; list-style-type: none; overflow: hidden; width: 1200px; margin: 0 auto; } li{ /*display与float两种方式使列表转为横向*/ /* display: inline; */ float: left; } li a{ display:block ; color: #000000; text-decoration: none; text-align: center; padding: 14px 46px; font-size: 16px; } li a:hover{ background-color:#000000 ; color: #ffffff; } .active{ background-color: #00aaff; } .sildeshow > *{ position: absolute; } .href{ z-index: 100; margin-top: 470px; } .href a{ display: block; width: 80px; height: 30px; background-color: #333; float: left; margin-left: 25px; } .images > li img{ width: 500px; height: 500px; }
06-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值