So I'm trying to create a template where one div is a picture and another one is a text with background. Now i want to make this template responsive, so that the text is going beneath the picture at a certain px width. Looking through stackoverflow i have seen countless posts that say you should use a flexbox. I tried, but i cant get it quite right.
So on Desktop it should look like this: https://imgur.com/a/XfJDwKL and on a Smartphone it should jump over here https://imgur.com/a/8KaKJxF
I need to have the margin to the sides, at least on the desktop version. Now my problem is, that my picture is having no limitations on my site and is getting too big, that an automatic switch to rows is happening(as i understand it).
My code is here : https://jsfiddle.net/wqesp83a/
.container {
display: inline-flex;
border: 1px solid black;
margin: 5%;
width: 90%;
}
.flex-direction {
flex-direction: row;
}
.div1 {
display: flex;
border-right: 1px solid black;
}
h {
color: #90bd49;
font-size: 30px;
}
p {
color: #333333;
font-size: 16px;
}
.div2 {
display: flex;
background-color: #fff;
max-width: 50%;
padding: 1%;
background-color: #e3e3e3;
}
span {
font-size: 16px;
text-align: left;
}
#media only screen and (min-width: 0px) and (max-width: 500px) {
.flex-direction {
flex-direction: column;
}
.div1 {
max-width: 100%;
border-right: none;
border-bottom: 1px solid black;
}
.div2 {
max-width: 100%;
}
.container {
margin: 0%;
}
<div class="container flex-direction">
<div class="div1"><span><img alt="Fotoabzüge" src="https://s3.eu-central-1.amazonaws.com//pbx-sw-profotolab/media/79/95/4c/1673964627/bild4_(1).jpg" width="100%" height="100%" /></span></div>
<div class="div2"><span><h>Lorem ipsum</h> <p> Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud.Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud.Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud.Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud.</p> </span></div>
</div>
I tried to limit the width and height of the divs and the picture but either it doesnt help or im breaking the whole thing even more. If someone could help me see my mistakes here, i would be very thankful.
grid to the rescue:
grid-template-columns: repeat(auto-fit, minmax(400px, 1fr))
will create a grid column for each child of the container, as long as they can stretch to 400px width. When there's not enough space for the grid items to be 400px in width, they will wrap into a single column. Just swap the px value to whatever you want.
grid-auto-rows: 1fr will let the two columns have equal height.
.container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
grid-auto-rows: 1fr;
border: 1px solid black;
margin: 5%;
width: 90%;
}
.flex-direction {
flex-direction: row;
}
.div1 {
display: flex;
border-right: 1px solid black;
}
h {
color: #90bd49;
font-size: 30px;
}
p {
color: #333333;
font-size: 16px;
}
.div2 {
display: flex;
background-color: #fff;
/* max-width: 50%; */
padding: 1%;
background-color: #e3e3e3;
}
span {
font-size: 16px;
text-align: left;
}
#media only screen and (min-width: 0px) and (max-width: 500px) {
.flex-direction {
flex-direction: column;
}
.div1 {
max-width: 100%;
border-right: none;
border-bottom: 1px solid black;
}
.div2 {
max-width: 100%;
}
.container {
margin: 0%;
}
<div class="container flex-direction">
<div class="div1"><span><img alt="Fotoabzüge" src="https://s3.eu-central-1.amazonaws.com//pbx-sw-profotolab/media/79/95/4c/1673964627/bild4_(1).jpg" width="100%" height="100%" /></span></div>
<div class="div2"><span><h>Lorem ipsum</h> <p> Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud.Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud.Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud.Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud.</p> </span></div>
</div>
Related
For my webpage I am tried to make it a one page website that fits all screen without scrolling, but I had white spaces in between my section and nav and footer so I added this box-sizing code:
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
It works for my desktop screen and s10 galaxy phone, but when I check my laptop the footer was stuck at something like "bottom: 10px" but when I check the css using inspect, it shows the css for the footer is at bottom: 0; You can view this bug via the snippet and if the using inspect and change width to >1000px. In my opinion it might have to do with the #media screen and (max-width: 1000px) which i set it to 1000px, If I change the height of section, class main, it will move the footer into the correct position but thats not the case for the different screen size monitors.
If I remove the box-sizing, the white spaces (not padding or margin) is above my section tag which I do not want but the footer is at bottom: 0px. So I am 100% confused. is there something wrong with my css or am I missing something that would be a fix all solution. Any help would be great! Thank you for the help in advance!
html,
body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
font-family: sans-serif;
}
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
.main {
display: grid;
justify-content: center;
align-content: center;
text-align: center;
height: 91.8%;
padding: 10% 5%;
margin-left: auto;
margin-right: auto;
}
.headerNav {
background-color: rgb(0, 0, 0);
color: white;
font-weight: bold;
z-index: 100;
max-width: 100%;
right: 0;
top: 0;
left: 0;
padding: 10px 0px;
font-size: 20px;
display: grid;
grid-template-columns: auto auto;
}
.homePG {
text-transform: uppercase;
text-decoration: none;
text-align: left;
padding: 10px 10px;
}
.headerLogin {
display: inline;
text-align: right;
line-height: 5px;
grid-gap: 5px;
padding: 0px 10px;
}
.navIcon {
display: none;
text-align: right;
color: blue;
padding: 0px 10px;
}
#mobile-navLinks {
margin-top: 10px;
padding: 0px 5px;
display: none;
text-decoration: none;
text-align: left;
grid-column-start: 1;
grid-column-end: 3;
}
footer {
position: relative;
text-align: center;
background-color: black;
color: white;
padding: 10px;
font-size: 15px;
bottom: 0;
}
#media screen and (max-width: 1000px) {
#mobile-navLinks {
grid-template-columns: 1fr;
}
.main {
height: 91.5%;
}
.homePGh1 {
font-size: 15px;
}
.homePGpara {
font-size: 13px;
}
.headerLogin {
display: none;
}
.navIcon {
display: block;
}
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<nav class="headerNav">
<nav>
HOME
</nav>
<div class="headerLogin">
HOME
HOME
HOME
</div>
<nav class="navIcon">
<a href="javascript:void(0);" class="icon" onclick="mobileNavs()">
<i class="fa fa-bars"></i></a>
</nav>
<div id="mobile-navLinks">
HOME
HOME
HOME
</div>
</nav>
<section class="main">
<div>
<h1 class="homePGh1">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </h1>
<p class="homePGpara">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p class="homePGpara">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Augue interdum velit euismod in pellentesque massa placerat duis ultricies. Purus ut faucibus pulvinar elementum. Nunc sed
blandit libero volutpat. Fermentum leo vel orci porta non pulvinar. </p>
<p class="homePGpara">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Augue interdum velit euismod in pellentesque massa placerat duis ultricies. Purus ut faucibus pulvinar elementum. Nunc sed
blandit libero volutpat. Fermentum leo vel orci porta non pulvinar.</p>
</div>
</section>
<footer>
© 2020
</footer>
</body>
</html>
When I set the .sidebar width to be 100%, it gets smaller than before.
However, when I remove the body's font-size: 1.3rem and toggle the .sidebar's width: 100%, it gets slightly larger.
I know that when we set the font-size to be 1.3rem, .primary-content's horizontal width (if it didn't wrap) should still be the same ratio as the .sidebar's width (if it didn't wrap).
So I'm not sure how flexbox calculates width: 100%
body {
font-size: 1.3rem;
}
h1 {
margin-top: 0;
}
.container {
width: 80%;
max-width: 1100px;
margin: 0 auto;
}
.row {
display: flex;
}
.primary-content {
background-color: moccasin;
}
.sidebar {
/* width: 100%; */
padding: 1em;
text-align: center;
color: #fff;
background-color: #136c72;
}
<main class="main container row">
<section class="primary-content">
<h2>Quality designs made custom, on demand, just for you</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore
et dolore magna aliqua. Ut enim ad minim veniam.</p>
</section>
<aside class="sidebar">
<h2>Cheap</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.</p>
</aside>
</main>
Here's the codepen.
https://codepen.io/Fullchee/pen/OJMBovq
It's all about the initial width here. To understand this let's take another simple example with less code:
.box {
display: flex;
width: 50%;
border: 2px solid red;
margin: auto;
}
.box>div {
border: 1px solid green;
}
<div class="box">
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris nulla nisi, accumsan vel purus nec, pretium dictum ex. Suspendisse pellentesque velit eget turpis porttitor efficitur
</div>
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris nulla nisi, accumsan vel purus nec, pretium dictum ex. Suspendisse pellentesque velit eget turpis porttitor efficitur
</div>
</div>
<div class="box">
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris nulla nisi, accumsan vel purus nec, pretium dictum ex. Suspendisse pellentesque velit eget turpis porttitor efficitur
</div>
<div style="width:100%;">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris nulla nisi, accumsan vel purus nec, pretium dictum ex. Suspendisse pellentesque velit eget turpis porttitor efficitur
</div>
</div>
It's trivial, that the second case seems a bit strange because the width is reduced but this is logical.
First, you should notice that both elements have the same content and the content need to wrap inside each one because there is not enough space.
If we reduce the content it will be different:
.box {
display: flex;
width: 50%;
border: 2px solid red;
margin: auto;
}
.box>div {
border: 1px solid green;
}
<div class="box">
<div>
Lorem ipsum dolor sit amet,
</div>
<div>
Lorem ipsum dolor sit amet,
</div>
</div>
<div class="box">
<div>
Lorem ipsum dolor sit amet,
</div>
<div style="width:100%;">
Lorem ipsum dolor sit amet,
</div>
</div>
To understand both cases, you need to understand the flexbox algorithm that I will summarize in 3 points:
We first set the initial width of each element
If the total width is bigger that the container width, we shrink both elements
The shrink factor consider the negative free space (total width - container width) and the width of each element.
The trick is in the (1).
Without width:100% we will have the following in (1)
$('.box div').each(function() {
console.log($(this).width());
})
.box {
display: flex;
width: 50%;
border: 2px solid red;
margin: auto;
}
.box>div {
border: 1px solid green;
flex-shrink:0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="box">
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris nulla nisi, accumsan vel purus nec, pretium dictum ex. Suspendisse pellentesque velit eget turpis porttitor efficitur
</div>
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris nulla nisi, accumsan vel purus nec, pretium dictum ex. Suspendisse pellentesque velit eget turpis porttitor efficitur
</div>
</div>
Both elements have the same width so both will shrink the same way to get the following:
$('.box div').each(function() {
console.log($(this).width());
})
.box {
display: flex;
width: 50%;
border: 2px solid red;
margin: auto;
}
.box>div {
border: 1px solid green;
flex-shrink:1;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="box">
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris nulla nisi, accumsan vel purus nec, pretium dictum ex. Suspendisse pellentesque velit eget turpis porttitor efficitur
</div>
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris nulla nisi, accumsan vel purus nec, pretium dictum ex. Suspendisse pellentesque velit eget turpis porttitor efficitur
</div>
</div>
Now if you make the second element width:100% it will have a smaller initial width
$('.box div').each(function() {
console.log($(this).width());
})
.box {
display: flex;
width: 50%;
border: 2px solid red;
margin: auto;
}
.box>div {
border: 1px solid green;
flex-shrink:0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="box">
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris nulla nisi, accumsan vel purus nec, pretium dictum ex. Suspendisse pellentesque velit eget turpis porttitor efficitur
</div>
<div style="width:100%">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris nulla nisi, accumsan vel purus nec, pretium dictum ex. Suspendisse pellentesque velit eget turpis porttitor efficitur
</div>
</div>
The first one is almost 3 times bigger than the second one thus they will not shrink the same way and at the end the second will remain smaller (it will be kept at almost 3 times smaller)
$('.box div').each(function() {
console.log($(this).width());
})
.box {
display: flex;
width: 50%;
border: 2px solid red;
margin: auto;
}
.box>div {
border: 1px solid green;
flex-shrink:1;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="box">
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris nulla nisi, accumsan vel purus nec, pretium dictum ex. Suspendisse pellentesque velit eget turpis porttitor efficitur
</div>
<div style="width:100%">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris nulla nisi, accumsan vel purus nec, pretium dictum ex. Suspendisse pellentesque velit eget turpis porttitor efficitur
</div>
</div>
Same logic apply to your code!
The same logic also apply when smaller content is used but in this case width:100% can make the initial width of the second item bigger so we end having a bigger element (like in the second snippet above)
Some related questions where you will get more details around the calculation and the flexbox algorithm:
How flexbox calculates flex-item's width if no flex-basis or width are set?
Why is a flex item limited to parent size?
The unpredictable wrapping habits of CSS
In case you want to increase the width of your element you can make the first element to shrink more:
body {
font-size: 1.3rem;
}
h1 {
margin-top: 0;
}
.container {
width: 80%;
max-width: 1100px;
margin: 0 auto;
}
.row {
display: flex;
}
.primary-content {
background-color: moccasin;
}
.sidebar {
padding: 1em;
text-align: center;
color: #fff;
background-color: #136c72;
}
<main class="main container row">
<section class="primary-content">
<h2>Quality designs made custom, on demand, just for you</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore
et dolore magna aliqua. Ut enim ad minim veniam.</p>
</section>
<aside class="sidebar">
<h2>Cheap</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.</p>
</aside>
</main>
<main class="main container row">
<section class="primary-content" style="flex-shrink:1.2;">
<h2>Quality designs made custom, on demand, just for you</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore
et dolore magna aliqua. Ut enim ad minim veniam.</p>
</section>
<aside class="sidebar">
<h2>Cheap</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.</p>
</aside>
</main>
You can also define flex-shrink for both and make sure it's bigger for the first element:
I will program a sticky sidebar inside a grid layout. I have made a screenshot
from my fist try to build this html page. I don't want use javascript. In the
css file I have used position: fixed. It should be positoin: sticky. How do I get
the sticky sidebar into the grid? If I klick on the link on the right side the the left side should move to the top.
Here the html page
.section-t {
margin-top: 10rem;
margin-bottom: 6rem;
min-height: calc(100vh - 30rem);
}
.section-t .container {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-gap: 1rem;
}
.sidebar {
position: fixed;
top: 10rem;
right: 3rem;
width: 450px;
}
.item12 {
grid-column: 1 / span 2;
}
.card {
background-color: var(--white-color);
border: solid 1px #757575;
border-radius: 0.4rem;
padding: 1em;
}
<section class="section-t">
<div class="container">
<div class="item12 card">
<h1>Handbook</h1>
<hr />
<h3>Introduction</h3>
<p>
Hello Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci
</p>
</div>
<div class="item12 card">
<h1>Help Pages</h1>
<hr />
<h3>General</h3>
<p>
Hello Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci
</p>
</div>
<div>
<div class="card sidebar">
<h1>Table of contents</h1>
<hr />
<div>
<fieldset>
<ul>
<li>
Introduction
</li>
<li>
How to create a strong password
</li>
</ul>
</fieldset>
</div>
</div>
</div>
</div>
</section>
My code has 3 divs in a row (gallery, sidebar, description). The HTML needs to remain unchanged, but I need to use CSS to get the .description up under the .sidebar (beside the .gallery) instead of beneath the .gallery.
I want to move that div like so
Code:
<div class="product">
<div class="gallery">
<img src="https://via.placeholder.com/300" alt="item" />
</div>
<div class="sidebar">
<h3>
Sidebar
</h3>
<p>
Product price, etc.
</p>
</div>
<div class="description">
<h3>
Details
</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer sed eros sem. Aliquam erat volutpat. Phasellus auctor lorem dolor, vitae egestas neque vestibulum sed. Proin sapien purus, faucibus ut elementum eget, consequat sed arcu. Morbi nisl libero,
molestie eget ligula quis, feugiat iaculis felis. Donec condimentum, felis eu sodales interdum, ex purus convallis augue, quis sollicitudin nibh ex vel lorem. Sed eget semper ipsum, vel dictum lorem. Proin ornare massa elit, non aliquam erat ultricies
at.
</p>
</div>
</div>
.product {
box-sizing: border-box;
position: static;
}
.gallery {
box-sizing: border-box;
float: left;
position: relative;
}
.sidebar {
box-sizing: border-box;
float: right;
position: static;
}
.description {
box-sizing: border-box;
clear: left;
float: left;
position: static;
}
If you're willing to use floats, set the width for your elements. Here's fiddle http://jsfiddle.net/y6g4p7u8/1/
I've set the background color for visual display.
.product {
box-sizing: border-box;
background: green;
}
.product:before,
.product:after {
content: " ";
display: table;
}
.product:after {
clear: both;
}
.gallery {
box-sizing: border-box;
width: 35%;
float: left;
background: red;
}
.sidebar {
box-sizing: border-box;
float: left;
width: 65%;
background: lightblue;
}
.description {
box-sizing: border-box;
float: left;
width: 65%;
background: yellow;
}
I suggest you to use a div to wrap both .sidebar and .description.
Then apply display: flex on parent .product.
HTML
<div class="column-wrap">
<div class="sidebar">..</div>
<div class="description">...</div>
</div>
CSS
.product{
display: flex
}
https://jsfiddle.net/blackcityhenry/n9qgvjh6/
css grid would be the easiest, and browser support is now pretty good.
https://css-tricks.com/snippets/css/complete-guide-grid/
https://caniuse.com/#search=grid
If I understand what you are asking correctly you could define your grid template area and then assign your elements to where they need to sit.
From the top of my head it would be something like this, check out the link to css-tricks.
Here is a pen demonstrating https://codepen.io/TomCheckley/pen/dQJQBv
<div class="product">
<div class="gallery">
<img src="https://lorempixel.com/400/200/cats/1" alt="">
</div>
<aside class="sidebar">
<h2>Sidebar</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</aside>
<div class="description">
<h2>Description</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>
</div>
</div>
img {
width: 100%;
height: auto;
}
h2 {
margin-top: 0;
}
p:last-child {
margin-bottom: 0;
}
.product {
max-width: 90%;
margin: auto;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: auto;
grid-gap: 1.5rem;
grid-template-areas: 'gallery gallery sidebar' 'gallery gallery description';
}
.product > * {
background-color: #c3cece;
padding: 1.5rem;
}
.gallery {
grid-area: gallery;
}
.sidebar {
grid-area: sidebar;
}
.description {
grid-area: description;
}
Well, actually grid maybe not the easiest if you've not used it! But it will give you the most flexible layout options without changing your markdown. It's definitely worth playing around with as browser support is getting near total (apart from IE). You can always progressively enhance as well - float is then overridden by flex and if you put grid after flex in the cascade the browser will use it if it understands it and use flex if it doesn't.
I'm so confused by why margin-top will not work. Here is my code:
HTML:
<div class="container-extended-blog">
<div class="offers-for-week">
<h1 class="title offers-for-this-week">offers for this week</h1>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
<img src="img/extended_blog_pic.jpg" alt="image of recipe">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
</div><!-- /.offers-for-week -->
</div><!-- /.container-extended-blog -->
SCSS:
.container-extended-blog {
margin-top: 200px;
margin-left: 300px;
background-color: $blue-ot;
width: 350px;
height: 450px;
overflow: hidden;
p {
font-family: $content-font;
color: $icon-font-color;
}
}
I have tried adding position: relative; which I find usually works whenever something like this happens, however I have no idea why this isn't working, and would really like to understand!
add position:absolute; to .container-extended-blog
.container-extended-blog {
top: 200px;
margin-left: 300px;
background-color: $blue-ot;
width: 350px;
height: 450px;
overflow: hidden;
position:absolute;
}
OR
Change top: 200px; to margin-top: 200px;
.container-extended-blog {
margin-top: 200px;
margin-left: 300px;
background-color: $blue-ot;
width: 350px;
height: 450px;
overflow: hidden;
}
see fiddle at : http://jsfiddle.net/Q5xdf/