CSS Display table add space between separating border - css

In a markup with display: table I'd like to separate some rows with a dividing line.
.table {
display: table;
width: 100%;
border-collapse: collapse;
}
.table-row {display: table-row; }
.table-cell {display: table-cell; width: 50%}
.border-between {border-top:1px solid;}
.padding-t {padding-top: .5rem}
.padding-b {padding-bottom: .5rem}
<div class="table">
<div class="table-row">
<div class="table-cell">1</div>
<div class="table-cell">1</div>
</div>
<div class="table-row">
<div class="table-cell">2</div>
<div class="table-cell padding-b">2</div>
</div>
<div class="table-row border-between">
<div class="table-cell padding-t">3</div>
<div class="table-cell">3</div>
</div>
<div class="table-row">
<div class="table-cell">4</div>
<div class="table-cell">4</div>
</div>
<div class="table-row border-between">
<div class="table-cell">5</div>
<div class="table-cell">5</div>
</div>
<div class="table-row">
<div class="table-cell">6</div>
<div class="table-cell">6</div>
</div>
<div class="table-row">
<div class="table-cell">7</div>
<div class="table-cell">7</div>
</div>
<div class="table-row">
<div class="table-cell">8</div>
<div class="table-cell">8</div>
</div>
</div>
While this works without problem when setting border-collapse: collapse; I'm looking for a nice and clean way to add some vertical space before and after the line as I did in my example between line 2 and 3. I would favor a solution without adding extra markup and modifying some cells for providing padding. Thanks for pushing me into the right direction!

You can simply define the height of every cell thereafter align the contents(numbers) in the center will also make it looks like an expected result you want
.table {
display: table;
width: 100%;
border-collapse: collapse;
}
.table-row {
display: table-row;
}
.table-cell {
display: table-cell;
width: 50%;
}
.border-between {
border-top: 1px solid;
}
.m {
height: 50px;
line-height: 50px;
}
<div class="table">
<div class="table-row">
<div class="table-cell m">1</div>
<div class="table-cell m">1</div>
</div>
<div class="table-row">
<div class="table-cell m">2</div>
<div class="table-cell m">2</div>
</div>
<div class="table-row border-between">
<div class="table-cell m">3</div>
<div class="table-cell m">3</div>
</div>
<div class="table-row">
<div class="table-cell m">4</div>
<div class="table-cell m">4</div>
</div>
<div class="table-row border-between">
<div class="table-cell m">5</div>
<div class="table-cell m">5</div>
</div>
<div class="table-row">
<div class="table-cell m">6</div>
<div class="table-cell m">6</div>
</div>
<div class="table-row">
<div class="table-cell m">7</div>
<div class="table-cell m">7</div>
</div>
<div class="table-row">
<div class="table-cell m">8</div>
<div class="table-cell m">8</div>
</div>
</div>

Related

Newspaper-style div alignment with flex-wrap, overflow, without fixed container size

