我有以下代码
div {
width: 200px;
border-bottom: 1px solid magenta;
height: 50px;
}
<div></div>
div {
width : 200px;
height : 50px;
position: relative;
z-index : 1;
background: #eee;
}
div:before {
content : "";
position: absolute;
left : 0;
bottom : 0;
height : 1px;
width : 50%; /* or 100px */
border-bottom:1px solid magenta;
}
<div>Item 1</div>
<div>Item 2</div>
不需要为了呈现目的而使用额外的标记。:after也受到IE8的支持。
编辑:
如果您需要右对齐的边框,只需将left: 0
更改为right: 0
如果您需要居中对齐的边框,只需简单地设置left: 50px;
div:before
设为 left: 50px
。 - Chowlettleft: 25%
,因为它将是25%+ 50%+ 25%。 - skiftmargin: auto
,right: 0
,left: 0
居中显示该行,在 :before
中添加这些属性。如果这对你有帮助,请点赞。 - Alessandro_Russo在现代浏览器中,另一种方法是使用负的扩散 box-shadow。请查看此已更新的代码片段:http://jsfiddle.net/WuZat/290/
box-shadow: 0px 24px 3px -24px magenta;
我认为上面被接受的答案是最安全和最兼容的方法。不过,我想分享另一种技术。
我像这样在h3标签下面添加了一行。
<h3 class="home_title">Your title here</h3>
.home_title{
display:block;
}
.home_title::after {
display:block;
clear:both;
content : "";
position: relative;
left : 0;
bottom : 0;
max-width:250px;
height : 1px;
width : 50%; /* or 100px */
border-bottom:1px solid #e2000f;
margin:0 auto;
padding:4px 0px;
}
您可以使用线性渐变:
div {
width:100px;
height:50px;
display:block;
background-image: linear-gradient(to right, #000 1px, rgba(255,255,255,0) 1px), linear-gradient(to left, #000 0.1rem, rgba(255,255,255,0) 1px);
background-position: bottom;
background-size: 100% 25px;
background-repeat: no-repeat;
border-bottom: 1px solid #000;
border-top: 1px solid red;
}
<div></div>
<div>
content
<div class ="ac-brdr"></div>
</div>
CSS as below:
.active {
color: magneta;
}
.active .ac-brdr {
width: 20px;
margin: 0 auto;
border-bottom: 1px solid magneta;
}
虽然有点晚了,但如果有人想要制作两条边框(在我的情况下是底部和右侧),您可以使用接受的答案中的技术,并为第二行添加一个 :after 伪元素,然后只需更改属性,如下所示: http://jsfiddle.net/oeaL9fsm/
div
{
width:500px;
height:500px;
position: relative;
z-index : 1;
}
div:before {
content : "";
position: absolute;
left : 25%;
bottom : 0;
height : 1px;
width : 50%;
border-bottom:1px solid magenta;
}
div:after {
content : "";
position: absolute;
right : 0;
bottom : 25%;
height : 50%;
width : 1px;
border-right:1px solid magenta;
}
我有一个案例,需要在div容器中的图片之间加一些底部边框,最好的一行代码是- border-bottom-style: inset;
div{
font-size: 25px;
line-height: 27px;
display:inline-block;
width:200px;
text-align:center;
}
div::after {
background: #f1991b none repeat scroll 0 0;
content: "";
display: block;
height: 3px;
margin-top: 15px;
width: 100px;
margin:auto;
}
以下内容可以帮助您:
http://www.w3schools.com/tags/att_hr_width.asp
<hr width="50%">
这将创建一个宽度为50%的水平线,如果您想编辑样式,则需要创建/修改类。