gpt4 book ai didi

JavaScript 中心

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

Possible Duplicate:
How to align a <div> to the middle of the page

这是一个简单的问题,应该有一个简单的答案,但我不知道该怎么做。

好吧,使用这段代码:

<html>
<head>
<style type="text/css">
body{
min-width: 710px;
}
#backdrop{
min-width: 710px;
max-width: 710px;
}
</style
</head><body>

<div id="backdrop">
</div>

</body></html>

如何让 #backdrop 在页面加载时居中并在调整大小时保持在页面居中? (直到您将宽度调整到小于710px,然后才会出现水平滚动条)

了解这些信息将极大地提高我的页面的布局质量,如果我对 javascript 和 jQuery 有更深入的了解,我可能可以做到这一点......但我还没有。

最佳答案

如果您需要的只是让 #backdrop div 水平居中,则不需要 JavaScript。整个事情都可以通过CSS来实现。

#backdrop{ 
display:block;
width: 710px; //just specify the width. no need for min-width or max-width if this is not meant to change.
margin: 0 auto; //this will center the div in its container
}

关于JavaScript 中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7565787/

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