gpt4 book ai didi

html - 屏幕每个 Angular 落的4张图片html css

转载 作者:太空宇宙 更新时间:2023-11-03 21:16:36 25 4
gpt4 key购买 nike

我试图在屏幕的每个 Angular 落放置 4 张小图片。我想要这样的东西:

如何使用 HTML 和 CSS 实现这一点?

以下代码显示一张图片,其中应该有 4 个 child 。

div.img {
border: 1px solid #ccc;
}
div.img:hover {
border: 1px solid #777;
}
div.desc {
padding: 15px;
text-align: center;
}
* {
box-sizing: border-box;
}
.responsive {
padding: 0 6px;
float: left;
width: 24.99999%;
}
@media only screen and (max-width: 5000px) {
.responsive {
width: 49.99999%;
margin: 6px 0;
}
}
.clearfix:after {
content: "";
display: table;
clear: both;
}
<div class="responsive">
<div class="img">
<img src="animals/cat.jpg" alt="Trolltunga Norway" width="600" height="400">
<div class="desc">Add a description of the image here</div>
</div>
</div>
<div class="responsive">
<div class="img">
<a target="_blank" href="animals/dog.jpg">
<img src="animals/dog.jpg" alt="Forest" width="600" height="400">
</a>
<div class="desc">Add a description of the image here</div>
</div>
</div>
<div class="responsive">
<div class="img">
<a target="_blank" href="animals/monkey.jpg">
<img src="animals/monkey.jpg" alt="Northern Lights" width="600" height="400">
</a>
<div class="desc">Add a description of the image here</div>
</div>
</div>
<div class="responsive">
<div class="img">
<a target="_blank" href="animals/fox.jpg">
<img src="animals/fox.jpg" alt="Mountains" width="600" height="400">
</a>
<div class="desc">Add a description of the image here</div>
</div>
</div>
<div class="clearfix"></div>

最佳答案

您可以使用 flexmargin(auto)、order 和一个伪元素来拆分这四个元素来构建您的基本布局。

下面的示例将四个盒子放在四个 Angular 上,它们可以填充任何东西和内容样式。

body {
display:flex;
flex-flow:row wrap;
margin:0;
height:100vh;
}
/* body:after
actually your code gives a container for this */
.clearfix {
/*content:'';
display:block;*/
width:100%;
order:1;
}
.responsive {
border:solid;
margin:0;
}
.responsive:nth-child(1) {
margin-bottom:auto;
margin-right:auto;
order:0;
}
.responsive:nth-child(2) {
margin-bottom:auto;
margin-left:auto;
order:0;
}

.responsive:nth-child(3) {
margin-top:auto;
margin-right:auto;
order:2;
}
.responsive:nth-child(4) {
margin-top:auto;
margin-left:auto;
order:2;
}
<div class="responsive">
<div class="img">
<img src="animals/cat.jpg" alt="Trolltunga Norway" width="600" height="400">
<div class="desc">Add a description of the image here</div>
</div>
</div>
<div class="responsive">
<div class="img">
<a target="_blank" href="animals/dog.jpg">
<img src="animals/dog.jpg" alt="Forest" width="600" height="400">
</a>
<div class="desc">Add a description of the image here</div>
</div>
</div>
<div class="responsive">
<div class="img">
<a target="_blank" href="animals/monkey.jpg">
<img src="animals/monkey.jpg" alt="Northern Lights" width="600" height="400">
</a>
<div class="desc">Add a description of the image here</div>
</div>
</div>
<div class="responsive">
<div class="img">
<a target="_blank" href="animals/fox.jpg">
<img src="animals/fox.jpg" alt="Mountains" width="600" height="400">
</a>
<div class="desc">Add a description of the image here</div>
</div>
</div>
<div class="clearfix"></div>

关于html - 屏幕每个 Angular 落的4张图片html css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41596783/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com