html - 在弹性框中的项目之间发出默认间隙
问题描述
给定一个简单的弹性盒:
我想发出 img 和绿色区域之间的空间。我怎样才能用我的代码做到这一点?
* {
box-sizing: border-box;
}
body {
margin: 0;
}
.flex-container {
display: flex;
flex-flow: row nowrap;
justify-content: center;
align-items: center;
border: solid;
width: 1028px;
margin: 0 auto; /* put the container on the middle */
}
.flex-container ul {
padding-left: 0; /* avoud the default padding to the left */
background: green;
}
.flex-container ul li {
display: inline-block;
padding: 30px;
}
.flex-container img {
vertical-align: middle;
width: 45%;
}
<div class="flex-container">
<div>
<img src="https://i.imgur.com/cvO9xwB.png">
</div>
<div>
<ul>
<li>Home</li>
<li>About</li>
<li>Shop</li>
<li>Contact us</li>
</ul>
</div>
</div>
解决方案
对于惰性修复,您可以执行以下操作:
<div style="margin-right: -132px">
<img src="https://i.imgur.com/cvO9xwB.png">
</div>
将更多地使用您的代码,并尝试找到一种更优雅的修复方法。
如果我发现任何东西,我会编辑。
编辑:
.flex-container img {
vertical-align: middle;
float: right; /*This fixes the image*/
width: 45%;
}
我发现当你调整图像大小时,它仍然保持它的宽度,所以这就是为什么右边有空间。
推荐阅读
- bash - Jenkins:在 shell 脚本和阶段之间传递一个变量
- reactjs - React Redux - 如何使用选择器派生然后聚合 mapStateStateToProps 中的数据?
- javascript - 一个函数调用另一个函数而在 Angular 中没有任何特定调用
- python - 成功时返回true是否是一种好习惯,否则会在python中引发异常?
- spring - boundedElastic() 与 parallel() 调度程序之间的区别
- python - 如何在 Ubuntu 18.04 上成功安装 sciencepython 包?
- javascript - 使用 CSS 列时,Swiper.js 自动宽度不起作用
- mysql - 从枚举中减去数字
- java - 在 Selenium 的单个窗口中更改不同页面之间的驱动程序焦点
- python - 如果在 tkinter 中编辑条目,则禁用按钮