gpt4 book ai didi

html - 将最大宽度的 div 居中,没有边距 : auto;

转载 作者:太空宇宙 更新时间:2023-11-03 23:03:08 25 4
gpt4 key购买 nike

那是我的笔:http://codepen.io/helloworld/pen/oxgqpJ

我想将一个具有固定最大宽度的 div 居中,但是当我在固定最大宽度以下时,我希望每边有 10% 的边距,因为此时在该分辨率区域中没有可见边距。

缺点是每边使用 10% 的边距,div 不再居中,它从左侧开始...

我该如何解决?

<div id="container">
Center me with a fixed max width, but when I am under the fixed max width I want a margin of 10% on each side , because at the moment there is no visible margin.
</div>



#container
{
margin: 0 auto;

// use instead in smaller resolutions
//margin: 0 10%;
max-width:1024px;
background:orange;
}

最佳答案

你可以使用这个,例如:

@media (max-width: 1024px) {
#container { margin: 0 10%; }
}

参见 http://www.w3schools.com/cssref/css3_pr_mediaquery.asp

关于html - 将最大宽度的 div 居中,没有边距 : auto;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35721602/

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