I'm trying to get the divs always be centered even after one div drops to the bottom if window size is adjusted. So basically if there are 5 divs and one drops to the bottom after window size reached a certain point, so the remaining 4 divs would still be centered. If possible it would be better if the one dropped wouldn't center but be on the left.
.item-holder {
width: 95%;
height: 80%;
margin-left: auto;
margin-right: auto;
overflow: scroll;
background-color: teal;
}
.item {
width: 300px;
height: 300px;
background-color: black;
float: left;
margin-right: 25px;
margin-left: 25px;
margin-bottom: 25px;
}
.item-text {
font-size: 20px;
color: white;
}
<div class="item-holder">
<div class="item">
<p class="item-text">Item 1</p>
</div>
<div class="item">
<p class="item-text">Item 2</p>
</div>
<div class="item">
<p class="item-text">Item 3</p>
</div>
<div class="item">
<p class="item-text">Item 4</p>
</div>
<div class="item">
<p class="item-text">Item 5</p>
</div>
<div class="item">
<p class="item-text">Item 6</p>
</div>
<div class="item">
<p class="item-text">Item 7</p>
</div>
<div class="item">
<p class="item-text">Item 8</p>
</div>
<div class="item">
<p class="item-text">Item 9</p>
</div>
<div class="item">
<p class="item-text">Item 10</p>
</div>
</div>
How the result should look
Use CSS Grid Layout
CSS Grid was like made for this purpose. In the following snippet, I have removed some of your lines and resized the children. But you need to pay attention to the three lines of code added to .item-holder.
I have also made the holder resizable, so you can play with it.
.item-holder {
width: 95%;
height: 80%;
background-color: teal;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
grid-gap: 5px;
/* Following code makes the element resizable*/
resize: horizontal;
overflow: auto;
}
.item {
width: 100px;
height: 50px;
background-color: black;
}
.item-text {
font-size: 20px;
color: white;
}
<div class="item-holder">
<div class="item">
<p class="item-text">Item 1</p>
</div>
<div class="item">
<p class="item-text">Item 2</p>
</div>
<div class="item">
<p class="item-text">Item 3</p>
</div>
<div class="item">
<p class="item-text">Item 4</p>
</div>
<div class="item">
<p class="item-text">Item 5</p>
</div>
<div class="item">
<p class="item-text">Item 6</p>
</div>
<div class="item">
<p class="item-text">Item 7</p>
</div>
<div class="item">
<p class="item-text">Item 8</p>
</div>
<div class="item">
<p class="item-text">Item 9</p>
</div>
<div class="item">
<p class="item-text">Item 10</p>
</div>
</div>
Further Reading
See CSS Grid Layout on MDN
Learn CSS Grid Layout on freeCodeCamp.org
See CSS Grid Layout: Create flexible layouts using auto-fill on freeCodeCamp.org
You can make the .item-holder a flexbox
.item-holder {
width: 95%;
height: 80%;
margin-left: auto;
margin-right: auto;
overflow: scroll;
background-color: teal;
display: flex;
flex-flow: row wrap;
}
.item {
width: 100px;
height: 100px;
background-color: black;
float: left;
margin-right: 25px;
margin-left: 25px;
margin-bottom: 25px;
}
.item-text {
font-size: 20px;
color: white;
}
<div class="item-holder">
<div class="item">
<p class="item-text">Item 1</p>
</div>
<div class="item">
<p class="item-text">Item 2</p>
</div>
<div class="item">
<p class="item-text">Item 3</p>
</div>
<div class="item">
<p class="item-text">Item 4</p>
</div>
<div class="item">
<p class="item-text">Item 5</p>
</div>
<div class="item">
<p class="item-text">Item 6</p>
</div>
<div class="item">
<p class="item-text">Item 7</p>
</div>
<div class="item">
<p class="item-text">Item 8</p>
</div>
<div class="item">
<p class="item-text">Item 9</p>
</div>
<div class="item">
<p class="item-text">Item 10</p>
</div>
</div>
Related
I have the following CSS layout:
* {
margin: 0;
box-sizing: border-box;
}
body {
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
nav {
background-color: darkslateblue;
color: white;
padding: 20px;
}
main h2 {
padding: 20px 20px 10px 20px;
}
#item-wrapper {
display: flex;
padding: 10px;
}
#item-selector,
#item-viewer {
margin: 0 10px;
}
#item-selector {
display: flex;
flex-direction: column;
width: 250px;
overflow-y: scroll;
}
#item-viewer {
flex: 1;
height: 50vh;
}
.item {
border: 3px solid darkslateblue;
margin-bottom: 10px;
padding: 10px;
cursor: pointer;
}
#item-viewer {
border: 3px solid darkslateblue;
}
<nav>
<h1>Header</h1>
</nav>
<main>
<h2>Your items:</h2>
<div id="item-wrapper">
<div id="item-selector">
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
</div>
<div id="item-viewer">
<p style="padding: 10px;">Select an item on the left to view more information</p>
</div>
</div>
</main>
I want the scrollable div on the left to not exceed the height of the window. I have tried setting the height of <body> and <html> to 100vh and adding overflow: auto and overflow: hidden to body, html, #item-wrapper and #item-selector but none of these worked. If I give #item-selector and explicit height then it works, but I want it to fill the remainder of the window height so this isn't ideal. I would like #item-selector to not exceed the height of the page and to scroll when its contents exceed its height.
You have to apply height settings to all parent elements, so html and body and #item-selector get height: 100%;, and main has to get a calculated height value, which subtracts the height of the nav and h2 elements from 100%. height: calc(100% - 130px); will approximately do that like in the snippet below, but you either would have to define exact height settings for nav and h2, or use javascript to get their actual heights.
* {
margin: 0;
box-sizing: border-box;
}
html {
height: 100%;
}
body {
font-family: Verdana, Geneva, Tahoma, sans-serif;
height: 100%;
}
nav {
background-color: darkslateblue;
color: white;
padding: 20px;
}
main {
height: calc(100% - 130px);
}
main h2 {
padding: 20px 20px 10px 20px;
}
#item-wrapper {
display: flex;
padding: 10px;
height: 100%;
}
#item-selector,
#item-viewer {
margin: 0 10px;
}
#item-selector {
display: flex;
flex-direction: column;
width: 250px;
overflow-y: scroll;
height: 100%;
}
#item-viewer {
flex: 1;
height: 50vh;
}
.item {
border: 3px solid darkslateblue;
margin-bottom: 10px;
padding: 10px;
cursor: pointer;
}
#item-viewer {
border: 3px solid darkslateblue;
}
<nav>
<h1>Header</h1>
</nav>
<main>
<h2>Your items:</h2>
<div id="item-wrapper">
<div id="item-selector">
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
</div>
<div id="item-viewer">
<p style="padding: 10px;">Select an item on the left to view more information</p>
</div>
</div>
</main>
* {
margin: 0;
box-sizing: border-box;
}
body {
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
nav {
background-color: darkslateblue;
color: white;
padding: 20px;
height: 10vh;
}
main h2 {
padding: 5px 20px 20px 20px;
}
#item-wrapper {
display: flex;
padding: 10px;
height:85vh;
}
#itemHeaderWrapper{
height:5vh;
}
#item-selector,
#item-viewer {
margin: 0 10px;
}
#item-selector {
display: flex;
flex-direction: column;
width: 250px;
overflow-y: scroll;
}
#item-viewer {
flex: 1;
height: 50vh;
}
.item {
border: 3px solid darkslateblue;
margin-bottom: 10px;
padding: 10px;
cursor: pointer;
}
#item-viewer {
border: 3px solid darkslateblue;
}
<nav>
<h1>Header</h1>
</nav>
<main>
<div id='itemHeaderWrapper'>
<h2>Your items:</h2>
</div>
<div id="item-wrapper">
<div id="item-selector">
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
<div class="item">
<p style="font-size:50px;">Item</p>
</div>
</div>
<div id="item-viewer">
<p style="padding: 10px;">Select an item on the left to view more information</p>
</div>
</div>
</main>
In this code, I've wrapped the h2 tag in a div, id 'itemHeaderWrapper' which I've given a pre-defined height of 5vh. I've also set the height of the nav to 10vh. This means I can force the scrollable div on the left to have height 85vh and then scroll.
I'm trying to create a script that will match div ids that scroll into view with the corresponding children in a gallery. I don't want to have to create individual scrollTop codes for each div id—so needing some kind of variable for the index of each div id? I've struggled to find anything close online.
This is the simple scrollTop code I am using as an example. When the "in-view" class is applied, the corresponding gallery items change their opacity.
<script>
$(function(){
$(document).scroll(function(){
if($(this).scrollTop() >= $("#item-1").offset().top - 250) {
$(".sticky-gallery .image-item:nth-child(1)").addClass("in-view");
} else {
$(".sticky-gallery .image-item:nth-child(1)").removeClass("in-view");
}
});
});
</script>
I'm hoping there's a way to create something that can flexibly work for #item-1 with nth-child(1), #item-2 with nth-child(2), etc...
Thank you for any guidance.
I think you can do this very simply by pairing off an array of the div elements with an array of the gallery elements. See the code below for a basic example.
This satisfies the requirements:
matching scrolling divs with gallery items
changing gallery item's styling when matching div in view
no ids required on divs, and indeed no ids equired on gallery items
var sections;
var galleryItems;
function getViewScrollingElements() {
sections = document.getElementsByClassName("section");
galleryItems = document.getElementsByClassName("item");
// Do first check before a scroll could have occured
checkInView();
}
function checkInView () {
var boundingRect;
for ( var i = 0; i < sections.length; i++ ) {
// Get the extremities of the div
boundingRect = sections[i].getBoundingClientRect();
// Are the div's extremities in view
if ( boundingRect.top < window.innerHeight && boundingRect.bottom >= 0 ) {
galleryItems[i].style.opacity = "1";
} else {
galleryItems[i].style.opacity = "0.2";
}
}
}
/* The gallery */
.gallery {
position: fixed;
top: 2vh;
background: none;
border: 2px solid red;
}
.item {
opacity: 0.2;
display: inline-block;
border: 2px solid black;
padding: 2px;
margin: 2px;
}
/* The scrolling items */
.section {
height: 40vh;
}
/* Make sections stand out.*/
.scroll_container > div:nth-of-type(odd).section {
background: pink;
}
.scroll_container > div:nth-of-type(even).section {
background: wheat;
}
<body onLoad="getViewScrollingElements()" onScroll="checkInView()">
<div class="gallery">
<div class="item">
<p>Item 1</p>
</div>
<div class="item">
<p>Item 2</p>
</div>
<div class="item">
<p>Item 3</p>
</div>
<div class="item">
<p>Item 4</p>
</div>
<div class="item">
<p>Item 5</p>
</div>
<div class="item">
<p>Item 6</p>
</div>
<div class="item">
<p>Item 7</p>
</div>
<div class="item">
<p>Item 8</p>
</div>
<div class="item">
<p>Item 9</p>
</div>
<div class="item">
<p>Item 10</p>
</div>
<div class="item">
<p>Item 11</p>
</div>
<div class="item">
<p>Item 12</p>
</div>
<div class="item">
<p>Item 13</p>
</div>
<div class="item">
<p>Item 14</p>
</div>
<div class="item">
<p>Item 15</p>
</div>
<div class="item">
<p>Item 16</p>
</div>
<div class="item">
<p>Item 17</p>
</div>
<div class="item">
<p>Item 18</p>
</div>
</div>
<div class="scroll_container">
<div class="section">
<p>Section 1</p>
</div>
<div class="section">
<p>Section 2</p>
</div>
<div class="section">
<p>Section 3</p>
</div>
<div class="section">
<p>Section 4</p>
</div>
<div class="section">
<p>Section 5</p>
</div>
<div class="section">
<p>Section 6</p>
</div>
<div class="section">
<p>Section 7</p>
</div>
<div class="section">
<p>Section 8</p>
</div>
<div class="section">
<p>Section 9</p>
</div>
<div class="section">
<p>Section 10</p>
</div>
<div class="section">
<p>Section 11</p>
</div>
<div class="section">
<p>Section 12</p>
</div>
<div class="section">
<p>Section 13</p>
</div>
<div class="section">
<p>Section 14</p>
</div>
<div class="section">
<p>Section 15</p>
</div>
<div class="section">
<p>Section 16</p>
</div>
<div class="section">
<p>Section 17</p>
</div>
<div class="section">
<p>Section 18</p>
</div>
</div>
</body>
I have a flex container containing 7 columns (Monday to Sunday), each with a min-width of 100px. I want users to scroll horizontally to see every column when the screen is smaller. I set the flex container to overflow: scroll. Yes, now the scrollbar appears, and I can scroll left and right. However, the smaller the screen is, the more part of the left side is still hidden, no matter how I scroll. The right side is fine.
Please see the code here:
https://codesandbox.io/s/busy-framework-ke4l0?file=/index.html
How can I fix this? Thanks in advance.
Your problem is the justify-content: center; in the .week-flex class. Because the browser then always centers the (.week-flex) container which leads to this unexpected behavior. If you want a scrollable, centered flex container you could use an extra container like this.
<div class="page-container">
<h1>課程專區</h1>
<div class="container">
<div class="week-flex">
<div class="day-flex">
<div class="day">Monday</div>
<div class="course">
<h4 class="level">初階</h4>
<p class="topic">Lv. 1</p>
<p class="time">20:00-21:00</p>
<p class="status open">即將開課</p>
</div>
</div>
<div class="day-flex">
<div class="day">Tuesday</div>
<div class="course">
<h4 class="level">初階</h4>
<p class="topic">Lv. 1</p>
<p class="time">20:00-21:00</p>
<p class="status">課程進行中</p>
</div>
<div class="course">
<h4 class="level">初階</h4>
<p class="topic">Lv. 1</p>
<p class="time">20:00-21:00</p>
<p class="status open">即將開課</p>
</div>
</div>
<div class="day-flex">
<div class="day">Wednesday</div>
<div class="course">
<h4 class="level">初階</h4>
<p class="topic">Lv. 1</p>
<p class="time">20:00-21:00</p>
<p class="status open">即將開課</p>
</div>
<div class="course">
<h4 class="level">初階</h4>
<p class="topic">Lv. 1</p>
<p class="time">20:00-21:00</p>
<p class="status open">即將開課</p>
</div>
</div>
<div class="day-flex">
<div class="day">Thursday</div>
<div class="course">
<h4 class="level">初階</h4>
<p class="topic">Lv. 1</p>
<p class="time">20:00-21:00</p>
<p class="status">課程進行中</p>
</div>
</div>
<div class="day-flex">
<div class="day">Friday</div>
<div class="course">
<h4 class="level">初階</h4>
<p class="topic">Lv. 1</p>
<p class="time">20:00-21:00</p>
<p class="status open">即將開課</p>
</div>
</div>
<div class="day-flex">
<div class="day">Saturday</div>
<div class="course">
<h4 class="level">初階</h4>
<p class="topic">Lv. 1</p>
<p class="time">20:00-21:00</p>
<p class="status open">即將開課</p>
</div>
</div>
<div class="day-flex">
<div class="day">Sunday</div>
<div class="course">
<h4 class="level">初階</h4>
<p class="topic">Lv. 1</p>
<p class="time">20:00-21:00</p>
<p class="status">課程進行中</p>
</div>
</div>
</div>
</div>
</div>
And the css.
.container {
display: flex;
width: 100%;
max-width: 100%;
overflow: auto;
}
.week-flex {
display: flex;
flex-direction: row;
column-gap: 10px;
margin: 0 auto;
}
.day-flex {
display: flex;
flex-direction: column;
row-gap: 10px;
min-width: 100px;
text-align: center;
}
.course {
width: 100%;
border: 1px solid black;
border-radius: 5px;
padding: 5px 0;
}
h4 {
margin: 0;
}
.status {
color: #125a12;
}
.status.open {
color: #941616;
}
Here is also a working codesandbox: https://codesandbox.io/s/gifted-albattani-e75bc
How do place these div's next to each other in a 3x2 row instead of rows of 1.
Should I make the event-box and event-info as one div instead of two separate div's? I've tried to combine them as one div and given the <p> the event-info class but that didn't work out. I've also tried different sizes for both of the div's and the container to maybe push them next to each other, but that also didn't work. See my code below.
.event-box{
height: 5rem;
width: 30rem;
float: left;
clear: both;
padding: 0;
margin-top: 1rem;
text-align: center;
background: url(/assets/images/placeholderimg4.jpg);}
.event-info{
height: 5rem;
width: 30rem;
float: left;
clear: both;
padding: 0;
margin: 0;
text-align: center;
background-color: rgba(77, 75, 75, 0.1);}
.container{
height: 100%;
width: 64rem;
word-wrap: break-word;
overflow-y: hidden;
padding: 0;}
<div class="container">
<div class="event-box">
<h3 class="event-text">Event 1</h3>
</div>
<div class="event-info">
<p>1</p>
</div>
<div class="event-box">
<h3 class="event-text">Event 2</h3>
</div>
<div class="event-info">
<p>2</p>
</div>
<div class="event-box">
<h3 class="event-text">Event 3</h3>
</div>
<div class="event-info">
<p>3</p>
</div>
<div class="event-box">
<h3 class="event-text">Event 4</h3>
</div>
<div class="event-info">
<p>4</p>
</div>
<div class="event-box">
<h3 class="event-text">Event 5</h3>
</div>
<div class="event-info">
<p>5</p>
</div>
<div class="event-box">
<h3 class="event-text">Event 6</h3>
</div>
<div class="event-info">
<p>6</p>
</div>
</div>
So I used CSS grid for this.
I did combine your event-info and event-box div's together to make them one object in the grid.
.event-box {
height: 5rem;
width: 30rem;
float: left;
clear: both;
padding: 0;
margin-top: 1rem;
text-align: center;
background: url(/assets/images/placeholderimg4.jpg);
}
.event-info {
height: 5rem;
width: 30rem;
float: left;
clear: both;
padding: 0;
margin: 0;
text-align: center;
background-color: rgba(77, 75, 75, 0.1);
}
.container {
height: 100%;
width: 64rem;
word-wrap: break-word;
padding: 0;
display: grid;
grid-template-columns: auto auto auto;
grid-template-rows: auto auto;
grid-gap: 2rem;
}
<div class="container">
<div class="event-box">
<h3 class="event-text">Event 1</h3>
<div class="event-info">
<p>1</p>
</div>
</div>
<div class="event-box">
<h3 class="event-text">Event 2</h3>
<div class="event-info">
<p>2</p>
</div>
</div>
<div class="event-box">
<h3 class="event-text">Event 3</h3>
<div class="event-info">
<p>3</p>
</div>
</div>
<div class="event-box">
<h3 class="event-text">Event 4</h3>
<div class="event-info">
<p>4</p>
</div>
</div>
<div class="event-box">
<h3 class="event-text">Event 5</h3>
<div class="event-info">
<p>5</p>
</div>
</div>
<div class="event-box">
<h3 class="event-text">Event 6</h3>
<div class="event-info">
<p>6</p>
</div>
</div>
</div>
So in the container class I added a display of grid (to use grid functions) and then I added grid-template-columns (which allows you to specify how many columns you want to include) and a grid-template-rows to do the same thing for the rows. I then added a grid-gap to separate the div tags a bit but this value can be played with depending on the desired gap.
You can add a wrap div, like 'event' for it :
<div class="container">
<div class='event'>
<div class="event-box">
<h3 class="event-text">Event 1</h3>
</div>
<div class="event-info">
<p>1</p>
</div>
</div>
<div class='event'>
<div class="event-box">
<h3 class="event-text">Event 2</h3>
</div>
<div class="event-info">
<p>2</p>
</div>
</div>
<div class='event'>
<div class="event-box">
<h3 class="event-text">Event 3</h3>
</div>
<div class="event-info">
<p>3</p>
</div>
</div>
<div class='event'>
<div class="event-box">
<h3 class="event-text">Event 4</h3>
</div>
<div class="event-info">
<p>4</p>
</div>
</div>
<div class='event'>
<div class="event-box">
<h3 class="event-text">Event 5</h3>
</div>
<div class="event-info">
<p>5</p>
</div>
</div>
<div class='event'>
<div class="event-box">
<h3 class="event-text">Event 6</h3>
</div>
<div class="event-info">
<p>6</p>
</div>
</div>
</div>
And a little css addition:
.event{
display:inline-block;
width:49%;
}
Try it - https://jsfiddle.net/5vz3Lhwc/
You can make use of the power of Flexbox! Wrap each row in a div with class row and each column in a div with class col. Example:
<div class="container">
<div class="row">
<div class="col">
<div class="event-box">
<h3 class="event-text">Event 1</h3>
</div>
<div class="event-info">
<p>1</p>
</div>
</div>
<div class="col">
<div class="event-box">
<h3 class="event-text">Event 2</h3>
</div>
<div class="event-info">
<p>2</p>
</div>
</div>
<div class="col">
<div class="event-box">
<h3 class="event-text">Event 3</h3>
</div>
<div class="event-info">
<p>3</p>
</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="event-box">
<h3 class="event-text">Event 4</h3>
</div>
<div class="event-info">
<p>4</p>
</div>
</div>
<div class="col">
<div class="event-box">
<h3 class="event-text">Event 5</h3>
</div>
<div class="event-info">
<p>5</p>
</div>
</div>
<div class="col">
<div class="event-box">
<h3 class="event-text">Event 6</h3>
</div>
<div class="event-info">
<p>6</p>
</div>
</div>
</div>
</div>
The CSS for the added elements:
.row {
width: 100%;
display: flex;
}
.col {
width: 33%;
flex: 1;
}
Edit: CSS Grid might be an even easier solution.
I have a goods list - floating div with position: relative. I need to change height of this block (for buttons like 'Add to basket') when I hover it without touching/moving another blocks. For example: wildberries.ru/catalog/20/women.aspx
I've tried to copy styles from that site but have failed. I don't fully understanding how it work =|
I have something like this:
#goods { width: 330px }
.item {
position: relative;
float: left;
width: 80px;
height: 140px;
margin: 5px;
padding: 8px;
border: solid 1px #999;
overflow: hidden;
text-align: center;
}
.item:hover {
height: 180px;
}
p { margin: 3px }
<div id="goods">
<div class="item">
<img src="http://placehold.it/80x120" />
<p>Cool item</p>
<button>buy</button>
</div>
<div class="item">
<img src="http://placehold.it/80x120" />
<p>Cool item</p>
<button>buy</button>
</div>
<div class="item">
<img src="http://placehold.it/80x120" />
<p>Cool item</p>
<button>buy</button>
</div>
<div class="item">
<img src="http://placehold.it/80x120" />
<p>Cool item</p>
<button>buy</button>
</div>
<div class="item">
<img src="http://placehold.it/80x120" />
<p>Cool item</p>
<button>buy</button>
</div>
</div>
add an innerWrap div to .item and use position: absolute;
#goods { width: 330px }
.item {
position: relative;
float: left;
width: 80px;
margin: 5px;
padding: 8px;
height: 145px;
text-align: center;
}
.itemWrap{
height: 145px;
overflow: hidden;
border: solid 1px #999;
position: absolute;
}
.item:hover .itemWrap{
height: 180px;
z-index: 2;
background: #fff;
}
p { margin: 3px }
<div id="goods">
<div class="item">
<div class="itemWrap">
<img src="http://placehold.it/80x120" />
<p>Cool item</p>
<button>buy</button>
</div>
</div>
<div class="item">
<div class="itemWrap">
<img src="http://placehold.it/80x120" />
<p>Cool item</p>
<button>buy</button>
</div>
</div>
<div class="item">
<div class="itemWrap">
<img src="http://placehold.it/80x120" />
<p>Cool item</p>
<button>buy</button>
</div>
</div>
<div class="item">
<div class="itemWrap">
<img src="http://placehold.it/80x120" />
<p>Cool item</p>
<button>buy</button>
</div>
</div>
<div class="item">
<div class="itemWrap">
<img src="http://placehold.it/80x120" />
<p>Cool item</p>
<button>buy</button>
</div>
</div>
</div>