I have created a masonry style grid in HTML/CSS. To do this I have used the
display:grid properties with 'grid-row' and 'grid-column.'
See attached pen.
This works great in Chrome, Firefox and Edge, not tried on Safari yet, but unfortunately, there are issues when it renders in the IE 11 browser.
Instead of getting a nice grid layout as shown in the attached pen it just displays 4 1x1 columns on top of one another.
Are there any IE specific properties that I can assign to my CSS classes in order to get this to display correctly across all browsers?
#container {
display:inline-block;
overflow: hidden; /* clip the excess when child gets bigger than parent */
}
#container img {
display: block;
transition: transform .4s; /* smoother zoom */
}
#container:hover img {
transform: scale(1.3);
transform-origin: 50% 50%;
}
.wrapper {
display: grid;
grid-gap: 0px;
grid-template-columns: 33% 33% 33%;
grid-template-rows: 400px 400px;
color: #000;
}
.a {
grid-column: 1;
grid-row: 1/3;
text-align:center;
color:#fff;
display:block;
position:relative;
overflow:hidden;
}
.b {
grid-column: 2 / span 2;
grid-row: 1;
color:#fff;
position:relative;
overflow:hidden;
}
.c {
grid-column: 2;
grid-row: 2;
color:#fff;
position:relative;
overflow:hidden;
}
.d {
grid-column: 3;
grid-row: 2;
color:#fff;
position:relative;
overflow:hidden;
}
.box {
border-radius: 0px;
padding: 10px;
font-size: 150%;
display:block;
position:relative;
}
.ctr {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%)
}
.imex-btn {
background-color: #4080fa;
border: none;
color: white;
padding: 10px 30px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin-top: 70px;
cursor: pointer;
font-family: "Century Gothic";
}
.imex-btn:hover {
background-color: #000;
color: #4080fa;
}
<div class="wrapper">
<div class="box a">
<div id="container">
<img id="image" src="https://via.placeholder.com/500x900
C/O https://placeholder.com/">
<div class="ctr"><h2 class="white">BOX A<h2>
</div>
VIEW NOW
</div>
</div>
<div class="box b">
<div id="container">
<img id="image" src="https://via.placeholder.com/1200x900/C/O https://placeholder.com/">
<div class="ctr"><h2 class="white">BOX B</h2>
</div>
VIEW NOW
</div>
</div>
<div class="box c">
<div id="container">
<img id="image" src="https://via.placeholder.com/500x500
C/O https://placeholder.com/">
<div class="ctr"><h2 class="white" style="text-align:center">BOX C</h2>
</div>
READ MORE
</div>
</div>
<div class="box d">
<div id="container">
<img id="image" src="https://via.placeholder.com/500x500
C/O https://placeholder.com/">
<div class="ctr"><h2 class="white" style="text-align:center">BOX D</h2>
</div>
READ MORE
</div>
</div>
</div>
Try to change the CSS from
grid-template-columns: 33% 33% 33%;
To
grid-template-columns: 1fr 1fr 1fr;
Some elements are not properly rendered on IE11 due to their implementation of the standards.
Try adding a -ms- prefix to elements such as display: grid, grid-column and grid-row.
You will probably face the same kind of problems when testing on older versions of Safari (in which case try the -webkit prefix).
I've added some css to make it work in IE. Pay attention to the -ms- prefix added in css. You can also refer to this article which explains how to support css grid in IE.
#container {
display: inline-block;
overflow: hidden; /* clip the excess when child gets bigger than parent */
}
#container img {
display: block;
transition: transform .4s; /* smoother zoom */
}
#container:hover img {
transform: scale(1.3);
transform-origin: 50% 50%;
}
.wrapper {
display: -ms-grid;
display: grid;
grid-gap: 0px;
grid-template-columns: 33% 33% 33%;
-ms-grid-columns: 33% 33% 33%;
grid-template-rows: 400px 400px;
-ms-grid-rows: 400px 400px;
color: #000;
}
.a {
grid-column: 1;
grid-row: 1/3;
-ms-grid-column: 1;
-ms-grid-row-span: 2;
text-align: center;
color: #fff;
display: block;
position: relative;
overflow: hidden;
}
.b {
grid-column: 2 / span 2;
grid-row: 1;
-ms-grid-row:1;
-ms-grid-column-span: 2;
-ms-grid-column:2;
color: #fff;
position: relative;
overflow: hidden;
}
.c {
grid-column: 2;
grid-row: 2;
-ms-grid-column:2;
-ms-grid-row:2;
color: #fff;
position: relative;
overflow: hidden;
}
.d {
grid-column: 3;
grid-row: 2;
-ms-grid-column:3;
-ms-grid-row:2;
color: #fff;
position: relative;
overflow: hidden;
}
.box {
border-radius: 0px;
padding: 10px;
font-size: 150%;
display: block;
position: relative;
}
.ctr {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%)
}
.imex-btn {
background-color: #4080fa;
border: none;
color: white;
padding: 10px 30px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin-top: 70px;
cursor: pointer;
font-family: "Century Gothic";
}
.imex-btn:hover {
background-color: #000;
color: #4080fa;
}
<div class="wrapper">
<div class="box a">
<div id="container">
<img id="image" src="https://via.placeholder.com/500x900
C/O https://placeholder.com/">
<div class="ctr">
<h2 class="white">BOX A</h2>
</div>
VIEW NOW
</div>
</div>
<div class="box b">
<div id="container">
<img id="image" src="https://via.placeholder.com/1200x900/C/O https://placeholder.com/">
<div class="ctr">
<h2 class="white">BOX B</h2>
</div>
VIEW NOW
</div>
</div>
<div class="box c">
<div id="container">
<img id="image" src="https://via.placeholder.com/500x500
C/O https://placeholder.com/">
<div class="ctr">
<h2 class="white" style="text-align:center">BOX C</h2>
</div>
READ MORE
</div>
</div>
<div class="box d">
<div id="container">
<img id="image" src="https://via.placeholder.com/500x500
C/O https://placeholder.com/">
<div class="ctr">
<h2 class="white" style="text-align:center">BOX D</h2>
</div>
READ MORE
</div>
</div>
</div>
Related
So this is a simple line of images, with hover effects, I have it doing everything I need, except when I add a link to open up a new page
so do i need to remake everything and use a different approach or is there a way to somehow fix the issue? Thanks :)
UPDATE!
The code might not be perfect, but I added
.box-1 a {
display:contents:
}
and that solved everything !
.container-1 {
display: inline-flex;
}
.box-1 {
-webkit-box-flex: 1;
-moz-box-flex: 1;
box-flex: 1;
-webkit-flex: 1 1 auto;
flex: 1 1 auto;
padding: 30px;
text-align: center;
display: inline-block;
position: relative;
}
.box-1:hover img {
filter: blur(3px) brightness(85%);
}
.box-1 img {
width: 100%;
height: 100%;
transition: 0.1s;
}
.box-1 :not(img) {
position: absolute;
top: 30%;
z-index: 1;
color: #fff;
text-align: center;
width: 90%;
opacity: 0;
transition: 0.1s;
letter-spacing: 2px;
}
.box-1 h2 {
top: 50%;
}
.box-1:hover :not(img) {
opacity: 1;
}
<div class="container-1">
<div class="box-1">
<a href="c1.html" target="_blank">
<img class="candle-image" src="image/candlesp/IMG_0900.jpg"/></a>
<h2>Festivity</h2>
</div>
<div class="box-1">
<img src="image/candlesp/IMG_0903.jpg" alt="">
<h2>Cinnamon</h2>
</div>
<div class="box-1">
<img src="image/candlesp/IMG_0917.jpg" alt="">
<h2>Forest</h2>
</div>
</div>
I think you are accidentally making <a> position: absolute. Instead of using :not, why not target the h2 directly .box-1 h2 and also try giving it a width and height
You close img tag in anchor tag
<div class="container-1">
<div class="box-1">
<a href="c1.html" target="_blank">
<img class="candle-image" src="image/candlesp/IMG_0900.jpg"></a>
<h2>Festivity</h2>
</div>
<div class="box-1">
<img src="image/candlesp/IMG_0903.jpg" alt="">
<h2>Cinnamon</h2>
</div>
<div class="box-1">
<img src="image/candlesp/IMG_0917.jpg" alt="">
<h2>Forest</h2>
</div>
</div>
I would like to display a css-grid which is full of flipcards. However, I found that if there isn't a non-flipcard element in a row of the css-grid, then it doesn't display properly: the rows overlap, the background-color isn't taken into account and the back side of the flipcard doesn't appear.
I think that the problem isn't linked with whichever version I use, for I also tested the following code in codepen.io and the problem is still there.
Here is my html:
<section class="grid-1">
<div class="flip-container item1">
<div class="flipper">
<div class="front">
1 front
</div>
<div class="back">
1 back
</div>
</div>
</div>
<div class="flip-container item2">
<div class="flipper">
<div class="front">
2 front
</div>
<div class="back">
2 back
</div>
</div>
</div>
<div class="flip-container item3">
<div class="flipper">
<div class="front">
3 front
</div>
<div class="back">
3 back
</div>
</div>
</div>
</section>
And here is my css:
body {
padding-top: 20px;
background: #f5f7f8;
}
.grid-1 {
display: grid;
padding-left: 20%;
padding-right: 20%;
width: 60%;
grid-template-columns: 1fr 1fr;
grid-auto-rows: 1fr;
grid-row-gap: 0.5%;
grid-template-areas: "item1 item2"
"item3 .";
}
.grid-1 div {
color: white;
font-size: 20px;
width: 100%;
height: 100%;
}
.item1{
grid-area: item1;
}
.item2{
grid-area:item2;
}
.item3{
grid-area: item3;
}
.flip-container {
background-color: transparent;
}
.flipper {
position: relative;
transition: transform 0.6s;
transform-style: preserve-3d;
}
.flip-container:hover .flipper {
transform: rotateY(180deg);
}
.front, .back {
position: absolute;
backface-visibility: hidden;
}
.front {
background-color: #bbb;
color: black !important;
}
.back {
background-color: #2980b9;
color: white;
transform: rotateY(180deg);
}
If the item1 or item2 is a simple div instead of a flip-container, then it all goes back to normal, the two rows don't overlap, the background-color is taken into account and the back side of the flipcard appears.
I would like to know where the problem lies, I'm quite a newbie css-wise so I don't really know where I should start to search.
Edit:
Thanks to Paulie_D, I now know how to do it, the answer is to set a height in px. However, I would also like to have a responsive grid, in which I will put images. How can I set a responsive height for element?
You have to give the elements a height...as the original 100% will not translate until the parent has a defined height.
body {
padding-top: 20px;
background: #f5f7f8;
}
.grid-1 {
display: grid;
padding-left: 20%;
padding-right: 20%;
width: 60%;
grid-template-columns: 1fr 1fr;
grid-auto-rows: 1fr;
grid-row-gap: 0.5%;
grid-template-areas: "item1 item2" "item3 .";
}
.grid-1 div {
color: white;
font-size: 20px;
width: 100%;
height: 100px;
}
.item1 {
grid-area: item1;
}
.item2 {
grid-area: item2;
}
.item3 {
grid-area: item3;
}
.flip-container {
background-color: transparent;
}
.flipper {
position: relative;
transition: transform 0.6s;
transform-style: preserve-3d;
}
.flip-container:hover .flipper {
transform: rotateY(180deg);
}
.front,
.back {
position: absolute;
backface-visibility: hidden;
}
.front {
background-color: #bbb;
color: black !important;
}
.back {
background-color: #2980b9;
color: white;
transform: rotateY(180deg);
}
<section class="grid-1">
<div class="flip-container item1">
<div class="flipper">
<div class="front">
1 front
</div>
<div class="back">
1 back
</div>
</div>
</div>
<div class="flip-container item2">
<div class="flipper">
<div class="front">
2 front
</div>
<div class="back">
2 back
</div>
</div>
</div>
<div class="flip-container item3">
<div class="flipper">
<div class="front">
3 front
</div>
<div class="back">
3 back
</div>
</div>
</div>
</section>
I have created div with flex only one active in at a time. It seems working well in body with 1200px, but less than 1200px its start flickering due to inside hide/show (class content) on transition.
If I will not change content class display none from flex it is working well; but I need to switch display flex.
See codepen and snippet below:
$('.top div').click(function(){
$('.top div').removeClass('active')
$(this).addClass('active')
})
body {
background-color: #fff;
}
.top {
display: flex;
}
.top .item {
display: flex;
border: 1px solid black;
padding: 10px;
flex-grow: 1;
flex-basis: 0;
height: 180px;
transition: all .5s;
}
.top .item .flexo-box {
display: flex;
flex-basis: 0;
background: #f8f8f8;
box-sizing: border-box;
position: relative;
}
.top .item .flexo-box img {
width: 100%;
max-width: 180px;
}
.top .item .view-btn {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
opacity: 0;
z-index: 2;
background: #eeeeee;
}
.top > div:not(:last-child) {
margin-right: 20px;
}
.top .active {
background-color: white;
flex-grow: 4;
flex-basis: 0;
opacity: 1;
}
.content {
display: none;
box-sizing: border-box;
height: 100%;
}
.content .active-tab {
height: 50px;
}
.content .active-tab p, .content .archive-tab p {
font-size: 12px;
margin: 0;
}
.content .active-tab p.active, .content .archive-tab p.active {
background: blue;
}
.content .active-tab p.active + span, .content .archive-tab p.active + span {
background: blue;
}
.content .active-tab span, .content .archive-tab span {
font-size: 10px;
}
.item.active .flexo-box:hover .view-btn {
opacity: 1;
}
.item.active .content {
display: flex;
flex-grow: 2;
}
.item > div {
flex-grow: 1;
flex-basis: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="top">
<div class="item">
<div class='flexo-box'>
<img src="https://picsum.photos/200/300">
<span class="view-btn">
<a href="/jobs/12526/proof_documents/19776" class="btn btn-secondary proof__order__link ">
View File
</a>
</span>
</div>
<div class='content'>
<div class="active-tab">
<p>dfgsfgsfg<p>
<p class="active">012620_11254_LEN_78441.pdf</p>
<span>fsdfgfs0<span>
<div class="archive-tab">
<h3>Archived file</h3>
<p>012620_87896_LEN_11548.pdf</p>
<span> archived dfgfd4<span>
<p>012620_16975_LEN_98761.pdf<p>
<span>archived sdfgsfg</span>
</div>
</div>
</div>
</div>
<div class="item">
<div class='flexo-box'>
<img src="https://picsum.photos/200/300" alt="" onerror="this.src = 'http://10.0.0.73:3000/assets/placeholder-6c8626f646674836d73093c5cd6377a4b8a05f672e0f14147692482e930d9bba.jpg'">
</div>
<div class='content'>
hello
</div>
</div>
<div class='item active'>
<div class='flexo-box'></div>
<div class='content'>
hello
</div>
</div>
<div class="item">
<div class='flexo-box'></div>
<div class='content'>
hello
</div>
</div>
<div class="item">
<div class='flexo-box'>
<img src="https://picsum.photos/200/300" alt="" onerror="this.src = 'http://10.0.0.73:3000/assets/placeholder-6c8626f646674836d73093c5cd6377a4b8a05f672e0f14147692482e930d9bba.jpg'">
</div>
<div class='content'>
<div class="active-tab">
<p>current file<p>
<p class="active">012620_11254_LEN_78441.pdf</p>
<span>wertrwet 190314 1250<span>
<div class="archive-tab">
<h3>Archived file</h3>
<p>012620_87896_LEN_11548.pdf</p>
<span> wert ertrwet4<span>
<p>012620_16975_LEN_98761.pdf<p>
<span> 190309 1ertret152</span>
</div>
</div>
</div>
</div>
</div>
</div>
The display property can't be animated - so remove display: none from content and add these:
.item>.content {
min-width: 0;
flex: 0;
overflow: hidden;
}
Now the content will be zero-width and the flexo-box will occupy all space. Note the use of min-width: 0 - this allows the flex item to shrink beyond its content (default min-width of a flex item is auto).
Now you can add min-width: 0 to the item too for a smoother animation - see demo below:
$('.top div').click(function() {
$('.top div').removeClass('active')
$(this).addClass('active')
})
body {
background-color: #fff;
}
.top {
display: flex;
}
.top .item {
display: flex;
border: 1px solid black;
padding: 10px;
flex-grow: 1;
flex-basis: 0;
height: 180px;
transition: all .5s;
min-width: 0; /* added */
}
.top .item .flexo-box {
display: flex;
flex-basis: 0;
background: #f8f8f8;
box-sizing: border-box;
position: relative;
}
.top .item .flexo-box img {
width: 100%;
max-width: 180px;
}
.top .item .view-btn {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
opacity: 0;
z-index: 2;
background: #eeeeee;
}
.top>div:not(:last-child) {
margin-right: 20px;
}
.top .active {
background-color: white;
flex-grow: 4;
flex-basis: 0;
opacity: 1;
}
.content {
/*display: none;*/
box-sizing: border-box;
height: 100%;
}
.content .active-tab {
height: 50px;
}
.content .active-tab p,
.content .archive-tab p {
font-size: 12px;
margin: 0;
}
.content .active-tab p.active,
.content .archive-tab p.active {
background: blue;
}
.content .active-tab p.active+span,
.content .archive-tab p.active+span {
background: blue;
}
.content .active-tab span,
.content .archive-tab span {
font-size: 10px;
}
.item.active .flexo-box:hover .view-btn {
opacity: 1;
}
.item.active .content {
display: flex;
flex-grow: 2;
}
.item>div {
flex-grow: 1;
flex-basis: 0;
}
.item>.content { /* added */
min-width: 0; /* allow it to go to zero */
flex: 0; /* reduce the width */
overflow: hidden; /* hide oveflow */
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="top">
<div class="item">
<div class='flexo-box'>
<img src="https://picsum.photos/200/300">
<span class="view-btn">
<a href="/jobs/12526/proof_documents/19776" class="btn btn-secondary proof__order__link ">
View File
</a>
</span>
</div>
<div class='content'>
<div class="active-tab">
<p>dfgsfgsfg</p>
<p class="active">012620_11254_LEN_78441.pdf</p>
<span>fsdfgfs0</span>
<div class="archive-tab">
<h3>Archived file</h3>
<p>012620_87896_LEN_11548.pdf</p>
<span> archived dfgfd4</span>
<p>012620_16975_LEN_98761.pdf</p>
<span>archived sdfgsfg</span>
</div>
</div>
</div>
</div>
<div class="item">
<div class='flexo-box'>
<img src="https://picsum.photos/200/300" alt="" onerror="this.src = 'http://10.0.0.73:3000/assets/placeholder-6c8626f646674836d73093c5cd6377a4b8a05f672e0f14147692482e930d9bba.jpg'">
</div>
<div class='content'>
hello
</div>
</div>
<div class='item active'>
<div class='flexo-box'></div>
<div class='content'>
hello
</div>
</div>
<div class="item">
<div class='flexo-box'></div>
<div class='content'>
hello
</div>
</div>
<div class="item">
<div class='flexo-box'>
<img src="https://picsum.photos/200/300" alt="" onerror="this.src = 'http://10.0.0.73:3000/assets/placeholder-6c8626f646674836d73093c5cd6377a4b8a05f672e0f14147692482e930d9bba.jpg'">
</div>
<div class='content'>
<div class="active-tab">
<p>current file</p>
<p class="active">012620_11254_LEN_78441.pdf</p>
<span>wertrwet 190314 1250</span>
<div class="archive-tab">
<h3>Archived file</h3>
<p>012620_87896_LEN_11548.pdf</p>
<span> wert ertrwet4</span>
<p>012620_16975_LEN_98761.pdf</p>
<span> 190309 1ertret152</span>
</div>
</div>
</div>
</div>
</div>
I'm trying to create a layout for print content on sticker label.
So, I create div and use display:grid; to divide space as I want.
The item1, item2, and item3 should overlap each other and centered in the cell.
.grid {
display: grid;
grid-template-columns: 1fr 1fr;
grid-auto-rows: 70mm; // Seems useless
align-items: center;
}
.cell {
border-style: dashed;
width: 100mm;
height: 70mm;
align-content: center;
}
.item1 {
z-index: 0;
width: 40mm;
height: 40mm;
background-color: red;
position: relative;
}
.item2 {
z-index: 1;
width: 20mm;
height: 20mm;
background-color: blue;
position: relative;
}
.item2 {
z-index: 2;
width: 10mm;
height: 10mm;
background-color: green;
position: relative;
}
<div class="grid">
<div class="cell">
<div class="item1"></div>
<div class="item2"></div>
<img class="item3" src="./src.png" />
</div>
<div class="cell">
<div class="item1"></div>
<img class="item2" src="./src.png" />
<div class="item3"></div>
</div>
<div class="cell">
<div class="item1"></div>
<img class="item2" src="./src.png" />
<div class="item3"></div>
</div>
</div>
I can't achieve the correct result: A grid with items centered horizontally AND vertically in each cell. The cell should have precise size (100mmx70mm), 2 cells per row since the page should be printed.
Is there any CSS wizard in the audience that can help me?
All you need is absolute positioning and translate transformations based on percentage.
.grid {
display: grid;
grid-template-columns: 1fr 1fr;
grid-auto-rows: 70mm; // Seems useless
align-items: center;
}
.cell {
border-style: dashed;
width: 100mm;
height: 70mm;
align-content: center;
position: relative;
}
.cell>*{
position: absolute;
left:50%;
top: 50%;
transform: translateX(-50%) translateY(-50%);
}
.item1 {
z-index: 0;
width: 40mm;
height: 40mm;
background-color: red;
}
.item2 {
z-index: 1;
width: 20mm;
height: 20mm;
background-color: blue;
}
.item2 {
z-index: 2;
width: 10mm;
height: 10mm;
background-color: green;
}
<div class="grid">
<div class="cell">
<div class="item1"></div>
<div class="item2"></div>
<img class="item3" src="./src.png" />
</div>
<div class="cell">
<div class="item1"></div>
<img class="item2" src="./src.png" />
<div class="item3"></div>
</div>
<div class="cell">
<div class="item1"></div>
<img class="item2" src="./src.png" />
<div class="item3"></div>
</div>
</div>
I am displaying two columns in the center of my grid with contents and I need to make these two columns above each other in mobile view how I can do that?
.two-pics {
display: grid;
grid-gap: 50px;
grid-template-columns: 400px 400px;
object-fit: cover;
color: #444;
margin-top: 100px;
justify-content: center;
}
.box {
background-color: white;
color: #fff;
border-radius: 5px;
font-size: 150%;
}
.a {
grid-column: 1;
grid-row: 1 / 12;
}
.b {
grid-column: 2;
grid-row: 1 / 12;
}
<div class="two-pics">
<div class="box a">
<img src="assets/images/pic1.jpg">
<br>
<p>title</p>
<ul>
<li></li>
<li>dfgdfghdfhdfh</li>
<li>dfgdfghdfhdfh</li>
<li>dfgdfghdfhdfh</li>
</ul>
</div>
<div class="box b">
<img src="assets/images/pic2.jpg">
<br>
<p>ldkjh ldkjfh ldk hjf</p>
</div>
</div>
Using the auto-fit property you can create as many 400px grid tracks as will fit in the container.
codepen
body {
background: grey;
}
.two-pics {
display: grid;
grid-gap: 50px;
grid-template-columns: repeat(auto-fit, 400px);
color: #444;
margin-top: 100px;
justify-content: center;
}
.box {
background-color: white;
color: #000;
border-radius: 5px;
font-size: 150%;
}
<div class="two-pics">
<div class="box a">
<img src="https://unsplash.it/400">
<br>
<p>title</p>
<ul>
<li>dfdfd</li>
<li>dfgdfghdfhdfh</li>
<li>dfgdfghdfhdfh</li>
<li>dfgdfghdfhdfh</li>
</ul>
</div>
<div class="box b">
<img src="https://unsplash.it/400">
<br>
<p>ldkjh ldkjfh ldk hjf</p>
</div>
</div>