Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertical rule (as opposed to <hr>) in CSS

Tags:

css

I know it doesn't exist, but is there a pure CSS version?

Would like to set height, and make it 1px wide (with shadow, if possible).

Just cannot fathom a pure CSS way of doing this. Would need to be absolutely positioned.

As my container has two divs side by side, 60-40% split for example. Need the vertical rule between the two, but don't really want to use border-left on div 2.

Any suggestions?

like image 984
422 Avatar asked Nov 28 '10 05:11

422


People also ask

Is there a vertical HR?

No, there is no vertical rule. It does not make logical sense to have one. HTML is parsed sequentially, meaning you lay out your HTML code from top to bottom, left to right how you want it to appear from top to bottom, left to right (generally) A vr tag does not follow that paradigm.

How do you put a vertical line on a HR tag?

A vertical line can be created in HTML using transform property in <hr> tag. With the help of this property, you can rotate a horizontal line to a vertical line.

Is there a vertical HR in HTML?

The <hr> tag in HTML is used to produce a horizontal line. However, there is no tag for creating a vertical line. The border-left CSS attribute can be used to simulate a vertical line. The border-left property of CSS is used to style the left-side border.

Can I style hr in CSS?

The HTML HR element provides semantic meaning to a page's layout. It can only be customized using CSS. But you can apply all sorts of crazy styles to a horizontal line to create very interesting layout affects.


2 Answers

for this you basically need to setup a place to put it and a div statement works.

 <div style="width:150px;height:2px;background-color:#000000;">&nbsp;</div>

this could also be referenced:

 .hr {width:150px;height:2px;background-color:#000000;} // in your css file/script

 <div class="hr">&nbsp;</div> <!-- IN HTML -->

You can change the position and have it going up/down or left/right with css placement and z-index

 .hr {width:2px;height:150px;background-color:#000000;position:absolute;top:0px;left:50px;z-index:10;} // in your css file/script

basically

 width            = how wide you want it
 height           = how tall you want it
 background-color = is the color you want it to be
 position         = absolute, relative, float - basically if it stays in one place or moves with page content
 top              = where to place in reference to top of page - could be margin-top
 left             = where to place in reference to left of page - could be margin-left
like image 95
James Williams Avatar answered Jan 03 '23 05:01

James Williams


This post already got a awnser but I'm facing the same problem and I found something interesting:

        hr, hr.vertically {
            color: #b2b2b2;
            background-color: #b2b2b2;
        }

        hr {
            width: 100%;
            height: 0;
        }

        hr.vertically {
            width: 0;
            height: 100%;
        }

        <div style="height: 400px;">
            a
            <hr />
            <hr class="vertically" />
        </div>

Hr means horizontal rule, adding a class vertically to it sounds close to a paradox, but it look's more organized to me.

like image 35
user1330271 Avatar answered Jan 03 '23 04:01

user1330271