I am currently working on an issue with regards to HTML+CSS and reaching the limits on what I know is possible. Here is the issue:
https://jsfiddle.net/jwco2sd8/1/
.container {
display: flex;
flex-direction: column;
flex-wrap: wrap;
overflow-y: auto;
}
.item {
width: 10em;
height: 2em;
margin: 0.1em;
background-color: red;
}
.item:nth-child(3n+2) {
background-color: lightgreen;
}
.item:nth-child(3n+3) {
background-color: blue;
}
<html>
<body>
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
<div class="item">10</div>
<div class="item">11</div>
<div class="item">12</div>
<div class="item">13</div>
<div class="item">14</div>
<div class="item">15</div>
<div class="item">16</div>
<div class="item">17</div>
<div class="item">18</div>
<div class="item">19</div>
<div class="item">20</div>
<div class="item">21</div>
<div class="item">22</div>
<div class="item">23</div>
<div class="item">24</div>
<div class="item">25</div>
<div class="item">26</div>
<div class="item">27</div>
<div class="item">28</div>
<div class="item">29</div>
<div class="item">30</div>
<div class="item">31</div>
<div class="item">32</div>
<div class="item">33</div>
<div class="item">34</div>
<div class="item">35</div>
<div class="item">36</div>
<div class="item">37</div>
<div class="item">38</div>
<div class="item">39</div>
<div class="item">40</div>
<div class="item">41</div>
<div class="item">42</div>
<div class="item">43</div>
<div class="item">44</div>
<div class="item">45</div>
<div class="item">46</div>
<div class="item">47</div>
<div class="item">48</div>
<div class="item">49</div>
<div class="item">50</div>
</div>
</body>
</html>
I want to achieve a newspaper-style ordering of the divs in the example linked. That means that the primary ordering of the items should be "column", but if there is horizontal space, instead of overflowing vertically, items should first be distributed horizontally first - and then if there is not enough space overflow vertically. I want the container to resize dynamically with the browser window, so I cannot set a constant width or height of the container item.
Adding a 'max-height: 25em' to the .container div, simulates what I want to achieve (on my screen):
Is there a way to achieve the desired effect with just HTML/CSS but without media-queries and JavaScript code. I pretty much understand why what I am doing is not working, but I do not know if there are alternatives.
I added a little bit of JavaScript now to do the necessary "space-left" computations and set max-height from there, but I still feel that a pure CSS+HTML solution should work and would be nicer. Are there any other ways that to accomplish this?
This is the job of columns where you only define the column-width and you keep the column-count auto
.container {
column-width:10em;
}
.item {
width: 10em;
display:inline-block;
height: 2em;
margin: 0.1em;
background-color: red;
}
.item:nth-child(3n+2) {
background-color: lightgreen;
}
.item:nth-child(3n+3) {
background-color: blue;
}
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
<div class="item">10</div>
<div class="item">11</div>
<div class="item">12</div>
<div class="item">13</div>
<div class="item">14</div>
<div class="item">15</div>
<div class="item">16</div>
<div class="item">17</div>
<div class="item">18</div>
<div class="item">19</div>
<div class="item">20</div>
<div class="item">21</div>
<div class="item">22</div>
<div class="item">23</div>
<div class="item">24</div>
<div class="item">25</div>
<div class="item">26</div>
<div class="item">27</div>
<div class="item">28</div>
<div class="item">29</div>
<div class="item">30</div>
<div class="item">31</div>
<div class="item">32</div>
<div class="item">33</div>
<div class="item">34</div>
<div class="item">35</div>
<div class="item">36</div>
<div class="item">37</div>
<div class="item">38</div>
<div class="item">39</div>
<div class="item">40</div>
<div class="item">41</div>
<div class="item">42</div>
<div class="item">43</div>
<div class="item">44</div>
<div class="item">45</div>
<div class="item">46</div>
<div class="item">47</div>
<div class="item">48</div>
<div class="item">49</div>
<div class="item">50</div>
</div>

Custom Bootstrap grid rows and cols

I am beginner in bootstrap, how to get this layout in bootstrap 4 grid? I do not see the areas marked in red
So far i have tried the below
<div class="row">
<div class="col-md-6">
</div>
<div class="col-md-6">
<div class="row">
<div class="col-md-12">
</div>
</div>
<div class="row">
<div class="col-md-12">
</div>
</div>
</div>
</div>
Hope this helps -:
<div class="container">
<div class="row green" style="height: 50px;"></div>
<div class="row">
<div class="col-sm-6 red" style="height: 100px;"></div>
<div class="col-sm-6">
<div class="row yellow" style="height: 50px;">
</div>
<div class="row blue" style="height: 50px;">
</div>
</div>
</div>
</div>
<style>
.green{
background: green;
}
.red{
background: red;
}
.yellow{
background: yellow;
}
.blue{
background: blue;
}
</style>

Foundation z-index for nested element

