gpt4 book ai didi

html - 使文本占用与网格中的图片一样多的空间

转载 作者:行者123 更新时间:2023-11-27 23:19:42 24 4
gpt4 key购买 nike

我正在做一个学校元素,我应该在那里做一个作品集。我正在尝试在该图片旁边制作一个带有图片和信息的网格,其中包含我所从事的工作。我想让文本框和图片一样大。我试过使用 flexbox 和很多其他东西,但无法让它工作。有没有人可以帮助我?

*{
box-sizing: border-box;
}

body{
background-color: #f4f4f4;
padding: 20px;
font-family: Arial;
}


.container {
max-width: 1600px;
margin: 0 auto;
}

.row {
margin:8px-16px;
}

.row,
.row > .column {
padding:2px 0px;
}

.column {
float:left;
width:50%;
}

.row:after {
content:"";
display:table;
clear:both;
}

.content {
background-color: white;
padding: 10px;
}

/* Responsive layout - makes the two columns stack on top of each other instead of next to each other */
@media screen and (max-width: 600px) {
.column {
width:100%;
}
}
<div class="container">
<div class="row">
<div class="column">
<div class="content">
<h3>Hemsida 1</h3>
<p>Lorem ipsum.</p>
</div>
</div>
<div class="column">
<div class="content">
<img src="atleta1.jpg" style="width:100%">
</div>
</div>
</div>
<div class="row">
<div class="column">
<div class="content">
<img src="atleta1.jpg" style="width:100%">´
</div>
</div>
<div class="column">
<div class="content">
<h3>Hemsida 2</h3>
<p>Lorem ipsum.</p>
</div>
</div>
</div>
<div class="row">
<div class="column">
<div class="content">
<h3>Hemsida 2</h3>
<p>Lorem ipsum.</p>
</div>
</div>
<div class="column">
<div class="content">
<img src="atleta1.jpg" style="width:100%">
</div>
</div>
</div>
</div>

最佳答案

您的布局非常复杂。您喜欢这个布局选项吗?

每行分为两部分,各占50%。

一个小小的好处:对于小屏幕,由于 Flexbox 属性 order,描述 block 位于图片上方。

附言当然,这不是最终选择。你可以继续改进它

结果

* {
box-sizing: border-box;
}

body {
background-color: #f4f4f4;
padding: 20px;
font-family: Arial;
}

.container {
max-width: 1600px;
margin: 0 auto;
padding: 0;
list-style: none;
}

.item {
display: flex;
justify-content: space-between;
margin-bottom: 20px;
;
padding: 10px;
background-color: white;
}

.item__desc {
flex-basis: 50%;
}

.item__pic {
flex-basis: 50%;
}

.item_img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
}


/* Responsive layout - makes the two columns stack on top of each other instead of next to each other */

@media screen and (max-width: 600px) {
.item {
flex-direction: column;
width: 100%;
}
.item__desc {
order: -1;
}
}
<ul class="container">
<li class="item">
<div class="item__desc">
<h3>Hemsida 1</h3>
<p>Lorem ipsum.</p>
</div>
<div class="item__pic">
<img class="item_img" src="https://picsum.photos/536/354"></div>
</li>
<li class="item">
<div class="item__pic">
<img class="item_img" src="https://picsum.photos/536/354">
</div>
<div class="item__desc">
<h3>Hemsida 2</h3>
<p>Lorem ipsum.</p>
</div>
</li>
<li class="item">
<div class="item__desc">
<h3>Hemsida 2</h3>
<p>Lorem ipsum.</p>
</div>
<div class="item__pic">
<img class="item_img" src="https://picsum.photos/536/354"></div>
</li>
</ul>

CodePen 上的代码相同

enter image description here

关于html - 使文本占用与网格中的图片一样多的空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58081652/

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