简体   繁体   English

发出弹性框中项目之间的默认间隙

[英]Emit default gap between items in a flexbox

Given a simple flexbox: 给出一个简单的flexbox:

在此输入图像描述

I want to emit the space between the img and the green area.. How can I do it with my code? 我想发出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> 

Give the .flex-container a justify-content: space-evenly; .flex-container一个justify-content: space-evenly; or justify-content: space-around; justify-content: space-around;

 * { box-sizing: border-box; } body { margin: 0; } .flex-container { display: flex; flex-flow: row nowrap; justify-content: space-evenly; align-items: center; border: solid; width: 1028px; margin: 0 auto; /* put the container on the middle */ } .flex-container .img-wrap{ width: 108px height: 110px } .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 class="img-wrap"> <img src="https://seeklogo.com/images/N/new-google-maps-icon-logo-263A01C734-seeklogo.com.png"> </div> <div> <ul> <li>Home</li> <li>About</li> <li>Shop</li> <li>Contact us</li> </ul> </div> </div> 

For a lazy fix you can do: 对于懒惰修复,您可以执行以下操作:

  <div style="margin-right: -132px">
    <img src="https://i.imgur.com/cvO9xwB.png">
  </div>

Will play more with your code and will try to find a more elegant way of fixing it. 将更多地使用您的代码,并将尝试找到一种更优雅的方法来修复它。
Will edit if I find anything. 如果我找到任何东西,将编辑。
EDIT: 编辑:

.flex-container img {
  vertical-align: middle;
  float: right; /*This fixes the image*/
  width: 45%;
}

I found out that when you resized the image it still keeps its width so this is why there is the space on the right. 我发现当你调整图像大小时它仍保持宽度,这就是为什么右边有空间的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM