html - 在 div 中放置一张照片,将其父亲的其余部分
问题描述
我想要这样的东西:
**************************************************************************
* * div2 *
* * *
* ***********
* * div3 *
* div1 * (image) *
* * *
* * *
* * *
* * *
* * *
**************************************************************************
div1
左侧有内容,其高度随内容高度调整。div2
包含一些文本,并且只有div3
一个图像。我想要的总高度div2
和div3
等于的高度div1
但是当我把照片放进去时,它会离开框架。在问题的标题中,我已经说过取其父亲身高的剩余部分,但紧随其后放置(如以下代码)或它们的高度比为 20 到 80
div3
并不重要。div3
div2
.container {
width: 100%
}
.left-side {
width: 80%;
background-color: red;
float: left;
}
.right-side {
text-align: center;
width: 20%;
background-color: blue;
float: right;
}
.top {
background-color: green;
}
.bottom img {
height: auto;
width: 100%;
}
<div class='container'>
<div class="left-side">
<p>Line 1</p>
<p>Line 2</p>
<p>Line 3</p>
<p>Line 4</p>
</div>
<div class="right-side">
<div class="top">
TOP
</div>
<div class="bottom">
<img src='https://www.kindpng.com/picc/m/73-736150_ios-arrow-thin-down-small-down-arrow-symbol.png'>
</div>
</div>
</div>
解决方案
我做了它flex
并删除了所有float
.container {
display:flex;
}
.left-side {
width: 80%;
background-color: red;
}
.right-side {
display:flex;
flex-direction:column;
text-align: center;
width: 20%;
background-color: blue;
}
.top {
background-color: green;
}
.bottom img {
height: auto;
width: 100%;
}
<div class='container'>
<div class="left-side">
<p>Line 1</p>
<p>Line 2</p>
<p>Line 3</p>
<p>Line 4</p>
</div>
<div class="right-side">
<div class="top">
TOP
</div>
<div class="bottom">
<img src='https://www.kindpng.com/picc/m/73-736150_ios-arrow-thin-down-small-down-arrow-symbol.png'>
</div>
</div>
</div>
推荐阅读
- netty - 是否有内置方法可以使空手道的 pathMatches 不区分大小写?
- scipy - Python Jupyter Notebook scipy
- influxdb - Influxdb 使用 group by 加速长时间的查询
- ruby - 我无法部署中间人项目
- php - Laravel - 队列作业 - 如何根据分派时传递给它的参数获取作业
- jenkins - 在scriptText中将变量传递给JobDsl种子作业(Jenkins)?
- java - Spring Boot 重复端点
- yii2 - 保存倍数复选框列表
- django - KeysValidator 在 django 中做了什么?
- ios - 将观察者从 ViewController 移动到 ViewModel