0

How do I draw a vertical border (newspaper-like) between the columns I've create? I'm also open to writing this in css3.

    #contentBox 
{
    margin: 0 auto;
    width: 80%;
}

#contentBox .article
{
    float: left;
    margin: 0;
    width: 50%;
    border-right: solid;
}

Then haml:

#contentBox
  .article
     %p text
  .article
     %p text

4 Answers4

3

as commented, 2 simple options:

1) pseudo

   #contentBox {
     margin: 0 auto;
     width: 80%;
     overflow: hidden;
     /* wraps floatting element */
   }
   #contentBox .article {
     float: left;
     margin: 0;
     width: 50%;
   }
   /* test  */
   #contentBox .article {
     height: 300px;
     background: rgba(0, 0, 0, 0.2);
   }
   #contentBox .article:nth-child(1) {
     height: 200px;
   }
   /* pseudo option */
   #contentBox {
     position: relative;
   }
   #contentBox:before {
     content: '';
     position: absolute;
     left: 50%;
     top: 0;
     bottom: 0;
     border-left: 1px solid;
   }
<div id='contentBox'>
  <div class='article'></div>
  <div class='article'></div>
</div>
http://codepen.io/anon/pen/JGyJLo

2) background-image (linear gradient for test) old solid method described here

   #contentBox {
     margin: 0 auto;
     width: 80%;
     overflow: hidden;
     /* wraps floatting element */
   }
   #contentBox .article {
     float: left;
     margin: 0;
     width: 50%;
   }
   /* test  */
   #contentBox .article {
     height: 300px;
     background: rgba(0, 0, 0, 0.2);/*  to see just because they might have different height */
   }
   #contentBox .article:nth-child(1) {
     height: 200px;
   }
   #contentBox {
     background: linear-gradient(to left, transparent 49.95%, black 49.95%, black 50%, transparent 50%)
   }
<div id='contentBox'>
  <div class='article'></div>
  <div class='article'></div>
</div>

http://codepen.io/anon/pen/VezWMe

G-Cyrillus
  • 101,410
  • 14
  • 105
  • 129
1

Add the following lines to your css:

#contentBox .article
{   
    border-right-style: solid;
    border-right-color: #CCC;
    border-right-width: thin;
}
Kurt Van den Branden
  • 11,995
  • 10
  • 76
  • 85
1

add box-sizing for the use of percentage widths and borders.

Then apply the border to the first article to split them with a single line.

* {
  box-sizing: border-box;
}
#contentBox {
  margin: 0 auto;
  width: 80%;
}
#contentBox article {
  float: left;
  margin: 0;
  width: 50%;
  height: 600px; /* DEMO HEIGHT */
}
#contentBox article:first-child {
  border-right: 2px solid red;
}
<div id="contentBox">
  <article>Change the HTML article to any tag/element you would like to use...</article>
  <article>Change the HTML article to any tag/element you would like to use...</article>
</div>
Aaron
  • 10,187
  • 3
  • 23
  • 39
0

the border is there just because its a block element so the border is displaying by the edge of screen you can do display: inline
here is a jsfiddle https://jsfiddle.net/kpx1tqf6/1/

David Genger
  • 875
  • 10
  • 25