html - 如何将一些容器彼此相邻放置?HTML/CSS
问题描述
我想将两个或更多容器内联这是我的 HTML 代码:
<div id="containers-place">
<div style="padding: 16px;">
<a href="https://google.com/" target="blank" style="text-decoration: none;"><div class="container" style="width: 20%;">
<img src="picture1.png" width="100%">
<h4>Picture One</h4>
<p>As you can see this is picture One</p>
</div></a>
</div>
<div id="idk" style="padding: 16px;">
<a href="https://google.com/" target="blank" style="text-decoration: none;"><div class="container" style="width: 20%;">
<img src="picture2.png" width="100%">
<h4>Picture2</h4>
<p>As you can see this is picture Two</p>
</div></a>
</div>
和CSS:
.container {
padding: 16px;
background-color: #333333;
color: #fff;
display: block;
}
我截取了浏览器的截图: screenshoot
解决方案
您可以为此使用 flex
<div id="containers-place"class='flexrow'>
<div style="padding: 16px;" class='flexcolumn'>
<a href="https://google.com/" target="blank" style="text-decoration: none;"><div style="width: 20%;">
<img src="picture1.png" width="100%">
<h4>Picture One</h4>
<p>As you can see this is picture One</p>
</div></a>
</div>
<div id="idk" style="padding: 16px;" class='flexcolumn'>
<a href="https://google.com/" target="blank" style="text-decoration: none;"><div style="width: 20%;">
<img src="picture2.png" width="100%">
<h4>Picture2</h4>
<p>As you can see this is picture Two</p>
</div></a>
</div>
css
.flexrow{
display: flex;
flex-direction: row
}
.flexcolumn{
//you can adjust width if you want
}
推荐阅读
- mysql - 有什么方法可以使用 JOIN 正确替换条件子查询并优化这些类型查询?
- css - 移动子菜单的自定义样式
- asp.net-core - 网络核心单元测试中的http类型客户端
- java - 字符串在 Dagger 中被多次绑定
- html - 从侧面切割的打印预览
- azure-sqldw - 如何将下一行开始日期添加为上一行结束日期?
- java - Groovy 脚本错误:java.io.NotSerializableException:com.xlson.groovycsv.CsvIterator
- ravendb - RavenDB 4+ 分页查询,字段不同
- r - 在 R 中,这个括号 `[` 是什么?
- php - Laravel:使用外键从表中获取数据