How to make a vertical line in HTML

2019-01-02 14:24发布

How do you make a vertical line using HTML?

标签: html css
20条回答
无与为乐者.
2楼-- · 2019-01-02 14:57

One more approach is possible : Using SVG.

eg :

<svg height="210" width="500">
    <line x1="0" y1="0" x2="0" y2="100" style="stroke:rgb(255,0,0);stroke-width:2" />
      Sorry, your browser does not support inline SVG.
</svg>

Pros :

  • You can have line of any length and orientation.
  • You can specify the width, color easily

Cons :

  • SVG are now supported on most modern browsers. But some old browsers (like IE 8 and older) don't support it.
查看更多
骚的不知所云
3楼-- · 2019-01-02 15:01

To create a vertical line centered inside a div I think you can use this code. The 'container' may well be 100% width, I guess.

div.container {
  width: 400px;
}

div.vertical-line {
  border-left: 1px solid #808080;
  height: 350px;
  margin-left: auto;
  margin-right: auto;
  width: 1px;
}
<div class="container">
  <div class="vertical-line">&nbsp;</div>
</div>

查看更多
像晚风撩人
4楼-- · 2019-01-02 15:05

Why not use &#124, which is the html special character for |

查看更多
深知你不懂我心
5楼-- · 2019-01-02 15:07

You can use hr (horizontal line) tag and than rotate it 90 degree with css below

hr {   
    transform:rotate(90deg);
    -o-transform:rotate(90deg);
    -moz-transform:rotate(90deg);
    -webkit-transform:rotate(90deg);
}

http://jsfiddle.net/haykaghabekyan/0c969bm6/1/

查看更多
冷夜・残月
6楼-- · 2019-01-02 15:09

Put a <div> around the markup where you want the line to appear to next, and use CSS to style it:

.verticalLine {
  border-left: thick solid #ff0000;
}
<div class="verticalLine">
  some other content
</div>

查看更多
与君花间醉酒
7楼-- · 2019-01-02 15:09

You can use an empty <div> that is styled exactly like you want the line to appear:

HTML:

<div class="vertical-line"></div>

With exact height (overriding style in-line):

  div.vertical-line{
      width: 1px; /* Line width */
      background-color: black; /* Line color */
      height: 100%; /* Override in-line if you want specific height. */
      float: left; /* Causes the line to float to left of content. 
        You can instead use position:absolute or display:inline-block
        if this fits better with your design */
    }
<div class="vertical-line" style="height: 45px;"></div>

Style the border if you want 3D look:

    div.vertical-line{
      width: 0px; /* Use only border style */
      height: 100%;
      float: left; 
      border: 1px inset; /* This is default border style for <hr> tag */
    }
   <div class="vertical-line" style="height: 45px;"></div>

You can of course also experiment with advanced combinations:

  div.vertical-line{
      width: 1px;
      background-color: silver;
      height: 100%;
      float: left;
      border: 2px ridge silver ;
      border-radius: 2px;
    }
 <div class="vertical-line" style="height: 45px;"></div>

查看更多
登录 后发表回答