Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create 100% vertical line in css

Tags:

html

css

I want to create a vertical line that cover whole page like this

enter image description here

here is my code

#menu
{
border-left: 1px solid black;
height: 100%;
}

result show like this enter image description here

like image 580
user1493448 Avatar asked Nov 04 '12 18:11

user1493448


People also ask

How do I type a vertical line in CSS?

You can use the horizontal rule tag to create vertical lines. By using minimal width and large size, horizontal rule becomes a vertical one.

How do I make a vertical line in HTML?

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.

How do you draw a straight line in CSS?

Its simple to add a horizontal line in your markup, just add: <hr>. Browsers draw a line across the entire width of the container, which can be the entire body or a child element.


4 Answers

Use an absolutely positioned pseudo element:

ul:after {
  content: '';
  width: 0;
  height: 100%;
  position: absolute;
  border: 1px solid black;
  top: 0;
  left: 100px;
}

Demo

like image 153
bookcasey Avatar answered Oct 03 '22 08:10

bookcasey


As bookcasey said, height: 100%; will only make the DIV 100% of its parent. For this reason you will need to make html, body {height: 100%; min-height: 100%} as stated by Marko, but also, make the same change on every parent DIV of #menu.

Because you have a bottom border, then apply the right border to the parent DIV at height: 100%; and apply the bottom-border to your #menu at whatever height you want the bottom border to show up.

like image 41
Matt Olan Avatar answered Oct 03 '22 08:10

Matt Olan


There are at least two ways to solve this.

Solution 1:

If you are okay with using an absolutely positioned element, you can use the top and bottom properties instead of height. By setting both top and bottom to 0 you force the element into taking up full height.

#menu
{
    position: absolute;
    border-right: 1px solid black;
    top: 0;
    bottom: 0;
}​

Demo

Solution 2:

Another way would be to force the HTML and BODY elements into a 100% height, to give room for a menu with 100% height:

body, html { height: 100%; }
#menu
{
    border-right: 1px solid black;
    height: 100%;
}​

Demo

like image 32
Christofer Eliasson Avatar answered Oct 03 '22 07:10

Christofer Eliasson


100% height refers to the height of the parent container. In order for your div to go full height of the body you have to set this:

html, body {height: 100%; min-height: 100%}

Hope it helps.

like image 45
Marko Francekovic Avatar answered Oct 03 '22 09:10

Marko Francekovic