我的 HTML 中有一个元素具有这种样式:
{
max-width: 1500;
padding-rigth: 40px;
padding-left: 40px;
width: auto;
}
当屏幕小于 1580px 时一切正常,元素在屏幕中居中,但是当屏幕大于 1580px 时,元素不居中并粘在屏幕右侧(有 40px 填充)。
当屏幕大于 1580 像素时,如何使元素居中?
最佳答案
when the screen is less than 1580px everything is ok and the element is centered in the screen
我假设该元素是一个 block 级元素,对吧?如果是这样,您只需提供 auto
的 margin-left
/margin-right
即可实现对齐。
{
max-width: 1500;
padding-rigth: 40px;
padding-left: 40px;
width: auto;
margin-left: auto;
margin-right: auto;
}
关于html - 元素达到最大宽度时不居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29306933/