How can I make child of grid take 100% height in Safari? - css

Help me adjust my code so that it will be working in Safari. Initially I used answer from here with a few adjustments. I needed my card to be responsive and has some additional elements at the bottom.
Here's my code:
.gallery {
display: grid;
gap: 15px;
grid-template-columns: repeat(2, 1fr);
}
.card {
background-color: #fff;
border-radius: 4px;
box-shadow: 0 0 4px rgba(0, 0, 0, 0.14);
max-width: 200px;
padding: 10px 10px 20px;
cursor: pointer;
position: relative;
}
.wrapper {
width: 100%;
position: relative;
margin-bottom: 20px;
}
.wrapper::before {
content: '';
padding-bottom: 100%;
display: block;
}
.img-grid {
display: grid;
border-radius: 4px;
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 1fr;
gap: 3px;
overflow: hidden;
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
right: 0;
bottom: 0;
}
.img-grid > div {
position: relative;
width: 100%;
height: 100%;
}
.img-grid > div:first-child {
grid-column: 1 / span 2;
}
img {
position: absolute;
width: 100%;
height: 100%;
object-fit: cover;
}
.logo {
width: 50px;
height: 50px;
background: gainsboro;
float: left;
margin-right: 15px;
}
h4,p {
margin: 3px 0;
}
p {
font-size: 13px;
}
<div class="gallery">
<div class="card">
<div class="wrapper">
<div class="img-grid">
<div>
<img loading="lazy" src="https://cdn.pixabay.com/photo/2015/04/19/08/32/marguerite-729510_960_720.jpg"></img>
</div>
<div>
<img loading="lazy" src="https://cdn.pixabay.com/photo/2015/04/19/08/32/marguerite-729510_960_720.jpg"></img>
</div>
<div>
<img loading="lazy" src="https://cdn.pixabay.com/photo/2015/04/19/08/32/marguerite-729510_960_720.jpg"></img>
</div>
</div>
</div>
<div class="logo"></div>
<h4>Logo name</h4>
<p>Some description</p>
</div>
<div class="card">
<div class="wrapper">
<div class="img-grid">
<div>
<img loading="lazy" src="https://cdn.pixabay.com/photo/2015/04/19/08/32/marguerite-729510_960_720.jpg"></img>
</div>
<div>
<img loading="lazy" src="https://cdn.pixabay.com/photo/2015/04/19/08/32/marguerite-729510_960_720.jpg"></img>
</div>
<div>
<img loading="lazy" src="https://cdn.pixabay.com/photo/2015/04/19/08/32/marguerite-729510_960_720.jpg"></img>
</div>
</div>
</div>
<div class="logo"></div>
<h4>Logo name</h4>
<p>Some description</p>
</div>
</div>
It works fine in Chrome, but it doesn't work in Safari(current and older). It's because I needed my cards to be responsive and always maintain square grid. So I used same trick on the wrapper that's widely used to maintain responsive squares. But as a result of that height: 100% is no longer working in Safari. Is there any way to make it work? I would appreciate some your help.

Related

I want to eliminate the blank area under the container in bootstrap

I want to expand the box_switch (red frame part) part of the image below to Top
and apply background color.
React.js
<div className="container">
<div className="row mx-auto text-center">
<>
<div className="col-12">
<div className="box_switch">
<img className="" src={plugon_pic} />
<p className="under_ic_switch_state">{item.state}</p>
</div>
</div>
</>
</div>
</div>
App.css
.box_switch {
position: relative;
background:#1E3E75;
padding:15px;
border-radius: 10px;
margin-bottom: 30px;
margin: 0 calc(50% - 50vw) 15px;
width: 100vw;
}
.box_switch {
position: relative;
background: #1E3E75;
padding: 15px;
border-radius: 10px;
margin-bottom: 30px;
margin: 0 calc(50% - 50vw) 15px;
width: 100vw;
}
<div class="container">
<div class="row mx-auto text-center">
<div class="col-12">
<div class="box_switch">
<img class="" src="https://via.placeholder.com/100" />
<p class="under_ic_switch_state">{item.state}</p>
</div>
</div>
</div>
</div>
then i think this will do
body {
margin: 0;
padding: 0;
}
.box_switch {
position: absolute;
left: 0;
top: 0;
background:#1E3E75;
padding:15px;
border-radius: 10px;
margin-bottom: 30px;
margin: 0 calc(50% - 50vw) 15px;
width: 100%;
}
.container {
position: relative;
}
This works
.container {
margin-top: 0 !important;
}

