Use two color stops: #880015 at 50% and #fff at 50% Use a background-size of 100% width and 3px in height, i.e. background-size: 100% 3px. Position the two backgrounds at the top left and bottom left of your element.
If you do not want to mess with the HTML at all, you can do it with an empty pseudoelement, using CSS only. You still need to know the background color, of course (assuming white here):
<span class="half-a-border-on-top">Hello world!</span>
<style>
.half-a-border-on-top {
border-top:1px solid black;
position: relative;
}
.half-a-border-on-top:after {
padding:0;margin:0;display:block;/* probably not really needed? */
content: "";
width:50%;
height:1.1px;/* slight higher to work around rounding errors(?) on some zoom levels in some browsers. */
background-color:white;
position: absolute;
right:0;
top:-1px;
}
</style>
Result:
Snippet
.half-a-border-on-top {
border-top:1px solid black;
position: relative;
}
.half-a-border-on-top:after {
padding:0;margin:0;display:block;/* probably not really needed? */
content: "";
width:50%;
height:1.1px;
background-color:white;
position: absolute;
right:0;
top:-1px;
}
<span class="half-a-border-on-top">Hello world!</span>
Fiddle:
http://jsfiddle.net/vL1qojj8/
Would this work:
#holder {
border: 1px solid #000;
height: 200px;
width: 200px;
position:relative;
margin:10px;
}
#mask {
position: absolute;
top:-1px;
left:1px;
width:50%;
height: 1px;
background-color:#fff;
}
<div id="holder">
<div id="mask"></div>
</div>
You can use CSS gradient border
.half-a-border-on-top {
border-top: 1px solid;
border-image: linear-gradient(to right, #000 50%, #FFF 50%) 100% 1;
}
<span class="half-a-border-on-top">Hello world!</span>
let show you how i edit the code of leo, to put a half border at left in center.
try this:
html code
<div class="half-a-border-on-left">Hello world!</div>
css code
<style>
.half-a-border-on-left {
border-left: 1px solid black;
position: relative;
height: 50px;
background: red;
}
.half-a-border-on-left:after {
padding:0;
margin:0;
content: "";
width: 1px;
height: 10px;
background-color:white;
position: absolute;
left:-1px;
top: -10px;
}
.half-a-border-on-left:before {
padding:0;
margin:0;
content: "";
width: 1px;
height: 10px;
background-color:white;
position: absolute;
left: -1px;
bottom: -5px;
}
</style>
Those are code i use to put a half border thank you leo,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With