I'm new to grids in CSS but I want to give it a try. I have a grid with 3x3 boxes. When I hover over a box it should should out the complete row... but that's not working.
When I hover over 1
it fills out the screen completely, and when I hover over 3
my screen starts to blink and it's not working.
.container {
display: grid;
grid-gap: 10px;
grid-template-columns: repeat(3, minmax(100px, auto));
grid-template-rows: repeat(3, minmax(100px, auto));
}
[class^="item"] {
text-align: center;
box-sizing: border-box;
padding: 10%;
font-size: 5em;
color: #0580d5;
transition: .2s;
}
[class^="item"]:hover {
grid-column-start: 1;
grid-column-end: 4;
}
.item-1 {
/*grid-area: 1 / 2 / span 2 / span 2;*/
}
.container>div {
border: 2px solid #0580d5;
background-color: rgba(40, 180, 240, .3);
border-radius: 5px;
}
@media only screen and (min-width: 789px) {
.container {
grid-template-columns: repeat(3, 1fr);
}
}
<div class="container">
<div class="item-1">1</div>
<div class="item-2">2</div>
<div class="item-3">3</div>
<div class="item-4">4</div>
<div class="item-5">5</div>
<div class="item-6">6</div>
<div class="item-7">7</div>
<div class="item-8">8</div>
<div class="item-9">9</div>
</div>
Span the first column over the two rows by using grid-row: span 2. Span the first row in the second column by using grid-column: span 2 . Extend the table over the last grid item by using 100% width and height.
The most simple way to reset any CSS property to its initial value is to use initial value. It will work on any property and you won't have to worry about any property defaults. But in the current case 1fr and none will work as well, of course.
Here is an idea where you can rely on negative margin to create the overlap effect whithout changing the structure and using display:contents
.container {
display: grid;
grid-gap: 10px;
grid-template-columns: repeat(3, minmax(100px, auto));
grid-template-rows: repeat(3, minmax(100px, auto));
}
[class^="item"] {
text-align: center;
box-sizing: border-box;
padding: 10%;
font-size: 5em;
color: #0580d5;
transition: .2s;
}
[class^="item"]:hover {
z-index:2; /*we increase the z-index to cover the other*/
background:
/*we this to keep the initial background*/
linear-gradient(rgba(40, 180, 240, .3),rgba(40, 180, 240, .3)),
#fff;
}
[class^="item"]:nth-child(3n + 1):hover {
margin-right:calc(-200% - 20px); /* we remove (2 x grid items + 2 x gap) */
}
[class^="item"]:nth-child(3n + 2):hover {
margin-left:calc(-100% - 10px);
margin-right:calc(-100% - 10px);
}
[class^="item"]:nth-child(3n + 3):hover {
margin-left:calc(-200% - 20px);
}
.container>div {
border: 2px solid #0580d5;
background-color: rgba(40, 180, 240, .3);
border-radius: 5px;
}
@media only screen and (min-width: 789px) {
.container {
grid-template-columns: repeat(3, 1fr);
}
}
<div class="container">
<div class="item-1">1</div>
<div class="item-2">2</div>
<div class="item-3">3</div>
<div class="item-4">4</div>
<div class="item-5">5</div>
<div class="item-6">6</div>
<div class="item-7">7</div>
<div class="item-8">8</div>
<div class="item-9">9</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With