Padding at bottom of modal messes up fixed header when scrolled to the bottom

I would like my modal to have a padding on the bottom of it, so that when you reach the bottom of the content when scrolling it looks like this:
instead of this:
The problem I'm having, and you can see it in these two pictures, is that when I try to implement this on my modal (by adding padding to the bottom of the modal), it basically scrolls past the sticky header I have.
Heres a picture of the modal before scrolling:
This is the gist of what code I have so far. I can't get it to look exactly right on here, but essentially if I add padding-bottom:5rem to .modal-content I get the first picture
.modal-background {
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
background-color: rgba(10, 10, 10, .86);
}
.modal-content, .modal-card {
margin: 0 auto;
overflow: auto;
position: relative;
margin-top: 5rem;
width: 60rem;
max-width: 100%;
max-height: calc(100% - 5rem);
}
.modal {
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
align-items: center;
display: block;
justify-content: center;
overflow: hidden;
position: fixed;
z-index: 20;
flex-direction: column;
}
.box{
background-color: white;
border-radius: 5px;
box-shadow: 0 2px 3px rgba(10, 10, 10, 0.1), 0 0 0 1px rgba(10, 10, 10, 0.1);
color: #4a4a4a;
display: block;
padding: 1.25rem;
}
<div class="modal">
<div class='modal-background' onclick="clearHash()"></div>
<div class="modal-content" style="margin-top:5rem;width: 60rem;max-width:100%;max-height:calc(100% - 5rem);">
<div class="box complete-article-content" id="modalContent" style="padding-bottom: .75rem;">
<div>
<h1 class="title is-4 header" >Modal Title</h1>
<h1 class="title is-5 header" >Modal Subtitle</h1>
<hr style="margin-bottom: 0rem;"/>
</div>
<div style="max-height: calc(100vh - 210px);overflow-y: auto;">
<div id="modalContents" style="margin-top: 1rem;">
<div style="padding-bottom:20rem">
<h1>Beginning of Modal Content</h1>
</div>
<div style="padding-bottom:20rem;padding-top:20rem">
<h1>Middle of Modal Content</h1>
</div>
<div style="padding-top:20rem">
<h1>Bottom of Modal Content</h1>
</div>
</div>
</div>
</div>
</div>
If you don't mind about the usage of flexbox, it could help you a lot to solve your issue without a lot of work:
<div class="modal">
<div class='modal-background' onclick="clearHash()"></div>
<div class="modal-content" style="margin-top:5rem;width: 60rem;max-width:100%;max-height:calc(100% - 5rem);">
<div class="box complete-article-content" id="modalContent" style="padding-bottom: .75rem;">
<div>
<h1 class="title is-4 header" >Modal Title</h1>
<h1 class="title is-5 header" >Modal Subtitle</h1>
<hr style="margin-bottom: 0rem;"/>
</div>
<div style="flex: 1; overflow-y: auto;">
<div id="modalContents" style="margin-top: 1rem;">
<div style="padding-bottom:20rem">
<h1>Beginning of Modal Content</h1>
</div>
<div style="padding-bottom:20rem;padding-top:20rem">
<h1>Middle of Modal Content</h1>
</div>
<div style="padding-top:20rem">
<h1>Bottom of Modal Content</h1>
</div>
</div>
</div>
</div>
</div>
And the CSS:
.modal-background {
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
background-color: rgba(10, 10, 10, .86);
}
.modal-content, .modal-card {
margin: 0 auto;
overflow: auto;
position: relative;
margin-top: 5rem;
width: 60rem;
max-width: 100%;
max-height: calc(100% - 5rem);
display: flex;
}
.modal {
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
align-items: center;
display: block;
justify-content: center;
overflow: hidden;
position: fixed;
z-index: 20;
flex-direction: column;
}
.box{
flex: 1;
box-sizing: border-box;
background-color: white;
border-radius: 5px;
box-shadow: 0 2px 3px rgba(10, 10, 10, 0.1), 0 0 0 1px rgba(10, 10, 10, 0.1);
color: #4a4a4a;
display: flex;
flex-direction: column;
padding: 1.25rem;
overflow: hidden;
}
To summarise: your problem is the sizing of the boxes which makes the inner box slightly bigger than you expect. That in combination with the overflow: auto; in the CSS class .modal-content causes your result.

