Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: Set border to half width

Tags:

html

css

Consider following:

<div class="box">
...
</div>

.box{
    width:500px;
    border-bottom: 1px solid #ccc;
}

It will set the bottom border of full width of the box (500px). But instead of setting the border bottom to whole width, I'd like to set 300px, in the middle of the box bottom, how should I do that..

like image 942
user1117313 Avatar asked Jan 10 '12 18:01

user1117313


People also ask

How do I cut border in CSS?

Style the cut corner with the ::before pseudo-element and use the content property required while using the :: before pseudo-element to generate and insert content. Set the position to "absolute" and add the top and right, border-top and border-right properties.

How can the bottom of a border be reduced?

You can go in to the HTML and add another element below the element you want to have the border-bottom and give it a background that is the color you want the border to be and then set the width and height, which is what I have done for years.


1 Answers

You can Use ::after or ::before pseudo-selectors. Like:

<div> something here </div>

CSS:

div {
    width: 500px;
    height: 100px;
    position: relative;
    padding-top: 20px;
    margin-top: 50px;
}

div::before {
    content: '';
    display: block;
    position: absolute;
    top: 0;
    width: 50%;
    left: 25%;
    border-top: 1px solid red;
}

Here is the jsfiddle

like image 151
Melniciuc Costea Avatar answered Nov 14 '22 08:11

Melniciuc Costea