max-width style applies differently, different values but same width - html

I am trying to apply a max-width to 2 different section and they seem to have the same width although the values are different. I have checked for padding but cannot see what would cause this.
I 've included the code below, as you can see .hero max-width is different from .container but still they're both 1280px in width.
Any help is appreciated, cheers!
<section class="section-hero">
<div class="hero">
<div class="hero-text-box">
<h1 class="heading-primary width-58rem">
A healthy meal delivered to your door, every single day
</h1>
<p class="hero-description">
The smart 365-days-per-year food subscription that will make you
eat healthy again. Tailored to your personal tastes and
nutritional needs.
</p>
<a href="#" class="btn btn--full margin-right-sm"
>Start eating well</a
>
Learn more ↓
<div class="delivered-meals">
<div class="delivered-imgs">
<img src="img/customers/customer-1.jpg" alt="customer photo" />
<img src="img/customers/customer-2.jpg" alt="customer photo" />
<img src="img/customers/customer-3.jpg" alt="customer photo" />
<img src="img/customers/customer-4.jpg" alt="customer photo" />
<img src="img/customers/customer-5.jpg" alt="customer photo" />
<img src="img/customers/customer-6.jpg" alt="customer photo" />
</div>
<p class="delivered-text">
<span>250,000+</span> meals delivered last year!
</p>
</div>
</div>
<div class="hero-image-box">
<img
src="img/hero.png"
alt="Woman enjoying food, meals in storage container and food bowls on a talbe"
/>
</div>
</div>
</section>
<section class="section-how">
<div class="container grid grid--2-cols">
<div>Test 1</div>
<div>Test 2</div>
<div>Test 3</div>
<div>Test 4</div>
</div>
</section>
.hero {
max-width: 150rem;
margin: 0 auto;
padding: 0 3.2rem;
display: grid;
align-items: center;
grid-template-columns: repeat(2, 1fr);
gap: 9.6rem;
}
.container {
max-width: 140rem;
margin: 0 auto;
padding: 0 3.2rem;
}

The reason why both elements reaches the same width, even though you defined different max-widths for your case, is because you are never actually reaching any of the max-width cases in order for the style to come into effect.
You mention that both elements have a width of 1280px. Note that your CSS definitions for max-width is using rem units. rem is usually calculated by a base of 16px (as default), meaning that 1280px is equal to 80 rem. You never reach the 140-150rem case. 140 rem equals to 2240px.

Related

I am having trouble aligning grid container with the width of the website

I am not sure why my CSS image grid is not aligning with the length of the webpage, even though I have made the length and width the same as the 1200px.
Note: When I open the inspect tool in google. It states that the width is 1184, however, when I change it to 1200px it doesn't fix the problem
My goal is to have this CSS grid to be 1200px * 500px. I really appreciate any help you can provide.
img {
width: 400px;
height: 250px;
}
.container-2 {
margin-top: 2em;
background-color: rgb(50, 100, 0);
display: grid;
grid-template-rows: 250px 250px;
grid-template-columns: repeat(3, 400px);
}
.photo_caption {
position: absolute;
}
<div class="container-2">
<div class="pic-1">
<img src="images/sailboat.jpg" alt="sailing" />
</div>
<div class="pic-2">
<img src="images/water.jpg" alt="oceanside" />
</div>
<div class="pic-3">
<img src="images/pool.jpg" alt="swimming pool" />
</div>
<div class="pic-4">
<img src="images/tree.jpg" alt="oceanview" />
</div>
<div class="pic-5">
<img src="images/side-wall.jpg" alt="campground" />
</div>
<div class="pic-6">
<p class="photo_caption">
We're dog-friendly... If your dog is friendly, too!</p>
<img src="images/dog.jpg" alt="dog friendly" />
</div>
</div>

HTML divs not properly displaying as a grid

I need to put these divs into a grid so that they display on the screen in a grid as opposed to a block. I have them displayed in a block and centered on the screen for smaller screen widths and after a certain screen width I would like them to display as a grid, but I keep getting the buttons and text displaying to the right of the images as opposed to displaying under the images. Here is my HTML and CSS code...
<section>
<div class="container-2">
<div class="wrapper-2">
<div class="boxes" data-aos="fade-up" data-aos-duration="800">
<img src="https://atlas-content-cdn.pixelsquid.com/stock-images/shirt-men-181dmv4-600.jpg" alt="Image cannot be displayed">
<h2>Men's slim fit blue plaid shirt</h2>
<p>$50.00</p>
<button class="arrivals-buttons">Add to cart</button>
</div>
<p class="border-bottom"></p>
<div class="boxes" data-aos="fade-up" data-aos-duration="800">
<img src="https://watchdreamer.com/sites/default/files/styles/soldat_md/public/2021-05/WBP201A.BA0632_.png?h=7afb1587&itok=EH_sMV2B" alt="Image cannot be displayed">
<h2>Men's silver and black time piece</h2>
<p>$499.99</p>
<button class="arrivals-buttons">Add to cart</button>
</div>
<p class="border-bottom" data-aos="fade-right" data-aos-duration="800"></p>
<div class="boxes" data-aos="fade-up" data-aos-duration="800">
<img src="https://www.pngall.com/wp-content/uploads/5/Brown-Men-Shoes-PNG-Image.png" alt="Image cannot be displayed">
<h2>Men's Uncle Tom dress shoes</h2>
<p>$44.99</p>
<button class="arrivals-buttons">Add to cart</button>
</div>
<p class="border-bottom" data-aos="fade-right" data-aos-duration="800"></p>
<div class="boxes" data-aos="fade-up" data-aos-duration="800">
<img src="https://i5.walmartimages.com/asr/b19cdda5-932f-4862-a7b3-b7440bfb759e_1.87f4ae5495ec75a86d5f6e4572e807d3.jpeg?odnHeight=612&odnWidth=612&odnBg=FFFFFF" alt="Image cannot be displayed">
<h2>Men's slim black slim fit dress pants</h2>
<p>$70.00</p>
<button class="arrivals-buttons">Add to cart</button>
</div>
<p class="border-bottom" data-aos="fade-right" data-aos-duration="800"></p>
<div class="boxes" data-aos="fade-up" data-aos-duration="800">
<img src="https://www.suitsexpert.com/wp-content/uploads/2019/01/silk-tie.png" alt="Image cannot be displayed">
<h2>Men's formal red tie</h2>
<p>$19.99</p>
<button class="arrivals-buttons">Add to cart</button>
</div>
</div>
</div>
</section>
<style>
.container-2 {
width: 90%;
display: block;
margin: 0 auto 0 auto;
}
.boxes {
display: grid;
justify-content: space-evenly;
grid-template-columns: 220px 220px 220px;
}
</style>
You need to change .boxes class. When grid-template-columns property is used, it will create columns that put your text and button to the side of your image.
.boxes {
display: grid;
width: 50%;
margin: 0 auto;
}
Also, you can add width and height to your image so that it does not go out of the grid width.
You don't put display:grid; at the boxes you want to be a part of the grid. But you put it in the container. This would be an example
.container-2 {
display:grid;
gap:1rem;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
grid-template-rows: 200px;
}
then you can remove the .wrapper-2 element

grid-template-columns CSS displaying vertically and not horizontally

I am a student working on a website. I have the below CSS/HTML script that should be displaying cards in order horizontally, however when I view it on a website its showing up vertically instead.
Goal:
[pic1] [pic2] [pic3]
[pic4] [pic5] [pic6]
Current Output:
[pic1]
[pic2]
[pic3]
[...]
[pic6]
Current Code:
I have only included code that should be relevant to my question, please let me know if I should include additional code for guidance.
.cards {
margin: 0 auto;
max-width: 1000px;
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-auto-rows: auto;
gap: 20px;
font-family: Arial;
padding-top: 30px;
}
<div class="cards">
<div class="card">
<img src="image.jpg" alt="image" class="card__image">
<div class="card__content">
<p2>Image</p2>
</div>
<div class="card__info">
<div>
BOUNTY
</div>
</div>
</div>
</div>
<div class="cards">
<div class="card">
<img src="image2.jpg" alt="image" class="card__image">
<div class="card__content">
<p2>Image2</p2>
</div>
<div class="card__info">
<div>
BOUNTY
</div>
</div>
</div>
</div>
I would really do that with display: flex ... why? because it is easier and not that complex to work with grid and give your flex-children a flex-basis of 30% to have three children in one row.
Nevertheless, you have div class="cards" openend twice. you will probably have this div only once and div class="card__*" several times.
grid is more compatible with older versions of browsers, like IE11, but also only with the prefix, but that's just my personal thought.

CSS Grid (grid-template-columns) fix for Safari?

