I'm trying to build a grid that contains card-like items. The cells of each type (headline, image, text, button, ...) should have equal height in each row, determined by the content of the largest cell, as in the code snippet below.
Now I'm trying to limit the number of columns, and let the cards wrap, as if I used flex-wrap: wrap; in a flexbox-based solution. The number of columns should be determined via media query. Is this possible without using the not-yet-supported subgrids?
Additionally, how would a solution using subgrids look like? I guess it will degrade to cells with non-equal height in current browsers?
.grid {
display: grid;
grid-template-rows: repeat(4, auto);
grid-gap: 10px;
grid-auto-flow: column;
grid-auto-columns: auto;
}
<div class="grid">
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100" />
<p class="c">text
</p>
<button class="d">Button</button>
<h2 class="a">Header 2 is longer and may span multiple lines</h2>
<img class="b" src="https://placekitten.com/400/100" />
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et cursus ligula. Maecenas non pharetra dui, eu tincidunt mi. Vivamus vitae luctus risus. Etiam vehicula sem est.
</p>
<button class="d">Button</button>
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100" />
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et cursus ligula. Maecenas non pharetra dui, eu tincidunt mi. Vivamus vitae luctus risus. Etiam vehicula sem est, non ultricies lectus placerat eget.
</p>
<button class="d">Button</button>
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100" />
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et cursus ligula. Maecenas non pharetra dui, eu tincidunt mi. Vivamus vitae luctus risus. Etiam vehicula sem est, non ultricies lectus placerat eget. Suspendisse pulvinar arcu massa, quis
varius velit facilisis tincidunt. Proin sed cursus orci.
</p>
<button class="d">Button</button>
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100" />
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</p>
<button class="d">Button</button>
</div>
This is a good example of a situation when we need sub-grids - aligning the grid cousins is essential in layouts such as in this question.
Until browsers implement the proposed Level 2 spec of Subgrids, we can only wrap each column in an element and then wrap it using an outer grid container.
The below is an excerpt from the Editor's Draft for CSS Grid Layout Module Level 2:
2. Subgrids
A grid item can itself be a grid container by giving it display: grid; in this case the layout of its contents will be
independent of the layout of the grid it participates in.
In some cases it might be necessary for the contents of multiple grid
items to align to each other. A grid container that is itself a grid
item can defer the definition of its rows and columns to its parent
grid container, making it a subgrid. In this case, the grid items of
the subgrid participate in sizing the grid of the parent grid
container, allowing the contents of both grids to align.
A good read that discussed this problem can be found here.
Here's a mock-up using nested grid containers (sub-grids can look like this but without breaking the non-equal cousins rule) - see demo below:
.wrapper {
display: grid;
grid-gap: 10px;
grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
}
.grid {
display: grid;
grid-template-rows: repeat(4, 1fr);
justify-items: flex-start;
border: 1px solid #07c;
}
img {
width: 100%;
}
button {
align-self: center;
justify-self: center;
}
p {
padding: 0 10px;
}
<div class="wrapper">
<div class="grid">
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100" />
<p class="c">text
</p>
<button class="d">Button</button>
</div>
<div class="grid">
<h2 class="a">Header 2 is longer and may span multiple lines</h2>
<img class="b" src="https://placekitten.com/400/100" />
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et cursus ligula. Maecenas non pharetra dui, eu tincidunt mi. Vivamus vitae luctus risus. Etiam vehicula sem est.
</p>
<button class="d">Button</button>
</div>
<div class="grid">
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100" />
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et cursus ligula. Maecenas non pharetra dui, eu tincidunt mi. Vivamus vitae luctus risus. Etiam vehicula sem est, non ultricies lectus placerat eget.
</p>
<button class="d">Button</button>
</div>
<div class="grid">
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100" />
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et cursus ligula. Maecenas non pharetra dui, eu tincidunt mi. Vivamus vitae luctus risus. Etiam vehicula sem est, non ultricies lectus placerat eget. Suspendisse pulvinar arcu massa, quis
varius velit facilisis tincidunt. Proin sed cursus orci.
</p>
<button class="d">Button</button>
</div>
<div class="grid">
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100" />
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</p>
<button class="d">Button</button>
</div>
</div>
A possible definition could be:
.wrapper {
display: grid; /* outer grid */
/* sets a wrapping grid container with items of width around 400px */
grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
}
.grid {
grid-row: span 4; /* span 4 rows */
display: grid;
/* magic is here */
grid-template-rows: subgrid; /* create a sub-grid with the 4 parent grid rows */
}
You have already a solution now, with a not ideal browser support, but anyway working, that is display: content
You need to wrap your elements in an auxiliary div, I set those to the class card. Then, make card disappear of the layour with the display : content:
.grid {
display: grid;
grid-gap: 10px;
grid-auto-columns: 1fr;
grid-auto-flow: dense;
}
.card {
display: contents;
}
.card:nth-child(odd) * {
grid-column-start: 1;
}
.card:nth-child(even) * {
grid-column-start: 2;
}
#media screen and ( min-width: 1300px) {
.card:nth-child(3n + 0) * {
grid-column-start: 3;
}
.card:nth-child(3n + 1) * {
grid-column-start: 1;
}
.card:nth-child(3n + 2) * {
grid-column-start: 2;
}
}
<div class="grid">
<div class="card">
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100">
<p class="c">text
</p>
<button class="d">Button</button>
</div>
<div class="card">
<h2 class="a">Header 2 is longer and may span multiple lines</h2>
<img class="b" src="https://placekitten.com/400/100">
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et cursus ligula. Maecenas non pharetra dui, eu tincidunt mi. Vivamus vitae luctus risus. Etiam vehicula sem est.
</p>
<button class="d">Button</button>
</div>
<div class="card">
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100">
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et cursus ligula. Maecenas non pharetra dui, eu tincidunt mi. Vivamus vitae luctus risus. Etiam vehicula sem est, non ultricies lectus placerat eget.
</p>
<button class="d">Button</button>
</div>
<div class="card">
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100">
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et cursus ligula. Maecenas non pharetra dui, eu tincidunt mi. Vivamus vitae luctus risus. Etiam vehicula sem est, non ultricies lectus placerat eget. Suspendisse pulvinar arcu massa, quis
varius velit facilisis tincidunt. Proin sed cursus orci.
</p>
<button class="d">Button</button>
</div>
<div class="card">
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100">
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</p>
<button class="d">Button</button>
</div>
</div>
I just missed the easiest solution:
Since you have already a flat HTML, and are intending to use media queries, you can just use the same idea, (nth- selectors) but on the flat HTMl
.grid {
display: grid;
grid-gap: 10px;
grid-auto-flow: dense;
grid-auto-rows: 1fr;
}
.card {
display: contents;
}
h2,
img,
p,
button {
grid-column-start: 1;
}
h2:nth-of-type(even),
img:nth-of-type(even),
p:nth-of-type(even),
button:nth-of-type(even) {
grid-column-start: 2;
}
#media screen and ( min-width: 1300px) {
h2:nth-of-type(3n + 1),
img:nth-of-type(3n + 1),
p:nth-of-type(3n + 1),
button:nth-of-type(3n + 1) {
grid-column-start: 1;
}
h2:nth-of-type(3n + 2),
img:nth-of-type(3n + 2),
p:nth-of-type(3n + 2),
button:nth-of-type(3n + 2) {
grid-column-start: 2;
}
h2:nth-of-type(3n),
img:nth-of-type(3n),
p:nth-of-type(3n),
button:nth-of-type(3n) {
grid-column-start: 3;
}
}
<div class="grid">
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100" />
<p class="c">text
</p>
<button class="d">Button</button>
<h2 class="a">Header 2 is longer and may span multiple lines</h2>
<img class="b" src="https://placekitten.com/400/100" />
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et cursus ligula. Maecenas non pharetra dui, eu tincidunt mi. Vivamus vitae luctus risus. Etiam vehicula sem est.
</p>
<button class="d">Button</button>
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100" />
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et cursus ligula. Maecenas non pharetra dui, eu tincidunt mi. Vivamus vitae luctus risus. Etiam vehicula sem est, non ultricies lectus placerat eget.
</p>
<button class="d">Button</button>
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100" />
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et cursus ligula. Maecenas non pharetra dui, eu tincidunt mi. Vivamus vitae luctus risus. Etiam vehicula sem est, non ultricies lectus placerat eget. Suspendisse pulvinar arcu massa, quis
varius velit facilisis tincidunt. Proin sed cursus orci.
</p>
<button class="d">Button</button>
<h2 class="a">Header 1</h2>
<img class="b" src="https://placekitten.com/400/100" />
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</p>
<button class="d">Button</button>
</div>
Related
I need an image (image container to be precise) to resize according to container height and maintain its aspect ratio. Longer the text = bigger the image. Right now its ether image getting out of container or just staying still.
article,
.information,
.image {
margin: 8px;
border: 2px solid black;
}
article {
display: flex;
}
.information {
flex-grow: 1;
}
.image {
font-size: 0;
}
<article>
<div class="information">
<h3>too much text. image must be resized to fill whole height and stay square</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer congue, turpis in sollicitudin fringilla, sapien augue consectetur augue, id lacinia nibh massa at justo. Praesent pellentesque nunc elementum cursus faucibus. Donec vel diam scelerisque,
pharetra velit a, pharetra quam. Ut tristique justo id justo pharetra, eget sollicitudin libero mattis.</p>
</div>
<div class="image">
<img src="https://via.placeholder.com/150" />
</div>
</article>
<hr/>
<article>
<div class="information">
<h3>too little text</h3>
<p>Lorem ipsum dolor sit amet</p>
</div>
<div class="image">
<img src="https://via.placeholder.com/150" />
</div>
</article>
article,
.information,
.image {
margin: 8px;
border: 2px solid black;
}
.image{
width:50%;
}
.image img{
height:100%;
width:100%;
}
article {
display: flex;
}
.information {
width:50%;
flex-shrink:0;
}
.image {
font-size: 0;
}
<article>
<div class="information">
<h3>too much text. image must be resized to fill whole height and stay square</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer congue, turpis in sollicitudin fringilla, sapien augue consectetur augue, id lacinia nibh massa at justo. Praesent pellentesque nunc elementum cursus faucibus. Donec vel diam scelerisque,
pharetra velit a, pharetra quam. Ut tristique justo id justo pharetra, eget sollicitudin libero mattis
pellentesque nunc elementum cursus faucibus. Donec vel diam scelerisque,
pharetra velit a, pharetra quam. Ut tristique justo id justo pharetra, eget sollicitudin libero mattis.</p>
</div>
<div class="image">
<img src="https://via.placeholder.com/150" />
</div>
</article>
<hr/>
<article>
<div class="information">
<h3>too little text</h3>
<p>Lorem ipsum dolor sit amet</p>
</div>
<div class="image">
<img src="https://via.placeholder.com/150" />
</div>
</article>
I have a template like this:
I want to maintain the same height between each item of both columns, depending on the one that has the biggest height, but only when they are side by side. In smaller screens, when they have width: 100%, each div has its own height depending of its own content height.
It should look like this:
I think that what I want is something like display: table, but I need both columns to be responsive.
All the questions I´have found are about maintaining the same height in both columns, but I´m already using flexbox to achieve this.
Is it possible to achieve what I vant with css only?
EDIT: Added code snippet. I forgot to mention that it needs to be supported by Chrome 36 (Android L WebView).
This question´s first answer shows what I wanted to achieve, but display:subgrid is not supported by any version Chrome at present:
Align child elements of different blocks
.title {
background: #b6fac0;
}
.content {
background: #b6b6fa;
}
.footer {
background: #f7f5b5;
}
.col-50 {
border: 1px solid red;
}
<link href="http://code.ionicframework.com/1.3.3/css/ionic.min.css" rel="stylesheet" />
<ion-content>
<div class="row responsive-sm">
<div class="col-50">
<div class="padding title">
Veeeeeeeeeeeeeeery veeeeeeeeeery veeeeeeeeeeeeeeery veeeeeeeeeery veeeeeeeeeeeeeeery veeeeeeeeeery veeeeeeeeeeeeeeery veeeeeeeeeery loooooooooooong title </div>
<div class="padding content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque rhoncus neque vitae lorem varius placerat. Donec blandit mi non mauris ornare faucibus. Quisque mollis nunc in tortor dapibus, et ornare lacus pharetra
</div>
<div class="padding footer">
Footer
</div>
</div>
<div class="col-50">
<div class="padding title">
Title </div>
<div class="padding content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque rhoncus neque vitae lorem varius placerat. Donec blandit mi non mauris ornare faucibus. Quisque mollis nunc in tortor dapibus, et ornare lacus pharetra. Phasellus tortor tortor, luctus
in dapibus sed, ultrices eget lorem. Morbi vehicula fermentum arcu, nec egestas augue. Fusce orci ex, sodales ut tellus sit amet, pretium pulvinar odio. Suspendisse potenti. Phasellus convallis metus sed erat rhoncus, eu tristique lacus fermentum.
</div>
<div class="padding footer">
Footer
</div>
</div>
</div>
</ion-content>
you may take a look at #supports to filter possible display:option or subgrid .
example with display:contents
.title {
background: #b6fac0;
}
.content {
background: #b6b6fa;
}
.footer {
background: #f7f5b5;
}
.col-50 {
border: 1px solid red;
}
#supports (display: contents) {
.row.responsive-sm {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-column-gap: 1em;
}
.col-50 {
display: contents
}
.title {
grid-row: 1
}
.content {
grid-row: 2;
}
#media screen and (max-width:500px) {
/* set the break point to the right value */
.row.responsive-sm,
.col-50 {
display: block;
}
}
}
<link href="http://code.ionicframework.com/1.3.3/css/ionic.min.css" rel="stylesheet" />
<ion-content>
<div class="row responsive-sm">
<div class="col-50">
<div class="padding title">
Veeeeeeeeeeeeeeery veeeeeeeeeery veeeeeeeeeeeeeeery veeeeeeeeeery veeeeeeeeeeeeeeery veeeeeeeeeery veeeeeeeeeeeeeeery veeeeeeeeeery loooooooooooong title </div>
<div class="padding content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque rhoncus neque vitae lorem varius placerat. Donec blandit mi non mauris ornare faucibus. Quisque mollis nunc in tortor dapibus, et ornare lacus pharetra
</div>
<div class="padding footer">
Footer a
</div>
</div>
<div class="col-50">
<div class="padding title">
Title </div>
<div class="padding content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque rhoncus neque vitae lorem varius placerat. Donec blandit mi non mauris ornare faucibus. Quisque mollis nunc in tortor dapibus, et ornare lacus pharetra. Phasellus tortor tortor, luctus
in dapibus sed, ultrices eget lorem. Morbi vehicula fermentum arcu, nec egestas augue. Fusce orci ex, sodales ut tellus sit amet, pretium pulvinar odio. Suspendisse potenti. Phasellus convallis metus sed erat rhoncus, eu tristique lacus fermentum.
</div>
<div class="padding footer">
Footer
</div>
</div>
</div>
</ion-content>
usefull for a fast check on supports on properties: https://caniuse.com/
I have implemented a layout using css Grid.
The left column should only scroll and the right one should be sticky or fixed.
It's working fine but the scrollbar break the design.
Can scrollbar be removed or any other solution?
I know that is native of the browser but what can I do? (I also tried to change the design but its now supported by Firefox)
.container {
height: 100vh;
display: grid;
grid-template-areas: "list content";
grid-template-columns: 150px 1fr;
grid-template-rows: auto;
color: white;
}
.container .list {
overflow: auto;
grid-area: list;
background-color: #131418;
padding: 20px;
}
.container .list .items {
margin-top: 15px;
display: block;
}
.container .content {
grid-area: content;
background-color: #15161b;
padding: 15px;
position: sticky;
}
<div class="container">
<div class="list">
<h5>
Items
</h5>
<div class="items">
<div class="item">
<small>User name</small>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec id efficitur arcu. Mauris ut nulla id lorem tempor malesuada id quis libero. Duis ornare massa at ex sodales blandit.
</p>
<small>Made by ...</small>
</div>
<div class="item" style="margin-top: 15px;">
<small>User name</small>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec id efficitur arcu. Mauris ut nulla id lorem tempor malesuada id quis libero. Duis ornare massa at ex sodales blandit.
</p>
<small>Made by ...</small>
</div>
</div>
</div>
<div class="content">
<h1>
Hello world
</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec id efficitur arcu. Mauris ut nulla id lorem tempor malesuada id quis libero. Duis ornare massa at ex sodales blandit.
</p>
</div>
</div>
A possible solution is to improve scrollbar's look.
Take a look at
perfect-scrollbar for example.
Perfect-scrollbar will only be displayed when mouse is hover related DIV.
Demo screenshot
(Look at the right very tiny scrollbar)
author's JSFiddle demo
var ps = new PerfectScrollbar('.container');
Your code snippet resolved
var ps = new PerfectScrollbar('.list');
.container {
height: 100vh;
display: grid;
grid-template-areas: "list content";
grid-template-columns: 150px 1fr;
grid-template-rows: auto;
color: white;
}
.container .list {
overflow: auto;
grid-area: list;
background-color: #131418;
padding: 20px;
}
.container .list .items {
margin-top: 15px;
display: block;
}
.container .content {
grid-area: content;
background-color: #15161b;
padding: 15px;
position: sticky;
}
<link href="https://rawgit.com/utatti/perfect-scrollbar/master/css/perfect-scrollbar.css" rel="stylesheet"/>
<script src="https://rawgit.com/utatti/perfect-scrollbar/master/dist/perfect-scrollbar.js"></script>
<div class="container">
<div class="list">
<h5>
Items
</h5>
<div class="items">
<div class="item">
<small>User name</small>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec id efficitur arcu. Mauris ut nulla id lorem tempor malesuada id quis libero. Duis ornare massa at ex sodales blandit.
</p>
<small>Made by ...</small>
</div>
<div class="item" style="margin-top: 15px;">
<small>User name</small>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec id efficitur arcu. Mauris ut nulla id lorem tempor malesuada id quis libero. Duis ornare massa at ex sodales blandit.
</p>
<small>Made by ...</small>
</div>
</div>
</div>
<div class="content">
<h1>
Hello world
</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec id efficitur arcu. Mauris ut nulla id lorem tempor malesuada id quis libero. Duis ornare massa at ex sodales blandit.
</p>
</div>
</div>
I'm struggling to achieve responsive column. Currently all columns are not the same height. When the screen gets smaller, the paragraphs are not the same level, I am trying to make them the same level no matter what screen size. My next problem is the button will also not be the same level in all columns.
Bellow is currently my HTML:
<div class="container">
<div class="section">
<img src="http://via.placeholder.com/500x400" alt="" width="400" height="300" style="max-width:90%;height:auto;" />
<h2>test heading text</h2 >
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
Learn more
</div>
<div class="section">
<img src="http://via.placeholder.com/500x400" alt="" width="400" height="300" style="max-width:90%;height:auto;" /> <h2>Fencing and Gates</h2>
<h2>test heading text long</h2 >
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vestibulum faucibus turpis, sed blandit mauris bibendum sit amet. Praesent congue enim at orci dapibus accumsan. Maecenas id leo at elit vestibulum sagittis at in ex. Cras vulputate laoreet dictum. Vestibulum nec quam placerat, blandit orci in, hendrerit ante. </p>
Learn more
</div>
<div class="section">
<img src="http://via.placeholder.com/500x400" alt="" width="400" height="300" style="max-width:90%;height:auto;" />
<h2>test heading text longer </h2 >
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vestibulum faucibus turpis, sed blandit mauris bibendum sit amet. Praesent congue enim at orci dapibus accumsan. </p>
Learn more
</div>
<div class="section">
<img src="http://via.placeholder.com/500x400" alt="" width="400" height="300" style="max-width:90%;height:auto;" />
<h2>test heading text longer longer </h2 >
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vestibulum faucibus turpis, sed blandit mauris bibendum sit amet. Praesent congue enim at orci dapibus accumsan. </p>
Learn more
</div>
<div class="section">
<img src="http://via.placeholder.com/500x400" alt="" width="400" height="300" style="max-width:90%;height:auto;" />
<h2>test heading text</h2 >
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vestibulum faucibus turpis, sed blandit mauris bibendum sit amet. Praesent congue enim at orci dapibus accumsan. </p>
Learn more
</div>
<div class="section">
<img src="http://via.placeholder.com/500x400" alt="" width="400" height="300" style="max-width:90%;height:auto;" />
<h2>Block Paved Driveways and Paths</h2>
<h2>test heading text</h2 >
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vestibulum faucibus turpis, sed blandit mauris bibendum sit amet. Praesent congue enim at orci dapibus accumsan. Maecenas id leo at elit vestibulum sagittis at in ex. Cras vulputate laoreet dictum. Vestibulum nec quam placerat, blandit orci in, hendrerit ante. </p>
Learn more
</div>
<div class="section">
<img src="http://via.placeholder.com/500x400" alt="" width="400" height="300" style="max-width:90%;height:auto;" />
<h2>test heading text</h2 >
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vestibulum faucibus turpis, sed blandit mauris bibendum sit amet. Praesent congue enim at orci dapibus accumsan. </p>
Learn more
</div>
<div class="section">
<img src="http://via.placeholder.com/500x400" alt="" width="400" height="300" style="max-width:90%;height:auto;" />
<h2>test heading text</h2 >
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vestibulum faucibus turpis, sed blandit mauris bibendum sit amet. Praesent congue enim at orci dapibus accumsan. </p>
Learn more
</div>
<div class="section">
<img src="http://via.placeholder.com/500x400" alt="" width="400" height="300" style="max-width:90%;height:auto;" />
<h2>test heading text</h2 >
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vestibulum faucibus turpis, sed blandit mauris bibendum sit amet. Praesent congue enim at orci dapibus accumsan. </p>
Learn more
</div>
</div>
Below is my CSS:
.container:after { /*clear float*/
content: "";
display: table;
width: 100%;
clear: both;
}
.container {
margin-left: 100px;
margin-right: 100px;
text-align: center;
padding-top: 30px;
}
.section {
float: left;
width: 33.3333%;
padding-bottom: 50px;
border: 1px solid;
box-sizing: border-box;
display: table-cell;
}
.section p {
padding-bottom: 50px;
text-align: center;
font-family: "Montserrat", sans-serif;
font-size: 19px;
padding-left: 25px;
padding-right: 25px;
}
.section h2 {
text-align: center;
font-family: "Slabo 27px", serif;
font-size: 24px;
font-weight: 700;
text-align: center;
padding-left: 25px;
padding-right: 25px;
}
#media (max-width: 768px) {
.section {
float: none;
width: auto;
}
}
below is a js fiddle of what I currently have
https://jsfiddle.net/b147rmdh/
Any help on this would be greatly appreciated!
You need to specify a height for each column for them to all be the same height. If you don't then the columns will size themselves based on the amount of content they contain (which is currently what is happening in your code). More specifically relating to your code, if you add a specific height to your .section class, then all the columns should be the same height.
Once you have done this, you could use absolute positioning on all of the elements within the columns (the headers, paragraphs, buttons, etc) so that they all line up. If you aren't very familiar with absolute positioning and the position property in general, here is a great reference that explains positioning well. Definitely recommend giving it a read and taking the time to get a good understanding of positioning since it's one of the most fundamental CSS skills.
I'd suggest a Flexbox with wrapping.
.container {
display: flex;
flex-wrap: wrap;
}
.section {
width: 33.3333%;
}
Once you've done that, you can use a similar method vertically if you wrap the upper content in one element and keep the button separate. Set your flex-direction to column and justify-content to space-between.
The three 'Spares Solutions' columns are in a container called relative. I have given it the properties below:
.relative {
top: -10rem;
position: relative;
}
I know that this is expected behaviour which is what you see in the screenshot.
You can also see that there is content below the three columns. This is where I get my problem.
I would like to know if there is a way to give something a minus value and get rid of the space where it expects to see the three columns.
one solution would be to give the content a minus 10 value. But I would like to avoid this due to the space then being under the content.
This is my current HTML:
<div class="relative home-top-minus">
<div class="row three-column-margin">
<div class="column small-12 medium-4">
<div class="panel-orange text-center column-padding">
<img src="http://placehold.it/200x150" alt="" />
<h3 class="heading-tan heading-padding-small">SPARES SOLUTIONS</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sit amet ultrices lorem, eget malesuada nulla. Pellentesque vel mattis nunc. Fusce quis ultricies quam,
ut molestie ex. Nulla facilisi. Praesent id magna consequat, pulvinar ligula sit amet, maximus tellus.
</p>
<a href="#"
class="button large">LEARN MORE</a>
</div>
</div>
<div class="column small-12 medium-4">
<div class="panel-light-orange text-center column-padding">
<img src="http://placehold.it/200x150" alt="" />
<h3 class="heading-brown heading-padding-small">SPARES SOLUTIONS</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sit amet ultrices lorem, eget malesuada nulla. Pellentesque vel mattis nunc. Fusce quis ultricies quam,
ut molestie ex. Nulla facilisi. Praesent id magna consequat, pulvinar ligula sit amet, maximus tellus.
</p>
<a href="#"
class="button large">LEARN MORE</a>
</div>
</div>
<div class="column small-12 medium-4">
<div class="panel-brown text-center column-padding">
<img src="http://placehold.it/200x150" alt="" />
<h3 class="heading-light-orange heading-padding-small">SPARES SOLUTIONS</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sit amet ultrices lorem, eget malesuada nulla. Pellentesque vel mattis nunc. Fusce quis ultricies quam,
ut molestie ex. Nulla facilisi. Praesent id magna consequat, pulvinar ligula sit amet, maximus tellus.
</p>
<a href="#"
class="button large">LEARN MORE</a>
</div>
</div>
</div>
<div class="row">
<div class="column small-12 medium-4">
<div class="bubble">
<p>
“Click Spares have saved us
thousands since we joined!!!”,
really great service and they
know exactly how to deal with
tricky customers”
</p>
<p class="heading-light-orange">
Product Retail Manager
</p>
</div>
</div>
<div class="column small-12 medium-8">
<h2 class="h1 heading-light-orange">WHY CLICK SPARES</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sit amet ultrices lorem, eget malesuada nulla. Pellentesque vel mattis nunc. Fusce quis ultricies quam,
ut molestie ex. Nulla facilisi. Praesent id magna consequat, pulvinar ligula sit amet, maximus tellus.
</p>
<a href="#"
class="button large alt">LEARN MORE</a>
</div>
</div>
</div>
use margin-top:-10rem instead of top:-10rem and use z-index:999 or something bigger than the div on the top ( the div before .relative ) has ( in this example top has z-index:2 ) . if it doesn't have a z-index give one manually
.top{z-index:2} , .relative{z-index:3}
let me know if it works ( in the snippet example it works )
.relative {
margin-top: -10rem;
position: relative;
z-index:999;
}
.top {
height:200px;
background:blue;
position:relative;
z-index:2;
}
.bottom {
height:200px;
background:blue;
}
<link href="https://maxcdn.bootstrapcdn.com/bootswatch/latest/journal/bootstrap.min.css" rel="stylesheet"/>
<div class="top">
</div>
<div class="relative home-top-minus">
<div class="row three-column-margin">
<div class="column small-12 medium-4">
<div class="panel-orange text-center column-padding">
<img src="http://placehold.it/200x150" alt="" />
<h3 class="heading-tan heading-padding-small">SPARES SOLUTIONS</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sit amet ultrices lorem, eget malesuada nulla. Pellentesque vel mattis nunc. Fusce quis ultricies quam,
ut molestie ex. Nulla facilisi. Praesent id magna consequat, pulvinar ligula sit amet, maximus tellus.
</p>
<a href="#"
class="button large">LEARN MORE</a>
</div>
</div>
<div class="column small-12 medium-4">
<div class="panel-light-orange text-center column-padding">
<img src="http://placehold.it/200x150" alt="" />
<h3 class="heading-brown heading-padding-small">SPARES SOLUTIONS</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sit amet ultrices lorem, eget malesuada nulla. Pellentesque vel mattis nunc. Fusce quis ultricies quam,
ut molestie ex. Nulla facilisi. Praesent id magna consequat, pulvinar ligula sit amet, maximus tellus.
</p>
<a href="#"
class="button large">LEARN MORE</a>
</div>
</div>
<div class="column small-12 medium-4">
<div class="panel-brown text-center column-padding">
<img src="http://placehold.it/200x150" alt="" />
<h3 class="heading-light-orange heading-padding-small">SPARES SOLUTIONS</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sit amet ultrices lorem, eget malesuada nulla. Pellentesque vel mattis nunc. Fusce quis ultricies quam,
ut molestie ex. Nulla facilisi. Praesent id magna consequat, pulvinar ligula sit amet, maximus tellus.
</p>
<a href="#"
class="button large">LEARN MORE</a>
</div>
</div>
</div>
<div class="row">
<div class="column small-12 medium-4">
<div class="bubble">
<p>
“Click Spares have saved us
thousands since we joined!!!”,
really great service and they
know exactly how to deal with
tricky customers”
</p>
<p class="heading-light-orange">
Product Retail Manager
</p>
</div>
</div>
<div class="column small-12 medium-8">
<h2 class="h1 heading-light-orange">WHY CLICK SPARES</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sit amet ultrices lorem, eget malesuada nulla. Pellentesque vel mattis nunc. Fusce quis ultricies quam,
ut molestie ex. Nulla facilisi. Praesent id magna consequat, pulvinar ligula sit amet, maximus tellus.
</p>
<a href="#"
class="button large alt">LEARN MORE</a>
</div>
</div>
</div>
<div class="bottom">
</div>
Just use margin-top: -10rem; instead of top: -10rem;