How can I put a vertical line down the center of a

2020-02-17 06:25发布

How do I put a vertical line down the middle of a div? Maybe I should put two divs inside the div and put a left border on one and a right border on the other? I have a DIV tag and I need to put one ascx on the left (that will get swapped out from time to time with another ascx) and then a static ascx on the left. Any ideas on how I should do this? Maybe I answered my own question.

Any pointers would be great

标签: css html
8条回答
小情绪 Triste *
2楼-- · 2020-02-17 07:01

Three divs?

<DIV>
   <DIV>
      /* ascx 1 goes here */
   </DIV>
   <DIV style="width:1px; background-color: #000"></DIV>
   <DIV>
      /* ascx 2 goes here */
   </DIV>
</DIV>
查看更多
啃猪蹄的小仙女
3楼-- · 2020-02-17 07:09

Here's a more modern way to draw a line down a div. Just takes a little css:

.line-in-middle {
    width:400px;
    height:200px;
	  background: linear-gradient(to right, 
	                              transparent 0%, 
	                              transparent calc(50% - 0.81px), 
	                              black calc(50% - 0.8px), 
	                              black calc(50% + 0.8px), 
	                              transparent calc(50% + 0.81px), 
	                              transparent 100%); 
	}
<div class="line-in-middle"></div>

Works in all modern browsers. http://caniuse.com/#search=linear-gradient

查看更多
▲ chillily
4楼-- · 2020-02-17 07:09

This is my version, a gradient middle line using linear-gradient

.block {
      width:400px;
      height:200px;
      position:relative;
 }
.block:before {
      content:"";
      width:1px;
      height:100%;
      display:block;
      left:50%;
      position:absolute;
	    background-image: -webkit-linear-gradient(top, #fff, #000, #fff);
      background-image: -moz-linear-gradient(top, #fff, #000, #fff);
      background-image: -ms-linear-gradient(top, #fff, #000, #fff);
      background-image: -o-linear-gradient(top, #fff, #000, #fff);
      background-image: linear-gradient(top, #fff, #000, #fff);
	}
<div class="block"></div>

查看更多
倾城 Initia
5楼-- · 2020-02-17 07:11

I think your multiple DIV approach is going to be the sanest way to approach this:

<DIV>
   <DIV style="width: 50%; border-right: solid 1px black">
      /* ascx 1 goes here */
   </DIV>
   <DIV style="width: 50%">
      /* ascx 2 goes here */
   </DIV>
</DIV>
查看更多
成全新的幸福
6楼-- · 2020-02-17 07:13

Just tested this; works:

<div id="left" style="width:50%;float:left;background:green;">left</div>
<div id="right" style="margin-left:50%;border-left:solid 1px black;background:red;">right</div>
查看更多
迷人小祖宗
7楼-- · 2020-02-17 07:18

Maybe this can help you

.here:after {
    content:"";
    position: absolute;
    z-index: -1;
    top: 0;
    bottom: 0;
    left: 50%;
    border-left: 2px dotted #ff0000;
    transform: translate(-50%);
}

div {
    margin: 10px auto;
    width: 60%;
    height: 100px;
    border: 1px solid #333;
    position:relative;
    text-align:center
}
<div class="here">Content</div>

Here's is a JSFiddle demo.

查看更多
登录 后发表回答