Adding a CSS Pseudo Elements to center of a grid only

.parnet{
max-width: 600px;
margin: 0 auto;
background: #f4f4f5;
}
.wrapper {
display: grid;
grid-template-columns: repeat(3, 1fr);
}
.cell {
position: relative;
}
.inner {
width: 80px;
height: 80px;
padding: 40px;
text-align: left;
}
.wrapper .cell:nth-child(2n):before{
content: "";
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
height: 60%;
width: 1px;
background-color:red;
}
<div class="parnet">
<div class="wrapper">
<div class="cell">
<div class="inner">1</div>
</div>
<div class="cell">
<div class="inner">2</div>
</div>
<div class="cell">
<div class="inner">3</div>
</div>
<div class="cell">
<div class="inner">4</div>
</div>
<div class="cell">
<div class="inner">5</div>
</div>
<div class="cell">
<div class="inner">6</div>
</div>
</div>
</div>
I have a grid that I'm trying to add a :before Pseudo Element to create a divider line between each grid cell. I only want the divider lines to show in the center cells and not the outside left and right.
I'm able to achieve this using border-right and then using nth-child(3n) to remove borders. But having trouble trying to do the same using a Pseudo Element
.parent {
background: white;
max-width: 600px;
margin: 0 auto;
.wrapper {
display: grid;
grid-template-columns: repeat(3, 1fr);
.cell {
position: relative;
&:before {
content: "";
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
height: 60%;
width: 1px;
background-color:red;
}
&:nth-child(3n):before {
width: 0;
}
.inner {
max-width: 320px;
width: 320px;
height: 200px;
padding: 57px 43px 40px;
text-align: left;
}
}
}
}
.parnet{
max-width: 600px;
margin: 0 auto;
background: #f4f4f5;
}
.wrapper {
display: grid;
grid-template-columns: repeat(3, 1fr);
}
.cell {
position: relative;
}
.inner {
width: 80px;
height: 80px;
padding: 40px;
text-align: left;
}
.wrapper .cell:before{
content: "";
position: absolute;
right: 0;
top: 50%;
transform: translateY(-50%);
height: 60%;
width: 1px;
background-color:red;
}
.wrapper .cell:nth-child(3n):before {
width: 0;
}
<div class="parnet">
<div class="wrapper">
<div class="cell">
<div class="inner">1</div>
</div>
<div class="cell">
<div class="inner">2</div>
</div>
<div class="cell">
<div class="inner">3</div>
</div>
<div class="cell">
<div class="inner">4</div>
</div>
<div class="cell">
<div class="inner">5</div>
</div>
<div class="cell">
<div class="inner">6</div>
</div>
</div>
</div>
So the clue was to set right: 0; on the cell instead of left:0;
Then uses
.wrapper .cell:nth-child(3n):before {
width: 0;
}
Thanks Keith i'm going to score your answer for giving me that great clue.
This is my answer. I'm using the .cell:nth-child(3n):before for the horizontal lines. I hope this is what you need.
.parent {
background: white;
max-width: 600px;
margin: 0 auto;
font-size:2em;
}
.parent .wrapper {
display: grid;
grid-template-columns: repeat(3, 1fr);
}
.parent .wrapper .cell {
position: relative;
}
.parent .wrapper .cell:before {
content: "";
position: absolute;
right: 50%;
top:.2em;
height: 60%;
width: 1px;
background-color: red;
}
.parent .wrapper .cell:nth-child(3n):before {
width: 300%;
height:1px;
top:100%
}
<div class="parent">
<div class="wrapper">
<div class="cell">1</div>
<div class="cell">2</div>
<div class="cell">3</div>
<div class="cell">4</div>
<div class="cell">5</div>
<div class="cell">6</div>
<div class="cell">7</div>
<div class="cell">8</div>
<div class="cell">9</div>
</div>
</div>

