CSS中的边框长度怎么控制其大小
Admin 2022-05-23 群英技术资讯 659 次浏览
以前需要边框长度比容器小一些时,我用div嵌套。后来发现伪类在实现这个效果时很方便,只需要一个div就够了,另外调整padding和margin都不会很麻烦。
<div class="content-block"> <div class="box-container"> <div class="border-top">border top</div> </div> <div class="box-container"> <div class="border-left">border left</div> </div> <div class="box-container"> <div class="border-right">border right</div> </div> <div class="box-container"> <div class="border-bottom">border bottom</div> </div> </div>
.box-container { position: relative; width: 90%; color: #777; } .border-top { background: #b4bcbf; padding: 15px; } .border-top:before { content: ''; position: absolute; left: 42%; top: 0; bottom: auto; right: auto; height: 7px; width: 50%; background-color: #8796a9; } .border-left { background: #dfdad6; padding: 15px; } .border-left:before { content: ''; position: absolute; left: 0; top: 6%; bottom: auto; right: auto; height: 52%; width: 5px; background-color: #a89d9e; } .border-right { background: #eee9c4; padding: 15px; } .border-right:after { content: ''; position: absolute; left: auto; top: auto; bottom: 5px; right: 0; height: 52%; width: 5px; background-color: #f39c81; } .border-bottom { background: #bcdc9d; padding: 15px; } .border-bottom:after { content: ''; position: absolute; left: 18px; top: auto; bottom: 0; right: auto; height: 6px; width: 105px; background-color: #32b66b; }
效果如下图:
总结
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
本文给大家分享CSS3实现列表无限滚动/轮播效果,实现思路大概是将当前列表滚动至最后一项的末尾,然后瞬间切换回第一项,怎么实现无限轮播效果,下面小编给大家带来了实现思路,感兴趣的朋友一起看看吧
css3中border-box是什么意思在css3中border-box是box-sizing属性的一个值。box-sizing 属性允许您以特定的方式定义匹配某个区域的特定元素。例如,假如您需要并排放置两个带
这篇文章我们来了解CSS中id选择器的用法,id选择器是CSS学习中的基础知识,因此本文就给大家来介绍一下,下文有详细的介绍,有需要的朋友可以参考,接下来就跟随小编来一起学习一下吧!
这篇文章给大家分享的是关于flex弹性盒布局的内容,下文实现的效果是元素左对齐,也就是八张图的九宫格,最后一行要实现左对齐的效果,那么具体怎样做呢?下面我们详细的了解看看。
这篇文章我们来了解CSS3弹性盒子是什么。CSS3中,弹性盒子是一种布局方式,小编觉得挺实用的,因此分享给大家做个参考,文中的示例代码介绍得很详细,有需要的朋友可以参考,接下来就跟随小编一起了解看看吧。
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008