gpt4 book ai didi

css - 固定宽度的页面布局,但可随内容调整

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

我想升级我的网站模板。我希望内容位于固定宽度居中的 div 中。这不是问题,网络上有很多示例。由于我已经对文本和表格感到满意,所以我想确保 div 不会切割某些页面的内容。我不想使用 Javascript 来调整宽度。有没有办法用 div 来做到这一点,还是应该改用表格?

最佳答案

没有正确回答您的问题,也像垂直居中一样?如果你想让它垂直居中,你需要使用 position: absolute;,如果你想让它水平居中,你只需要使用 margin: auto;,就这么简单...

/* Totally center fixed width content */

.center {
position: absolute;
top: 50%;
left: 50%;
margin-top: /* Half of the total height of the container div */
margin-left: /* Half of the total width of the container div */
}

如果需要内容水平居中,需要使用

.horizontal {
margin: auto;
}

内容不会被裁剪,除非同时使用 fixed width divoverflow: hidden;

关于css - 固定宽度的页面布局,但可随内容调整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14627324/

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