How to scroll content blocks left and right in css

I am building a scrolling frame on a web page.
The frame is width: 90% of the page-width.
I have a total of 7 blocks but I only want to show 5 at a time with a left & right button for scrolling left and right. Each block is width: 18%
What are the minimum css styles I should consider to get starting building this?
What are the minimum css styles I should consider to get starting
building this?
Is this what are you trying to achieve?
* {
margin: 0;
padding: 0;
}
html, body {
width: 100%;
height: 100%;
}
body {
text-align: center;
}
.wrapper {
display: inline-block;
width: 90vw;
height: 100px;
background-color: lightgray;
padding: 16px 0;
overflow-x: scroll;
text-align: start;
}
.content {
display: inline-block;
height: 100%;
width: calc(90vw / 5);
text-align: start;
float: left;
}
.content-wrapper {
height: 100%;
width: calc((90vw / 5) * 7);
text-align: start;
}
.buttons-wrapper {
position: absolute;
width: 90vw;
height: calc(100px - 16px);
}
.left-button,
.right-button {
position: absolute;
background-color: black;
width: 30px;
height: 30px;
top: calc(50% - 15px);
color: white;
text-align: center;
}
.left-button {
left: 0;
}
.right-button {
right: 0;
}
<div class="wrapper">
<div class="buttons-wrapper">
<div class="left-button">L</div>
<div class="right-button">R</div>
</div>
<div class="content-wrapper">
<div class="content" style="background-color: red"></div>
<div class="content" style="background-color: orange"></div>
<div class="content" style="background-color: yellow"></div>
<div class="content" style="background-color: green"></div>
<div class="content" style="background-color: lightblue"></div>
<div class="content" style="background-color: blue"></div>
<div class="content" style="background-color: violet"></div>
</div>
</div>

Safari isn't stretching image to flexbox grid

