I want to create grid or table with three cards. Two cards in a row and the third under these two cards, like on the image (the third card can be other size). But how can I do this?
<div class="cards">
<div id="card1">
<img src="..." alt="Image" style="width: 100%">
<div class="card-container">
<h4 class="class-text"><b>...</b></h4>
<p></p>
</div>
</div>
<div id="card2">
<img src="..." alt="Image" style="width: 100%">
<div class="card-container">
<h4 class="class-text"><b>...</b></h4>
<p></p>
</div>
</div>
<div id="card3">
<img src="..." alt="Image" style="width: 100%">
<div class="card-container">
<h4 class="class-text"><b>...</b></h4>
<p></p>
</div>
</div>
</div>
This should work
.first-row{
display:flex;
}
.first-row .card{
flex:1;
}
.card{
border:5px solid black;
margin: 10px;
}
<div class="cards">
<div class='first-row'>
<div class='card' id="card1">
<img src="..." alt="Image" style="width: 100%">
<div class="card-container">
<h4 class="class-text"><b>...</b></h4>
<p></p>
</div>
</div>
<div class='card' id="card2">
<img src="..." alt="Image" style="width: 100%">
<div class="card-container">
<h4 class="class-text"><b>...</b></h4>
<p></p>
</div>
</div>
</div>
<div class='card' id="card3">
<img src="..." alt="Image" style="width: 100%">
<div class="card-container">
<h4 class="class-text"><b>...</b></h4>
<p></p>
</div>
</div>
</div>
Check it out.
.first-row{
display:flex;
}
.first-row .card{
flex:1;
}
.card{
border:5px solid black;
margin: 10px;
}
<div class="cards">
<div class='first-row'>
<div class='card' id="card1">
<img src="..." alt="Image" style="width: 100%">
<div class="card-container">
<h4 class="class-text"><b>...</b></h4>
<p></p>
</div>
</div>
<div class='card' id="card2">
<img src="..." alt="Image" style="width: 100%">
<div class="card-container">
<h4 class="class-text"><b>...</b></h4>
<p></p>
</div>
</div>
</div>
<div class='card' id="card3">
<img src="..." alt="Image" style="width: 100%">
<div class="card-container">
<h4 class="class-text"><b>...</b></h4>
<p></p>
</div>
</div>
</div>
The Answer is CSS Flex Box ;)
section {
max-width: 740px;
margin: 0 auto;
display: flex;
}
.column {
margin: 10px;
flex-grow: 1;
flex-shrink: 1;
flex-basis: 0;
}
section:nth-of-type(5) .column:first-of-type {
flex-grow: 2;
flex-shrink: 2;
flex-basis: 22px;
}
section:nth-of-type(6) .column:nth-of-type(2) {
flex-grow: 4;
flex-shrink: 4;
flex-basis: 66px;
}
/* OTHER STYLES */
html, body {
color: white;
height: 100%;
box-sizing: border-box;
}
body {
font-family: 'Raleway', sans-serif;
padding: 10px;
background: linear-gradient(135deg, #b04, #f80) fixed;
}
.column {
padding: 10px 0;
background-color: rgba(255, 0, 0, 0.25);
text-align: center;
border: 1px solid transparentize(white, 0.25);
background-color: transparentize(white, 0.8);
color: transparentize(white, 0.1);
}
<section>
<div class="column">One Third</div>
<div class="column">One Third</div>
<div class="column">One Third</div>
</section>
<section>
<div class="column">One Half</div>
<div class="column">One Half</div>
</section>
<section>
<div class="column">One Fourth</div>
<div class="column">One Fourth</div>
<div class="column">One Fourth</div>
<div class="column">One Fourth</div>
</section>
<section>
<div class="column">One Sixth</div>
<div class="column">One Sixth</div>
<div class="column">One Sixth</div>
<div class="column">One Sixth</div>
<div class="column">One Sixth</div>
<div class="column">One Sixth</div>
</section>
<section>
<div class="column">One Half</div>
<div class="column">One Fourth</div>
<div class="column">One Fourth</div>
</section>
<section>
<div class="column">One Sixth</div>
<div class="column">Two Thirds</div>
<div class="column">One Sixth</div>
</section>
.cards {
display: grid;
/* Make two tracks with the remaining space*/
grid-template-columns: 1fr 1fr;
grid-gap: 10px;
}
#card1,
#card2 {
background: #a03;
}
#card3 {
background: #be3;
/*Let card3 span 2 tracks*/
grid-column: span 2;
}
/*This will make the images span 100%*/
img {
max-width: 100%;
height: auto;
}
<div class="cards">
<div id="card1">
<img src="https://images.unsplash.com/photo-1440703281807-16ead562a596?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=f2b0cfa6c4950efda736ae4308c03420" alt="Image">
<div class="card-container">
<h4 class="class-text"><b>...</b></h4>
<p></p>
</div>
</div>
<div id="card2">
<img src="https://images.unsplash.com/photo-1440703281807-16ead562a596?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=f2b0cfa6c4950efda736ae4308c03420" alt="Image">
<div class="card-container">
<h4 class="class-text"><b>...</b></h4>
<p></p>
</div>
</div>
<div id="card3">
<img src="https://images.unsplash.com/photo-1440703281807-16ead562a596?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=f2b0cfa6c4950efda736ae4308c03420" alt="Image">
<div class="card-container">
<h4 class="class-text"><b>...</b></h4>
<p></p>
</div>
</div>
</div>
Related
This question already has answers here:
CSS-only masonry layout
(4 answers)
Closed 1 year ago.
I am trying to make a gallery that is uneven and staggered by using images and colored divs that are not the same size. I have the columns set to a min of 352px and to auto-fit the screen. So the container with grid looks something like this:
display: grid;
grid-template-columns: repeat(auto-fit, minmax(352px, 1fr));
grid-gap: 20px;
The issue I am having is the tallest picture sets the height of the row and the divs that have the smaller images follow the same height. Is there a way to tell the items in the row to not all be the same size? Or rather just target certain items in each row and tell them to be a specific height?
.grey {
background: #D9D9D9;
}
.tan {
background: #DCCEC8;
}
.light-brown {
background: #DC997D;
}
.brown {
background: #814A3D;
}
.black {
background: #000;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(352px, 1fr));
grid-gap: 20px;
}
.grid > div {
display: flex;
flex-direction: column;
align-items: center;
position: relative;
}
img {
max-width: 350px;
width: 350px;
}
.overlay {
position: absolute;
width: 350px;
height: 100%;
background: rgba(0, 0, 0, 0.05);
}
h4 {
text-transform: uppercase;
font-size: 26px;
color: #fff;
position: absolute;
z-index: 9;
}
h4:nth-child(2) {
bottom: 35px;
}
h4:nth-child(3) {
font-size: 18px;
margin: 5px 0;
bottom: 5px;
}
.fill {
max-width: 350px;
height: 100%;
width: 100%;
}
<div class='grid'>
<div>
<img class="thumbnail" src="https://picsum.photos/500/600" alt="person" />
<h4>Person One</h4>
<h4>#person1</h4>
<div class="overlay"></div>
</div>
<div><div class="tan fill"></div></div>
<div>
<img class="thumbnail" src="https://picsum.photos/300/220" alt="person" />
<h4>Person TWO</h4>
<h4>#person2</h4>
<div class="overlay"></div>
</div>
<div><div class="black fill"></div></div>
<div>
<img class="thumbnail" src="https://picsum.photos/700/700" alt="person" />
<h4>Person 3</h4>
<h4>#person3</h4>
<div class="overlay"></div>
</div>
<div>
<img class="thumbnail" src="https://picsum.photos/400/400" alt="person" />
<h4>Person four</h4>
<h4>#person4</h4>
<div class="overlay"></div>
</div>
<div>
<img class="thumbnail" src="https://picsum.photos/500/260" alt="person" />
<h4>Person Five</h4>
<h4>#pesron5</h4>
<div class="overlay"></div>
</div>
<div><div class="light-brown fill"></div></div>
<div><div class='brown fill'></div></div>
<div>
<img class="thumbnail" src="https://picsum.photos/600/220" alt="person" />
<h4>Person Six</h4>
<h4>#person6</h4>
<div class="overlay"></div>
</div>
<div><div class="black fill"></div></div>
<div>
<img class="thumbnail" src="https://picsum.photos/200/350" alt="person" />
<h4>Person Seven</h4>
<h4>#person7</h4>
<div class="overlay"></div>
</div>
<div>
<img class="thumbnail" src="https://picsum.photos/500/300" alt="person" />
<h4>Person Eight</h4>
<h4>#person8</h4>
<div class="overlay"></div>
</div>
<div><div class="tan fill"></div></div>
<div>
<img class="thumbnail" src="https://picsum.photos/250/250" alt="person" />
<h4>Person Nine</h4>
<h4>#Person9</h4>
<div class="overlay"></div>
</div>
<div>
<img class="thumbnail" src="https://picsum.photos/300/220" alt="person" />
<h4>Person Ten</h4>
<h4>#person10</h4>
<div class="overlay"></div>
</div>
</div>
Use height on the grid items. Moreover, the headings should be wrapped in a container and their default margins should be overwritten so that headings fit in container with image's height < 150px.
.grey {
background: #d9d9d9;
}
.tan {
background: #dccec8;
}
.light-brown {
background: #dc997d;
}
.brown {
background: #814a3d;
}
.black {
background: #000;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(352px, 1fr));
grid-gap: 20px;
}
.grid>div {
display: flex;
flex-direction: column;
align-items: center;
position: relative;
}
img {
max-width: 350px;
width: 350px;
}
.overlay {
position: absolute;
width: 350px;
height: fit-content;
background: rgba(0, 0, 0, 0.05);
bottom: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-content: center;
}
h4 {
text-transform: uppercase;
font-size: 26px;
color: #fff;
z-index: 9;
text-align: center;
margin: 0;
margin-bottom: 10px;
}
.fill {
max-width: 350px;
height: 100%;
width: 100%;
}
.grid-item {
height: fit-content;
height: -moz-fit-content;
}
<div class="grid">
<div class="grid-item">
<img class="thumbnail" src="https://picsum.photos/500/1000" alt="person" />
<div class="overlay">
<h4>Person One</h4>
<h4>#person1</h4>
</div>
</div>
<div>
<div class="tan fill"></div>
</div>
<div class="grid-item">
<img class="thumbnail" src="https://picsum.photos/1500/2000" alt="person" />
<div class="overlay">
<h4>Person TWO</h4>
<h4>#person2</h4>
</div>
</div>
<div>
<div class="black fill"></div>
</div>
<div class="grid-item">
<img class="thumbnail" src="https://picsum.photos/700/1500" alt="person" />
<div class="overlay">
<h4>Person 3</h4>
<h4>#person3</h4>
</div>
</div>
<div class="grid-item">
<img class="thumbnail" src="https://picsum.photos/400/100" alt="person" />
<div class="overlay">
<h4>Person four</h4>
<h4>#person4</h4>
</div>
</div>
<div class="grid-item">
<img class="thumbnail" src="https://picsum.photos/500/200" alt="person" />
<div class="overlay">
<h4>Person Five</h4>
<h4>#pesron5</h4>
</div>
</div>
<div>
<div class="light-brown fill"></div>
</div>
<div>
<div class="brown fill"></div>
</div>
<div class="grid-item">
<img class="thumbnail" src="https://picsum.photos/600/220" alt="person" />
<div class="overlay">
<h4>Person Six</h4>
<h4>#person6</h4>
</div>
</div>
<div>
<div class="black fill"></div>
</div>
<div class="grid-item">
<img class="thumbnail" src="https://picsum.photos/200/150" alt="person" />
<div class="overlay">
<h4>Person Seven</h4>
<h4>#person7</h4>
</div>
</div>
<div class="grid-item">
<img class="thumbnail" src="https://picsum.photos/500/300" alt="person" />
<div class="overlay">
<h4>Person Eight</h4>
<h4>#person8</h4>
</div>
</div>
<div>
<div class="tan fill"></div>
</div>
<div class="grid-item">
<img class="thumbnail" src="https://picsum.photos/250/250" alt="person" />
<div class="overlay">
<h4>Person Nine</h4>
<h4>#Person9</h4>
</div>
</div>
<div class="grid-item">
<img class="thumbnail" src="https://picsum.photos/300/220" alt="person" />
<div class="overlay">
<h4>Person Ten</h4>
<h4>#person10</h4>
</div>
</div>
</div>
I am trying to style a page that shows a list of uploaded photos.
The requirements are (applied in this order in case of ambiguity):
The photos must be in a grid
There must be 3 columns
A photo that is too wide must shrink to the column width
A photo that is too narrow must grow to the column width
A photo that is shorter than it is wide is left as it is
A photo that is taller than it is wide is truncated (overflow hidden)
I can do all of the above except for the last one.
I tried the trick with padding-top: 100% but all that seemed to do was make everything twice as tall.
So how can I hide the overflow on a cell with defined width and aspect ratio?
.container {
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
}
.box {
margin: 1rem;
width: calc((100% - 1rem * 6) / 3);
}
.box img {
width: 100%;
}
.green {
background-color: green;
}
.red {
background-color: red;
}
<div class="container">
<div class="box green">
<img src="https://dummyimage.com/200x200/000/fff">
</div>
<div class="box green">
<img src="https://dummyimage.com/100x100/000/fff">
</div>
<div class="box green">
<img src="https://dummyimage.com/200x200/000/fff">
</div>
<div class="box green">
<img src="https://dummyimage.com/200x200/000/fff">
</div>
<div class="box green">
<img src="https://dummyimage.com/300x200/000/fff">
</div>
<div class="box green">
<img src="https://dummyimage.com/200x200/000/fff">
</div>
<div class="box red">
<img src="https://dummyimage.com/200x200/000/fff">
</div>
<div class="box red">
<img src="https://dummyimage.com/200x300/000/fff">
</div>
<div class="box red">
<img src="https://dummyimage.com/200x200/000/fff">
</div>
</div>
Woops ok so I tried the padding-top: 100% top trick again and this time it worked.
You cannot apply it to the children of the flex container (i.e. the .box) directly, you must have another box inside it like this:
.container {
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
}
.box {
margin: 1rem;
width: calc((100% - 1rem * 6) / 3);
}
.box img {
width: 100%;
}
.green {
background-color: green;
}
.red {
background-color: red;
}
.aspect-ratio-box {
height: 0;
overflow: hidden;
padding-top: 100%;
position: relative;
}
.aspect-ratio-box-inside {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
<div class="container">
<div class="box green">
<div class="aspect-ratio-box">
<div class="aspect-ratio-box-inside">
<img src="https://dummyimage.com/200x200/000/fff">
</div>
</div>
</div>
<div class="box green">
<div class="aspect-ratio-box">
<div class="aspect-ratio-box-inside">
<img src="https://dummyimage.com/100x100/000/fff">
</div>
</div>
</div>
<div class="box green">
<div class="aspect-ratio-box">
<div class="aspect-ratio-box-inside">
<img src="https://dummyimage.com/200x200/000/fff">
</div>
</div>
</div>
<div class="box green">
<div class="aspect-ratio-box">
<div class="aspect-ratio-box-inside">
<img src="https://dummyimage.com/200x200/000/fff">
</div>
</div>
</div>
<div class="box green">
<div class="aspect-ratio-box">
<div class="aspect-ratio-box-inside">
<img src="https://dummyimage.com/300x200/000/fff">
</div>
</div>
</div>
<div class="box green">
<div class="aspect-ratio-box">
<div class="aspect-ratio-box-inside">
<img src="https://dummyimage.com/200x200/000/fff">
</div>
</div>
</div>
<div class="box red">
<div class="aspect-ratio-box">
<div class="aspect-ratio-box-inside">
<img src="https://dummyimage.com/200x200/000/fff">
</div>
</div>
</div>
<div class="box red">
<div class="aspect-ratio-box">
<div class="aspect-ratio-box-inside">
<img src="https://dummyimage.com/200x300/000/fff">
</div>
</div>
</div>
<div class="box red">
<div class="aspect-ratio-box">
<div class="aspect-ratio-box-inside">
<img src="https://dummyimage.com/200x200/000/fff">
</div>
</div>
</div>
</div>
It also fixed that weird extra bit that was showing at the bottom.
I have problem in vertical space between Up and down portfolio row.
I have some unwanted space in rows
It's not margin or padding in box, i think this problem is for img tag
Can anyone help me?
.portfolio.row {
display: flex;
}
.col-4 {
flex: 33.33%;
}
.portfolio > div img {
width: 100%;
}
<div class="portfolio row">
<div class="col-4" id="coffe">
<img src="https://cdn.pixabay.com/photo/2019/05/07/16/19/strawberry-4186310_960_720.jpg" alt="Nature1">
</div>
<div class="col-4" id="coffe">
<img src="https://cdn.pixabay.com/photo/2019/05/07/16/19/strawberry-4186310_960_720.jpg" alt="Nature2">
</div>
<div class="col-4" id="coffe">
<img src="https://cdn.pixabay.com/photo/2019/05/07/16/19/strawberry-4186310_960_720.jpg" alt="Nature3">
</div>
</div>
<div class="portfolio row">
<div class="col-4" id="work">
<img src="https://cdn.pixabay.com/photo/2019/05/07/16/19/strawberry-4186310_960_720.jpg" alt="Nature1">
</div>
<div class="col-4" id="work">
<img src="https://cdn.pixabay.com/photo/2019/05/07/16/19/strawberry-4186310_960_720.jpg" alt="Nature2">
</div>
<div class="col-4" id="work">
<img src="https://cdn.pixabay.com/photo/2019/05/07/16/19/strawberry-4186310_960_720.jpg" alt="Nature3">
</div>
</div>
My guess is that it's trying to keep the aspect ratio of the images. If you add height: 100% it does work:
.portfolio.row {
display: flex;
}
.col-4 {
flex: 33.33%;
}
.portfolio > div img {
width: 100%;
height: 100%;
}
<div class="portfolio row">
<div class="col-4" id="coffe">
<img src="https://cdn.pixabay.com/photo/2019/05/07/16/19/strawberry-4186310_960_720.jpg" alt="Nature1">
</div>
<div class="col-4" id="coffe">
<img src="https://cdn.pixabay.com/photo/2019/05/07/16/19/strawberry-4186310_960_720.jpg" alt="Nature2">
</div>
<div class="col-4" id="coffe">
<img src="https://cdn.pixabay.com/photo/2019/05/07/16/19/strawberry-4186310_960_720.jpg" alt="Nature3">
</div>
</div>
<div class="portfolio row">
<div class="col-4" id="work">
<img src="https://cdn.pixabay.com/photo/2019/05/07/16/19/strawberry-4186310_960_720.jpg" alt="Nature1">
</div>
<div class="col-4" id="work">
<img src="https://cdn.pixabay.com/photo/2019/05/07/16/19/strawberry-4186310_960_720.jpg" alt="Nature2">
</div>
<div class="col-4" id="work">
<img src="https://cdn.pixabay.com/photo/2019/05/07/16/19/strawberry-4186310_960_720.jpg" alt="Nature3">
</div>
</div>
Just use the following code and it will be fixed! height: 100%; will solve your problem. here is example
.portfolio>div img {
width: 100%;
height: 100%; /* Add this extar value */
}
how does the audio and the last avatar got in the center? I want the last avatar to be in the center and under it is the audio that was also in the center,
please help me thank you guys i just try in after the of the last avatar picture the audio progress didn't get at the center please help guys thanks a lot this is just for learning new things
and how does the last avatar picture got in the center i tried again the but it didn't work thanks guys
img {
border-radius: 50%;
}
table, th, td {
border: 10px solid black;
}
.container {
position: relative;
width: 20%;
float: left;
}
.image {
opacity: 1;
display: absolute;
width: 50%;
height: auto;
transition: .5s ease;
backface-visibility: hidden;
}
.middle {
transition: .5s ease;
opacity: 0;
position: absolute;
top: 50%;
left: 3%;
transform: translate(17%, -20%);
-ms-transform: translate(50%, 50%);
text-align: center;
}
.container:hover .image {
opacity: 0.5;
}
.container:hover .middle {
opacity: 1;
}
.text {
background-color: #dbe0dc;
color: black;
font-size: 16px;
padding: 10px 20px;
}
.column {
float: left;
width: 33.33%;
padding: 5px;
}
}
<div class="container">
<img src="https://images.vexels.com/media/users/3/145908/preview2/52eabf633ca6414e60a7677b0b917d92-male-avatar-maker.jpg" class="image" alt="Avatar" style="width:200px">
<div class="middle">
<div class="text">sample 1</div>
</div>
</div> <br>
<div class="container">
<img src="https://images.vexels.com/media/users/3/145908/preview2/52eabf633ca6414e60a7677b0b917d92-male-avatar-maker.jpg" class="image" alt="Avatar" style="width:200px">
<div class="middle">
<div class="text">sample 2</div>
</div></div>
<div class="container">
<img src="https://images.vexels.com/media/users/3/145908/preview2/52eabf633ca6414e60a7677b0b917d92-male-avatar-maker.jpg" class="image" alt="Avatar" style="width:200px">
<div class="middle">
<div class="text">sample 3</div>
</div></div>
<div class="container">
<img src="https://images.vexels.com/media/users/3/145908/preview2/52eabf633ca6414e60a7677b0b917d92-male-avatar-maker.jpg" class="image" alt="Avatar" style="width:200px">
<div class="middle">
<div class="text">sample 4</div>
</div></div>
<div class="container">
<img src="https://images.vexels.com/media/users/3/145908/preview2/52eabf633ca6414e60a7677b0b917d92-male-avatar-maker.jpg" class="image" alt="Avatar" style="width:200px">
<div class="middle">
<div class="text">sample 5</div>
</div></div>
<div class="container">
<img src="https://images.vexels.com/media/users/3/145908/preview2/52eabf633ca6414e60a7677b0b917d92-male-avatar-maker.jpg" class="image" alt="Avatar" style="width:200px">
<div class="middle">
<div class="text">sample 6</div>
</div></div>
<div class="container">
<img src="https://images.vexels.com/media/users/3/145908/preview2/52eabf633ca6414e60a7677b0b917d92-male-avatar-maker.jpg" class="image" alt="Avatar" style="width:200px">
<div class="middle">
<div class="text">sample 7</div>
</div></div>
<div class="container">
<img src="https://images.vexels.com/media/users/3/145908/preview2/52eabf633ca6414e60a7677b0b917d92-male-avatar-maker.jpg" class="image" alt="Avatar" style="width:200px">
<div class="middle">
<div class="text">sample 8</div>
</div></div>
<div class="container">
<img src="https://images.vexels.com/media/users/3/145908/preview2/52eabf633ca6414e60a7677b0b917d92-male-avatar-maker.jpg" class="image" alt="Avatar" style="width:200px">
<div class="middle">
<div class="text">sample 9</div>
</div></div>
<div class="container">
<img src="https://images.vexels.com/media/users/3/145908/preview2/52eabf633ca6414e60a7677b0b917d92-male-avatar-maker.jpg" class="image" alt="Avatar" style="width:200px">
<div class="middle">
<div class="text">sample 10</div>
</div></div>
<div class="container">
<img src="https://images.vexels.com/media/users/3/145908/preview2/52eabf633ca6414e60a7677b0b917d92-male-avatar-maker.jpg" class="image" alt="Avatar" style="width:200px">
<div class="middle">
<div class="text">sample 11</div>
</div></div>
</center>
<center>
<br><br><br><br><br><br>
<div id="wrapper">
<audio id="mytrack" controls>
<source src="sample audio.com" type="audio/mp3">
</audio>
<nav>
<div id="defaultBar">
<div id="progressBar"></div>
</div>
</center>
I tried to make as few changes as possible. Here is a quick fix to your problem. Separate the last image along with the audio div from other images. You don't need to use center tag you can center a element with margin: auto.
img {
border-radius: 50%;
}
table,
th,
td {
border: 10px solid black;
}
.container {
position: relative;
width: 20%;
float: left;
}
.image {
opacity: 1;
width: 50%;
height: auto;
transition: .5s ease;
backface-visibility: hidden;
}
.middle {
transition: .5s ease;
opacity: 0;
position: absolute;
top: 50%;
left: 3%;
transform: translate(17%, -20%);
-ms-transform: translate(50%, 50%);
text-align: center;
}
.last {
float: none;
margin: auto;
}
.container:hover>.image {
opacity: 0.5;
}
.container:hover>.middle {
opacity: 1;
}
.text {
background-color: #dbe0dc;
color: black;
font-size: 16px;
padding: 10px 20px;
}
.column {
float: left;
width: 33.33%;
padding: 5px;
}
.rows {
display: inline-block;
}
<div class="rows">
<div class="container">
<img src="https://images.vexels.com/media/users/3/145908/preview2/52eabf633ca6414e60a7677b0b917d92-male-avatar-maker.jpg"
class="image" alt="Avatar" style="width:200px">
<div class="middle">
<div class="text">sample 1</div>
</div>
</div> <br>
<div class="container">
<img src="https://images.vexels.com/media/users/3/145908/preview2/52eabf633ca6414e60a7677b0b917d92-male-avatar-maker.jpg"
class="image" alt="Avatar" style="width:200px">
<div class="middle">
<div class="text">sample 2</div>
</div>
</div>
<div class="container">
<img src="https://images.vexels.com/media/users/3/145908/preview2/52eabf633ca6414e60a7677b0b917d92-male-avatar-maker.jpg"
class="image" alt="Avatar" style="width:200px">
<div class="middle">
<div class="text">sample 3</div>
</div>
</div>
<div class="container">
<img src="https://images.vexels.com/media/users/3/145908/preview2/52eabf633ca6414e60a7677b0b917d92-male-avatar-maker.jpg"
class="image" alt="Avatar" style="width:200px">
<div class="middle">
<div class="text">sample 4</div>
</div>
</div>
<div class="container">
<img src="https://images.vexels.com/media/users/3/145908/preview2/52eabf633ca6414e60a7677b0b917d92-male-avatar-maker.jpg"
class="image" alt="Avatar" style="width:200px">
<div class="middle">
<div class="text">sample 5</div>
</div>
</div>
<div class="container">
<img src="https://images.vexels.com/media/users/3/145908/preview2/52eabf633ca6414e60a7677b0b917d92-male-avatar-maker.jpg"
class="image" alt="Avatar" style="width:200px">
<div class="middle">
<div class="text">sample 6</div>
</div>
</div>
<div class="container">
<img src="https://images.vexels.com/media/users/3/145908/preview2/52eabf633ca6414e60a7677b0b917d92-male-avatar-maker.jpg"
class="image" alt="Avatar" style="width:200px">
<div class="middle">
<div class="text">sample 7</div>
</div>
</div>
<div class="container">
<img src="https://images.vexels.com/media/users/3/145908/preview2/52eabf633ca6414e60a7677b0b917d92-male-avatar-maker.jpg"
class="image" alt="Avatar" style="width:200px">
<div class="middle">
<div class="text">sample 8</div>
</div>
</div>
<div class="container">
<img src="https://images.vexels.com/media/users/3/145908/preview2/52eabf633ca6414e60a7677b0b917d92-male-avatar-maker.jpg"
class="image" alt="Avatar" style="width:200px">
<div class="middle">
<div class="text">sample 9</div>
</div>
</div>
<div class="container">
<img src="https://images.vexels.com/media/users/3/145908/preview2/52eabf633ca6414e60a7677b0b917d92-male-avatar-maker.jpg"
class="image" alt="Avatar" style="width:200px">
<div class="middle">
<div class="text">sample 10</div>
</div>
</div>
</div>
<div>
<div class="last container">
<img src="https://images.vexels.com/media/users/3/145908/preview2/52eabf633ca6414e60a7677b0b917d92-male-avatar-maker.jpg"
class="image" alt="Avatar" style="width:200px">
<div class="middle">
<div class="text">sample 11</div>
</div>
</div>
<div id="wrapper" class="last container">
<audio id="mytrack" controls style="width: 200px">
<source src="sample audio.com" type="audio/mp3">
</audio>
<nav>
<div id="defaultBar">
<div id="progressBar"></div>
</div>
</div>
</div>
I have a layout like this:
body {
text-align: center;
}
.link {
position: relative;
}
.info {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
position: absolute;
top: 0;
text-align: center;
width: 100%;
height: 100%;
background-color: #263238;
color: #1DE9B6;
opacity: 0;
visibility: hidden;
}
.link:hover .info {
opacity: 1;
visibility: visible;
}
.col-md-3 {
margin-bottom: 30px;
}
<div class="container">
<div class="row">
<div class="col-md-3">
<div class="link">
<img class="img-fluid" src="http://image.tmdb.org/t/p/w300/c9XxwwhPHdaImA2f1WEfEsbhaFB.jpg" alt="img">
<div class="info">Info</div>
</div>
</div>
<div class="col-md-3">
<div class="link">
<img class="img-fluid" src="http://image.tmdb.org/t/p/w300/c9XxwwhPHdaImA2f1WEfEsbhaFB.jpg" alt="img">
<div class="info">Info</div>
</div>
</div>
<div class="col-md-3">
<div class="link">
<img class="img-fluid" src="http://image.tmdb.org/t/p/w300/c9XxwwhPHdaImA2f1WEfEsbhaFB.jpg" alt="img">
<div class="info">Info</div>
</div>
</div>
<div class="col-md-3">
<div class="link">
<img class="img-fluid" src="http://image.tmdb.org/t/p/w300/c9XxwwhPHdaImA2f1WEfEsbhaFB.jpg" alt="img">
<div class="info">Info</div>
</div>
</div>
<div class="col-md-3">
<div class="link">
<img class="img-fluid" src="http://image.tmdb.org/t/p/w300/c9XxwwhPHdaImA2f1WEfEsbhaFB.jpg" alt="img">
<div class="info">Info</div>
</div>
</div>
<div class="col-md-3">
<div class="link">
<img class="img-fluid" src="http://image.tmdb.org/t/p/w300/c9XxwwhPHdaImA2f1WEfEsbhaFB.jpg" alt="img">
<div class="info">Info</div>
</div>
</div>
<div class="col-md-3">
<div class="link">
<img class="img-fluid" src="http://image.tmdb.org/t/p/w300/c9XxwwhPHdaImA2f1WEfEsbhaFB.jpg" alt="img">
<div class="info">Info</div>
</div>
</div>
<div class="col-md-3">
<div class="link">
<img class="img-fluid" src="http://image.tmdb.org/t/p/w300/c9XxwwhPHdaImA2f1WEfEsbhaFB.jpg" alt="img">
<div class="info">Info</div>
</div>
</div>
</div>
</div>
When the layout gets small, and only one column is displayed horizontally, the div which is supposed to show on hover gets as big as the column, but I only want it to be as big as the fluid image. How would I need to achieve this?
Here is the codepen link: https://codepen.io/Kestvir/pen/gKVwLe
Just add display: inline-block to the link element
.link {
position: relative;
display: inline-block;
}
Or you can also add d-inline-block position-relative classes on the .link elements .
body {
text-align: center;
}
.link {
position: relative;
display: inline-block;
}
.info {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
position: absolute;
top: 0;
text-align: center;
width: 100%;
height: 100%;
background-color: #263238;
color: #1DE9B6;
opacity: 0;
visibility: hidden;
}
.link:hover .info {
opacity: 1;
visibility: visible;
}
.col-md-3 {
margin-bottom: 30px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-md-3">
<div class="link">
<img class="img-fluid" src="http://image.tmdb.org/t/p/w300/c9XxwwhPHdaImA2f1WEfEsbhaFB.jpg" alt="img">
<div class="info">Info</div>
</div>
</div>
<div class="col-md-3">
<div class="link">
<img class="img-fluid" src="http://image.tmdb.org/t/p/w300/c9XxwwhPHdaImA2f1WEfEsbhaFB.jpg" alt="img">
<div class="info">Info</div>
</div>
</div>
<div class="col-md-3">
<div class="link">
<img class="img-fluid" src="http://image.tmdb.org/t/p/w300/c9XxwwhPHdaImA2f1WEfEsbhaFB.jpg" alt="img">
<div class="info">Info</div>
</div>
</div>
<div class="col-md-3">
<div class="link">
<img class="img-fluid" src="http://image.tmdb.org/t/p/w300/c9XxwwhPHdaImA2f1WEfEsbhaFB.jpg" alt="img">
<div class="info">Info</div>
</div>
</div>
<div class="col-md-3">
<div class="link">
<img class="img-fluid" src="http://image.tmdb.org/t/p/w300/c9XxwwhPHdaImA2f1WEfEsbhaFB.jpg" alt="img">
<div class="info">Info</div>
</div>
</div>
<div class="col-md-3">
<div class="link">
<img class="img-fluid" src="http://image.tmdb.org/t/p/w300/c9XxwwhPHdaImA2f1WEfEsbhaFB.jpg" alt="img">
<div class="info">Info</div>
</div>
</div>
<div class="col-md-3">
<div class="link">
<img class="img-fluid" src="http://image.tmdb.org/t/p/w300/c9XxwwhPHdaImA2f1WEfEsbhaFB.jpg" alt="img">
<div class="info">Info</div>
</div>
</div>
<div class="col-md-3">
<div class="link">
<img class="img-fluid" src="http://image.tmdb.org/t/p/w300/c9XxwwhPHdaImA2f1WEfEsbhaFB.jpg" alt="img">
<div class="info">Info</div>
</div>
</div>
</div>
</div>