gpt4 book ai didi

html - 在 flexbox 中的元素之间发出默认间隙

转载 作者:行者123 更新时间:2023-11-28 00:13:15 25 4
gpt4 key购买 nike

给定一个简单的 flexbox:

enter image description here

我想发出 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>

最佳答案

.flex-container justify-content: space-evenly; 或者 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>

关于html - 在 flexbox 中的元素之间发出默认间隙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55267011/

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