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

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
}

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>

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

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.

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.

Expand dynamic grid columns upto row max width?

Greet1ngs, everyone. I'm trying to implement a header on grid which dynamically moves columns to the next row on smaller screens. I use the following string to build it:
grid-template-columns: repeat(auto-fit, minmax(max-content, 230px));
It kinda works but on some resolutions columns do not expand to the full width to the right and thus another background (from [body]) becomes visible from underneath. How can I make all columns even to the right end of the screen without mediaquery or calc (will try those if no other way)? Sorry for unprofessional explanation, I'm still new to coding. Screenshot
#charset "utf-8";
.headergrid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(max-content, 230px));
margin-top: -8px;
margin-left: -8px;
margin-right: -8px;}
.headergrid > div {
background-color: #191D1F;}
<body style="background-color:#1ba6fc;">
<div class="headergrid">
<div class="location">
<img src="clipart-map-location-11.png" alt="location" width="20" height="20" class="locicon"><span style="color:#E2E4C9">Москва, ул Хабаровская, 2. Cр-Вс с 12 до 18.</span>  
</div>
<div class="element">
<img src="phngrn.png" width="25" height="25" alt="phone" class="phonicon">+7(977)8844-922  
</div>
<div class="element">
<img src="hiclipart.com (11).png" width="30" height="20" alt="mail" class="mailicon"/>mail#zvteh.ru    
</div>
<div class="element">
</div>
<div class="social">
<img src="hiclipart.com.png" width="40" height="30" alt="whatsapp" class="whappicon">  
<img src="hiclipart.com (12).png" width="30" height="30" alt="VK.com" class="vkicon">  
<img src="hiclipart.com (14).png" width="27" height="27" alt="Telegram" class="telecon"></div>
</div>
The solution is to put this grid into parent div box with header's background color. It will override main background there and all rows appear having 100% width at all resolutions.

Centering in IE11 with CSS Grid

I am currently attempting to center (both vertically and horizontally) elements via a CSS grid. After some research, it seems IE11 supports css grid via different syntax than more up to date browsers (edge, safari, chrome, etc). I am using the display:-ms-grid syntax and this is putting my elements in the top left of the screen instead of centering them as I'd like. Note the posted example does work as expected with other browsers.
<div style="height:100%;display:grid;display:-ms-grid;">
<div style="margin:auto" align="center">
<img id="logo" alt="Logo" style="width:250px;margin-top:-5%" src="data:image/svg+xml;base64,xxxxxxxxxxxxx">
<div style="margin-top:2%;" class="loader"></div>
</div>
</div>
How can I overcome the centering issue for IE11?
Update: I've been able to center it vertically but not horizontally so far. This is where I'm currently at:
<div style="height:100%;display:grid;display:-ms-grid;-ms-grid-columns:2fr 2fr 2fr;">
<div style="margin:auto;-ms-grid-column:2;" align="center">
<img id="logo" alt="Logo" style="width:250px;margin-top:-5%" src="data:image/svg+xml;base64,xxxxxxxxxxxxx">
<div style="margin-top:2%;" class="loader"></div>
</div>
</div>
Looks like I found a working solution to support this in IE 10/11. Basically to define 3 columns and 3 rows for the -ms-grid by using -ms-grid-columns and -ms-grid-rows and then specify that my content I want centered should be in column 2 and row 2 (the middle) by using -ms-grid-column and -ms-grid-row. Solution as follows:
<div style="height:100%;display:grid;display:-ms-grid;-ms-grid-columns:2fr 2fr 2fr;-ms-grid-rows: 2fr 2fr 2fr;">
<div style="margin:auto;-ms-grid-column:2;-ms-grid-row:2;" align="center">
<img id="logo" alt="Logo" style="width:250px;margin-top:-5%" src="data:image/svg+xml;base64,xxxxxxxxxxxxx">
<div style="margin-top:2%;" class="loader"></div>
</div>
</div>
CSS
.grid-container {
height: 100%;
display: -ms-grid;
display: grid;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-ms-flex-line-pack: center;
align-content: center
}
HTML
<div class="grid-container">
<img id="logo" alt="Logo" width="250px" src="data:image/svg+xml;base64,xxxxxxxxxxxxx" />
</div>