admin 管理员组文章数量: 1086019
I have Created four cards in a same line in my html page.But when I resize(decrease window size) my window, the cards which are in right corner are going down.they don't stay in a line.How can I keep my all cards in a same line even if I resize my window?
<div class="tab1cards">
<div class="card">
<img src="safari.jpg" alt="safari" style="width: 250px;">
<h4><b>Wild Life</b></h4>
</div>
<div class="card">
<img src="safari.jpg" alt="safari" style="width: 250px">
<h4><b>Heritage</b></h4>
</div>
<div class="card">
<img src="safari.jpg" alt="safari" style="width: 250px">
<h4><b>Beach</b></h4>
</div>
<div class="card">
<img src="safari.jpg" alt="safari" style="width: 250px">
<h4><b>Sri lanka</b></h4>
</div>
</div>
this is style sheet
.card{
float: left;
padding: 16px;
text-align: center;
}
I have Created four cards in a same line in my html page.But when I resize(decrease window size) my window, the cards which are in right corner are going down.they don't stay in a line.How can I keep my all cards in a same line even if I resize my window?
<div class="tab1cards">
<div class="card">
<img src="safari.jpg" alt="safari" style="width: 250px;">
<h4><b>Wild Life</b></h4>
</div>
<div class="card">
<img src="safari.jpg" alt="safari" style="width: 250px">
<h4><b>Heritage</b></h4>
</div>
<div class="card">
<img src="safari.jpg" alt="safari" style="width: 250px">
<h4><b>Beach</b></h4>
</div>
<div class="card">
<img src="safari.jpg" alt="safari" style="width: 250px">
<h4><b>Sri lanka</b></h4>
</div>
</div>
this is style sheet
.card{
float: left;
padding: 16px;
text-align: center;
}
Share
Improve this question
asked Mar 6, 2020 at 5:05
Jeewantha LahiruJeewantha Lahiru
4042 gold badges5 silver badges19 bronze badges
3
- use flex and flex direction – Bhavya Singh Commented Mar 6, 2020 at 5:07
- @BhavyaSingh it worked.thank you – Jeewantha Lahiru Commented Mar 6, 2020 at 5:09
- Kindly mark the answer as accepted – Bhavya Singh Commented Mar 6, 2020 at 5:11
2 Answers
Reset to default 6
.card {
padding: 16px;
text-align: center;
}
.tab1cards {
display: flex;
flex-direction: row;
}
<div class="tab1cards">
<div class="card">
<img src="safari.jpg" alt="safari" style="width: 250px;">
<h4><b>Wild Life</b></h4>
</div>
<div class="card">
<img src="safari.jpg" alt="safari" style="width: 250px">
<h4><b>Heritage</b></h4>
</div>
<div class="card">
<img src="safari.jpg" alt="safari" style="width: 250px">
<h4><b>Beach</b></h4>
</div>
<div class="card">
<img src="safari.jpg" alt="safari" style="width: 250px">
<h4><b>Sri lanka</b></h4>
</div>
</div>
This code will solve the problem and align them into a single row.
You can use flex like this. Here is working example https://jsfiddle/fyckzuhL/
.tab1cards{
display:flex;
flex-direction:row;
justify-content:space-between;
}
本文标签: javascriptHow to keep many image cards in a same line in HTML CSSStack Overflow
版权声明:本文标题:javascript - How to keep many image cards in a same line in HTML , CSS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744007211a2517504.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论