[英]Align Images Side By Side with hover
<div align="center">
<div class="container2">
<a href="D:/Games/CIC/MFWS/discussion.html"><img src="img/3.png" alt="discussion Threads" class="image" height="200px" width="150px"></a>
<div class="overlay">
<div class="text">Here you can discuss different topics and ask or answer questions.</div>
</div>
</div>
<div class="container2">
<img src="download.png" alt="Avatar" class="image">
<div class="overlay overlay2">
<div class="text">Bottom</div>
</div>
</div>
<div class="container2">
<img src="download.png" alt="Avatar" class="image">
<div class="overlay overlay3">
<div class="text">Bottom</div>
</div>
</div>
</div>
i want to make the images next to each other but i can't idk why or how tbh and this is the css i have tried everything it doesn't work I want 3 images side by side with hover and caption, at the moment I have 3 images going from top to bottom, the hover is good but not side by side.我想让图像彼此相邻,但我不知道为什么或如何 tbh,这是 css 我已经尝试了一切它不起作用我想要 3 个图像并排并带有悬停和标题,此刻我有 3 张图像从上到下,悬停很好,但不能并排。 How do I make the images appear side by side?如何让图像并排显示? Thanks.谢谢。
.container2 {
position: relative;
width: 250px;
}
.image {
display: block;
width: 250px;
height: 300px;
height: auto;
margin: 17%;
border-top-left-radius: 30px;
border-top-right-radius: 30px;
}
.overlay {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-color: #4CAF50;
overflow: hidden;
width: 100%;
height: 0;
transition: .5s ease;
margin-left: 17%;
border-top-left-radius: 70px;
border-top-right-radius: 70px;
pointer-events: none
}
.container2:hover .overlay {
height: 85%;
}
.text {
color: white;
font-size: 15px;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
}
.overlay2 {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-color: #4CAF50;
overflow: hidden;
width: 100%;
height: 0;
transition: .5s ease;
margin-left: 17%;
border-top-left-radius: 70px;
border-top-right-radius: 70px;
pointer-events: none
}
.container2:hover .overlay2 {
height: 85%;
}
.overlay3 {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-color: #4CAF50;
overflow: hidden;
width: 100%;
height: 0;
transition: .5s ease;
margin-left: 17%;
border-top-left-radius: 70px;
border-top-right-radius: 70px;
pointer-events: none
}
.container2:hover .overlay3 {
height: 85%;
}
You would have to add float
property to your container2
selector.您必须将float
属性添加到您的container2
选择器。 Please check the css rule below.请检查下面的css规则。
.container2 {
float: left;
position: relative;
width: 250px;
}
.container { width: 400px; height: 400px; padding: 0px; display: grid; grid-template-columns: auto auto auto; } .item { width: 100px; height: 200px; margin: 2px; }
<div class="container"> <div class="item" style="background-color:red"> </div> <div class="item" style="background-color:blue"> </div> <div class="item" style="background-color:yellow"> </div> </div>
Why don't you grid-display property ?为什么不使用 grid-display 属性?
For these such scenarios there is a beautiful/clean/simple concept called flex
which is helping by decreasing number of lines of code:对于这些场景,有一个漂亮/干净/简单的概念叫做flex
,它有助于减少代码行数:
here is the example with column
, color
and hover
effect, hope it helps you:这是带有column
、 color
和hover
效果的示例,希望对您有所帮助:
#MainDiv { height: 200px; width: 650px; display: flex; /* here is a concept */ flex-direction: row; /* you can either change it to row/columns */ padding: 5px; } #firstDiv { width: 200px; margin: 5px; background-color: red; } #secondDiv { width: 200px; margin: 5px; background-color: blue; } #thirdDiv { width: 200px; margin: 5px; background-color: green; } #firstDiv:hover { background-color: blue; color: white; } #secondDiv:hover { background-color: green; color: white; } #thirdDiv:hover { background-color: red; color: white; }
<div id="MainDiv"> <div id="firstDiv">First Div</div> <div id="secondDiv">Second Div</div> <div id="thirdDiv">Third Div</div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.