Reputation:
Short of creating a 7 column / 3 row table with a 1 pixel image that can be expanded to simulate the lines, how can this layout be reproduced using HTML and CSS without a table or an image for the "dividers"?
What I really like about it is how the lines don't intersect.
<!-- layout reproduced -->
<TABLE BORDER="0" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR ALIGN="center">
<TD CLASS="boldedcolor4text">the first</TD>
<TD><IMG SRC="/gfx/Style1/color1.gif" ALT="" WIDTH="1" HEIGHT="20"></TD>
<TD CLASS="boldedcolor4text">the second</TD>
<TD><IMG SRC="/gfx/Style1/color1.gif" ALT="" WIDTH="1" HEIGHT="20"></TD>
<TD CLASS="boldedcolor4text">the third</TD>
<TD><IMG SRC="/gfx/Style1/color1.gif" ALT="" WIDTH="1" HEIGHT="20"></TD>
<TD CLASS="boldedcolor4text">the fourth</TD>
</TR>
<TR ALIGN="center">
<TD COLSPAN="7"><IMG SRC="/gfx/Style1/color1.gif" ALT="" WIDTH="520" HEIGHT="1"></TD>
</TR>
<TR ALIGN="center">
<TD><A CLASS="image" HREF="><IMG SRC="1.jpg" ALT="" BORDER="0"></A></TD>
<TD><IMG SRC="/gfx/Style1/color1.gif" ALT="" WIDTH="1" HEIGHT="135"></TD>
<TD><A CLASS="image" HREF="><IMG SRC="2.jpg" ALT="" BORDER="0"></A></TD>
<TD><IMG SRC="/gfx/Style1/color1.gif" ALT="" WIDTH="1" HEIGHT="135"></TD>
<TD><A CLASS="image" HREF="><IMG SRC="3.jpg" ALT="" BORDER="0"></A></TD>
<TD><IMG SRC="/gfx/Style1/color1.gif" ALT="" WIDTH="1" HEIGHT="135"></TD>
<TD><A CLASS="image" HREF="><IMG SRC="4.jpg" ALT="" BORDER="0"></A></TD>
</TR>
</TABLE>
Upvotes: 8
Views: 568
Reputation: 1092
You could try it like: https://jsfiddle.net/wh48rjvt/
SCSS:
$border: 1px solid grey;
.table-row {
border-bottom: $border;
&:last-child {
border-bottom: 0;
}
.table-box {
border-right: $border;
margin: 0.75rem 0;
&:last-child {
border-right: 0;
}
}
}
this makes following CSS:
.table-row {
border-bottom: 1px solid grey;
}
.table-row:last-child {
border-bottom: 0;
}
.table-row .table-box {
border-right: 1px solid grey;
margin: 0.75rem 0;
}
.table-row .table-box:last-child {
border-right: 0;
}
HTML:
<div class="container">
<div class="table-row row">
<div class="table-box col-xs-3">1</div>
<div class="table-box col-xs-3">2</div>
<div class="table-box col-xs-3">3</div>
<div class="table-box col-xs-3">4</div>
</div>
<div class="table-row row">
<div class="table-box col-xs-3">5</div>
<div class="table-box col-xs-3">6</div>
<div class="table-box col-xs-3">7</div>
<div class="table-box col-xs-3">8</div>
</div>
...
</div>
And I used Bootstrap for the grid.
Upvotes: 1
Reputation: 19111
No dependencies for my solution. I create a flexbox .container
and then four flex .item
s. The default direction for flexbox is row
, which is what we want for the outer layout, but not for the contents of each item in the row. To adjust this, I changed the flex-direction
of the children (.item
) to column
since, in your example, the images are stacked beneath the anchors.
For the non-breaking border between the anchors and the images, I took a bit of a shortcut and moved the styles to a pseudo class. Notice the position: relative;
on .item
. This was done to create a safe container in which to hold the absolutely positioned pseudo class borders.
.container, .item {
display: flex;
}
.item {
flex-direction: column;
position: relative;
}
.item:before {
content: '';
border-top: 1px solid;
position: absolute;
width: 100%;
top: 2em;
}
.item:first-child:before {
left: 1.5em;
}
.item:last-child:before {
left: -1.5em;
}
.item:last-child .link,
.item:last-child .img {
border-right: none;
}
.link,
.img {
border-right: 1px solid;
}
.link {
text-align: center;
}
.img {
margin-top: 2em;
padding: 0.5em 1em 0.5em;
}
<div class="container">
<div class="item">
<a class="link" href="">link 1</a>
<img class="img" src="http://placehold.it/100x130" alt="" />
</div>
<div class="item">
<a class="link" href="">link 2</a>
<img class="img" src="http://placehold.it/100x130" alt="" />
</div>
<div class="item">
<a class="link" href="">link 3</a>
<img class="img" src="http://placehold.it/100x130" alt="" />
</div>
<div class="item">
<a class="link" href="">link 4</a>
<img class="img" src="http://placehold.it/100x130" alt="" />
</div>
</div>
Fiddle: https://jsfiddle.net/1sbx2h5e/
Upvotes: 10