Recently I picked up webdesign again, creating a website for a free festival we're organising. Now I'm pretty exited about CSS Grid and everything seemed to be working out until someone told me the website looks quite stupid in Safari..
The lower part of the grid system is displayed as it is supposed to be.. on mobile. But the sponsor logo's below the header just appear to be a vertical list.
Now I could fix those logos in a different way with float probably, for the lower part I have no idea how to make it look the same, but I'd rather just find a workaround for Safari.
I expect it has something to do with grid-template-columns, tried some stuff (change from auto to fr and adding align/justify-self), but can't seem to figure it out myself. Could anyone here help me out?
HTML:
<div class="sponsors">
<div class="sponsorlogo">
<img src="img/Logo_Recupel.png" alt="Logo Recupel" />
</div>
<div class="sponsorlogo">
<img src="img/Logo_StadBrugge.png" alt="Logo Stad Brugge" />
</div>
<div class="sponsorlogo">
<img src="img/Logo_transform3.png" alt="Logo transform3" />
</div>
<div class="sponsorlogo">
<img src="img/Logo_ecoFoundation.png" alt="Logo eco Foundation" />
</div>
<div class="sponsorlogo">
<img src="img/Logo_AandePlas.png" alt="Logo Domein Aan de Plas" />
</div>
<div class="sponsorlogo">
<img src="img/Logo_LegendsFreeWalkingTours.png" alt="Logo Legends Free Walking Tours" />
</div>
<div class="sponsorlogo">
<img src="img/Logo_MoederAarde.png" alt="Logo Moeder Aarde" />
</div>
CSS:
.sponsors{
display: grid;
grid-template-columns: repeat(7, auto);
}
.sponsorlogo img{
object-fit: scale-down;
height: 100%;
max-width: 100%;
}
Live at http://pachafest.be
Thanks in advance!
Safari does not yet support intrinsic and extrinsic sizing with grid properties such as grid-template-rows (Source: Can I Use). You could use #supports
#supports (display: grid) {
.sponsors {
display: grid;
grid-template-columns: repeat(7, auto);
}
}
#supports not (display: grid) {
// Safari/IE style
}

How do you use CSS column / grid to setup a text and image collage layout?

I am using older Skeleton css version, it is a 16 column grid system. I am trying to setup similar layout as in this picture.
http://imgur.com/sIV2aYo
I am pretty new to CSS, is using two containers (one inside another) a proper method?
Here is a sample code of what I been trying, but not working out too well =(
<div class="container">
<div class="eight columns alpha">
<div class="image">
<img alt="" src="images/coffee.jpg">
</div>
</div>
<div class="eight columns omega">
<div class="container">
<div class="eight columns">
<img alt="" src="images/plate.jpg">
</div>
<div class="eight columns">
<img alt="" src="images/macaro.jpg">
</div>
<div class="text area">
<p class="quote">"One of my favorite parts of using Square Register is being able to talk to customers while I am swiping their cards."</p>
<p class="name">Norm Mui, Coffee Foundry</p>
</div>
</div> <!-- 2nd container -->
</div>
</div> <!-- 1st container -->
Thanks in advance.
I don't know your CSS, but maybe this helps you:
HTML:
// The class "columns" is your "block" (div) that needs the content. I've made a CSS with a background-color, height and width.
// In that div "columns we create new "columns, numbered by 1,2 and 3. I've floated all the text to the left and gived it a margin. The first, second and the third a margin of 15px ( top, right, buttom and left ).
// In the div column "columns" I have made a textarea with also a margin of 15px. The vertical-align is for a top vertical align. with the display we means that it needs to be in the block, with a margin of 40% ( it takes 40% of the block).
<div id="container">
<div class="columns">
<div class="eight-columns-1">
<img alt="" src="http://ww1.prweb.com/prfiles/2014/04/10/11752526/gI_134971_best-image-web-hosting.png">
</div>
<div class="eight-columns-2">
<img alt="" src="http://www.causingeffect.com/images/made/images/example/cow_100_100_c1.jpg">
</div>
<div class="eight-columns-3">
<img alt="" src="http://www.causingeffect.com/images/made/images/example/cow_100_100_c1.jpg">
</div>
<div class="textarea">
<p class="quote">"One of my favorite parts of using Square Register is being able to talk to customers while I am swiping their cards."</p>
<p class="name">Norm Mui, Coffee Foundry</p>
</div>
</div>
</div>
CSS:
.columns {background-color:yellow; width: 530px; height: 285px;}
.eight-columns-1 {float:left; margin: 15px;}
.eight-columns-2 {float: left; margin: 15px;}
.eight-columns-3 {float:left; margin: 15px 15px 15px 0px;}
.textarea {vertical-align:top; margin: 15px; display:inline-block; width: 40%;}