so I built my layout to the exact specifications but when I try to push the .feat section up (position: absolute; margin-top: -60px;) over the header element I run into z-index issues.
I've read many posts on setting the header element to position: relative; but that's not doing it.
a visual for you: the image should be over the white background
Here's my codePen with the exact setup.
I would really love to get this, thank you for your suggestions.
You can achieve this layout without using the absolute positioning for your different sections. Foundation offers XY Grid which can be used as demonstrated in the code examples/CodePen link below:
HTML
<div class="grid-container fluid">
<div class="grid-x header">
<div class="cell auto">
<h1>Coming to the Stage</h1>
</div>
</div>
<div class="grid-x grid-margin-x">
<div class="cell medium-8">
<div class="grid-y h-100">
<div class="cell shrink">
<div class="grid-x grid-padding-x synopsis">
<div class="cell medium-4">
<p>Synopsis</p>
</div>
<div class="cell medium-8">
<p>Comedy powerhouse Jim Gaffigan has made a career out of finding the extraordinary </p>
</div>
</div>
</div>
<div class="cell medium-shrink">
<div class="grid-x grid-padding-x metainfo">
<div class="cell medium-4">
<p>Credits</p>
</div>
<div class="cell medium-8">
<div class="grid-x grid-padding-x">
<div class="cell medium-6">
<p>Talent</p>
</div>
<div class="cell medium-6">
<p>Jim Gaffigan</p>
</div>
</div>
<div class="grid-x grid-padding-x">
<div class="cell medium-6">
<p>Directors</p>
</div>
<div class="cell medium-6">
<p>Aaron Feldman</p>
</div>
</div>
<div class="grid-x grid-padding-x">
<div class="cell medium-6">
<p>Producters</p>
</div>
<div class="cell medium-6">
<p>Jim Gaffigans</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="cell medium-4">
<div class="grid-x grid-margin-x">
<div class="cell medium-10 feat">
<img src="http://www.comedydynamicsstaging.com/wp-content/uploads/2018/11/unnamed.jpg">
</div>
<div class="cell medium-2 pagination">
1 2 3
</div>
</div>
</div>
</div>
</div>
<div class="grid-container fluid">
<div class="grid-x">
<div class="cell medium-12 extra-meta">
Extra meta
</div>
</div>
</div>
CSS
body {
padding: 0;
margin: 0;
box-sizing: border-box;
background: green;
color: #fff;
text-align: center;
}
.header {
height: 285px;
background: grey;
text-align: left;
padding: 1rem;
}
.h-100 {
height: 100%;
}
.feat img {
margin-top: -60px;
}
.synopsis {
background: red;
height: 100%;
}
.pagination {
background: blue;
}
.metainfo {
background: orange;
height: 100%;
}
#media screen and (max-width: 640px) {
.metainfo {
margin-bottom: 60px;
}
}
.extra-meta {
background: pink;
margin-top: 1rem;
padding: 1rem;
}
CodePen example
Link to CodePen example here.

Bootstrap creating a row with 4 boxes

Hi guys I'm using bootstrap 3 and trying to crate this effect here :
However i cant seem to create this using bootstrap at all Mine keep lying under each other, Any help on recreating this format would be great
HTML:
<div id="night">
<div class="container">
<div class="row">
<div class="col-xs-3 col-md-6 first">
<p>a</p>
</div>
</div>
<div class="row">
<div class="col-xs-3 col-md-3 first">
<p>a</p>
</div>
<div class="col-xs-3 col-md-3 first">
<p>a</p>
</div>
</div>
<div class="row">
<div class="col-xs-3 col-md-3 first">
<p>a</p>
</div>
<div class="col-xs-3 col-md-3 first">
<p>a</p>
</div>
</div>
</div>
</div>
css:
.first {
border-style: solid;
border-color: red;
}
Thanks
Try this please
<div id="night">
<div class="container">
<div class="row">
<div class="col-md-4 first">
<div class="second">a</div>
</div>
<div class="col-md-4 first">
<div class="third">a</div>
<div class="third">a</div>
</div>
<div class="col-md-4 first">
<div class="third">a</div>
<div class="third">a</div>
</div>
</div>
</div>
</div>
CSS:
.first {
border-style: solid;
border-color: red;
}
.second {
border-style: solid;
border-color: blue;
display: block;
height: 400px;
}
.third {
border-style: solid;
border-color: blue;
display: block;
height: 200px;
}
This works in full page, maybe you can work with this aproximation:
<div class="container">
<div class="row">
<div class="col-sm-4" style="background-color:yellow;">
1
</div>
<div class="col-sm-8" style="background-color:pink;">
<div class="row">
<div class="col-sm-6" style="background-color:blue;">
2
</div>
<div class="col-sm-6" style="background-color:red;">
3
</div>
<div class="col-sm-6" style="background-color:green;">
4
</div>
<div class="col-sm-6" style="background-color:black;">
5
</div>
</div>
</div>
</div>
</div>

Center Div scroll

In my code,
Within one container Three blocks will be there. one freezes on the left and one freezes on the right and the other will scroll in between these two divs. Just like modern grids. But I don't want to use the grid.
I have tried, but the center block is not getting the Horizontal scroll.
I want no breakage of the center block, instead, it should scroll horizontally.
* {
box-sizing: border-box;
}
.container {
width: 100%;
overflow: auto;
white-space: nowrap
}
.scroll-center {
width: auto;
overflow: auto;
display: block;
white-space: nowrap
}
.row {
float: left;
}
.cell {
padding: 3px;
border: 1px solid #bbb;
min-height: 25px;
min-width: 200px;
}
<div class="container">
<div class="row">
<div class="cell">HeaderL1</div>
<div class="cell">HeaderL2</div>
<div class="cell">HeaderL3</div>
</div>
<div class="scroll-center">
<div class="row">
<div class="cell">HeaderT2</div>
<div class="cell">Data21</div>
<div class="cell">Data22</div>
</div>
<div class="row">
<div class="cell">HeaderT3</div>
<div class="cell">Data31</div>
<div class="cell">Data32</div>
</div>
<div class="row">
<div class="cell">HeaderT4</div>
<div class="cell">Data41</div>
<div class="cell">Data42</div>
</div>
<div class="row">
<div class="cell">HeaderT5</div>
<div class="cell">Data51</div>
<div class="cell">Data52</div>
</div>
<div class="row">
<div class="cell">HeaderT6</div>
<div class="cell">Data61</div>
<div class="cell">Data62</div>
</div>
<div class="row">
<div class="cell">HeaderT7</div>
<div class="cell">Data71</div>
<div class="cell">Data72</div>
</div>
<div class="row">
<div class="cell">HeaderT8</div>
<div class="cell">Data81</div>
<div class="cell">Data82</div>
</div>
<div class="row">
<div class="cell">HeaderT9</div>
<div class="cell">Data91</div>
<div class="cell">Data92</div>
</div>
</div>
<div class="right">
<div class="row">
<div class="cell">HeaderTR</div>
<div class="cell">DataR1</div>
<div class="cell">DataR2</div>
</div>
</div>
</div>
You probably need to add width to your container. Right now it's set to 100% so it will not size beyond the browser window. Instead you could do something like this:
.container {
overflow: auto;
white-space: nowrap;
width:2000px;
}
I realize that you may need to change this value dynamically but hopefully this gets you started
Example:http://codepen.io/nilestanner/pen/jAjbdK
Try with For example:
css:
* {
box-sizing: border-box;
}
.left, .center, .right{
float:left
}
.center {
width:400px;
overflow: scroll;
display: block;
white-space: nowrap
}
#center-scroll{
width:2000px;
}
.center .row{
display:inline-block;
width:33%;
}
.center .row .cell{
min-width:100%;
}
.row{
float:left;
}
.cell {
padding: 3px;
border: 1px solid #bbb;
min-height: 25px;
min-width: 200px;
}
HTML
<div class="container">
<div class="left">
<div class="row" >
<div class="cell">HeaderL1</div>
<div class="cell">HeaderL2</div>
<div class="cell">HeaderL3</div>
</div>
</div>
<div class="center">
<div id="center-scroll">
<div class="row">
<div class="cell">HeaderT2</div>
<div class="cell">Data21</div>
<div class="cell">Data22</div>
</div>
<div class="row">
<div class="cell">HeaderT3</div>
<div class="cell">Data31</div>
<div class="cell">Data32</div>
</div>
<div class="row">
<div class="cell">HeaderT4</div>
<div class="cell">Data41</div>
<div class="cell">Data42</div>
</div>
<div class="row">
<div class="cell">HeaderT5</div>
<div class="cell">Data51</div>
<div class="cell">Data52</div>
</div>
<div class="row">
<div class="cell">HeaderT6</div>
<div class="cell">Data61</div>
<div class="cell">Data62</div>
</div>
<div class="row">
<div class="cell">HeaderT7</div>
<div class="cell">Data71</div>
<div class="cell">Data72</div>
</div>
<div class="row">
<div class="cell">HeaderT8</div>
<div class="cell">Data81</div>
<div class="cell">Data82</div>
</div>
<div class="row">
<div class="cell">HeaderT9</div>
<div class="cell">Data91</div>
<div class="cell">Data92</div>
</div>
</div>
</div>
<div class="right">
<div class="row">
<div class="cell">HeaderTR</div>
<div class="cell">DataR1</div>
<div class="cell">DataR2</div>
</div>
</div>
</div>

Resources