HTML响应式网站图像中心
这个问题在这里已经有了答案:
你可以试试: {
display:flex;
justify-content:center;
}
您可以使用柔性盒。
.box {
display: flex;
justify-content: center;
justify-items: center;
}
https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Flexbox
您应该通过在框中添加容器来重构您的HTML:
<div class="box-container">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
使用flexbox作为容器,并使用flex
属性在屏幕上给出相同的空间:
/* Only for demo purposes */
body, html {
box-sizing: border-box;
width: 100vw;
max-width: 100%;
overflow-x: hidden;
}
/* Main part: flexbox is added to the container box and the flex property allots them equal space with a margin of 10px as well */
.box-container {
width: 100vw;
display: flex;
}
.box {
flex: 1 0 0;
width: 120px;
height: 120px;
background-color: red;
margin-right: 10px;
}
这里是一个小提琴的链接:jsfiddle
链接地址: http://www.djcxy.com/p/75767.html