I'm trying to build a simple teaser grid for featured posts on a website using flexbox. It should look like this:
And in FF and Chrome it's all good. If i change the resolution of one image, all the others follow and update their size. But not in Safari. Whatever i do, it never fits to an equal height:
I really don't get the point why this is happening. Each image container on the right has exactly 50% of the height calculated by flexbox. And each image should be stretched to that height.
I could probably achieve this with background-size:cover but i would love to find a solution to use img tags instead.
Here's a demo: https://jsfiddle.net/7tjw8j83/1/
.featured-grid{
margin: 0;
padding: 0;
display: flex;
flex-wrap: wrap;
}
img{
width: 100%;
height: 100%;
display: block;
object-fit:cover;
}
.left{
width: 66.6666%;
}
.right{
width: 33.3333%;
display: flex;
flex-direction: column;
}
.right-top{
background: green;
flex: 1;
}
.right-bottom{
background: red;
flex: 1;
}
<div class="featured-grid">
<div class="left">
<img src="https://unsplash.it/600/450?image=1055">
</div>
<div class="right">
<div class="right-top">
<img src="https://unsplash.it/600/400?image=1051">
</div>
<div class="right-bottom">
<img src="https://unsplash.it/600/400?image=1057">
</div>
</div>
</div>
In addition to Michaels suggestion, you could do like this, where I used background-image instead of img (since you use a given height anyway), and how to add text at an absolute position
html, body {
margin: 0;
}
.featured-grid{
display: flex;
height: 100vh;
}
div {
position: relative;
background-position: center;
background-repeat: no-reapat;
background-size: cover;
overflow: hidden;
}
.left {
width: 66.666%;
}
.right{
width: 33.333%;
display: flex;
flex-direction: column;
}
.right-top{
flex: 1;
}
.right-bottom{
flex: 1;
}
.text {
position: absolute;
left: 10px;
bottom: 10px;
color: white;
}
.text > * {
margin: 5px;
}
<div class="featured-grid">
<div class="left" style="background-image: url(https://unsplash.it/600/450?image=1055)">
<div class="text">
<h2>Title</h2>
<h3>Text</h3>
</div>
</div>
<div class="right">
<div class="right-top" style="background-image: url(https://unsplash.it/600/400?image=1051)">
<div class="text">
<h2>Title</h2>
<h3>Text</h3>
</div>
</div>
<div class="right-bottom" style="background-image: url(https://unsplash.it/600/400?image=1057)">
<div class="text">
<h2>Title</h2>
<h3>Text</h3>
</div>
</div>
</div>
</div>
Updated based on a comment
html, body {
margin: 0;
}
.featured-grid{
display: flex;
height: 100vh;
}
div {
position: relative;
overflow: hidden;
}
img{
width: 100%;
height: 100%;
display: block;
object-fit:cover;
}
.left {
width: 66.666%;
}
.right{
width: 33.333%;
display: flex;
flex-direction: column;
}
.right-top{
flex: 1;
}
.right-bottom{
flex: 1;
}
.text {
position: absolute;
left: 10px;
bottom: 10px;
color: white;
}
.text > * {
margin: 5px;
}
<div class="featured-grid">
<div class="left">
<img src="https://unsplash.it/600/450?image=1055">
<div class="text">
<h2>Title</h2>
<h3>Text</h3>
</div>
</div>
<div class="right">
<div class="right-top">
<img src="https://unsplash.it/600/400?image=1051">
<div class="text">
<h2>Title</h2>
<h3>Text</h3>
</div>
</div>
<div class="right-bottom">
<img src="https://unsplash.it/600/400?image=1057"> <div class="text">
<h2>Title</h2>
<h3>Text</h3>
</div>
</div>
</div>
</div>
Updated (2:nd) based on a comment
html,
body {
margin: 0;
}
.featured-grid {
display: flex;
}
div {
position: relative;
overflow: hidden;
}
img {
visibility: hidden;
display: block;
}
img.show {
position: absolute;
visibility: visible;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: block;
object-fit: cover;
}
.left img {
max-height: 100vh;
}
.right img {
max-height: 50vh;
}
.left {
width: 66.666%;
}
.right {
width: 33.333%;
display: flex;
flex-direction: column;
}
.right-top {
flex: 1;
}
.right-bottom {
flex: 1;
}
.text {
position: absolute;
left: 10px;
bottom: 10px;
color: white;
}
.text > * {
margin: 5px;
}
<div class="featured-grid">
<div class="left">
<img src="https://unsplash.it/300/250?image=1055">
<img class="show" src="https://unsplash.it/300/250?image=1055">
<div class="text">
<h2>Title 1</h2>
<h3>Text 1</h3>
</div>
</div>
<div class="right">
<div class="right-top">
<img src="https://unsplash.it/300/200?image=1057">
<img class="show" src="https://unsplash.it/300/200?image=1057">
<div class="text">
<h2>Title 2</h2>
<h3>Text 2</h3>
</div>
</div>
<div class="right-bottom">
<img src="https://unsplash.it/300/200?image=1057">
<img class="show" src="https://unsplash.it/300/200?image=1057">
<div class="text">
<h2>Title 3</h2>
<h3>Text 3</h3>
</div>
</div>
</div>
</div>

Resources