gpt4 book ai didi

javascript - 围绕 div 对齐/环绕图像

转载 作者:太空宇宙 更新时间:2023-11-03 18:56:47 24 4
gpt4 key购买 nike

我想要实现的是一个页面,其中的 div 位于屏幕中间 (720x360)。这是使用 jQuery 完成的:

$(window).height()

和:

$(window).width()

完美运行。

下一部分是获取 180x180 图像以适合中间的 div。这些将填满屏幕 + 超出范围。

我一直在研究如何让它们以这种方式对齐,但我找不到任何人做同样事情的活生生的例子。

那么,这有可能吗?

最佳答案

<style type="text/css">

#main {
display: block;
margin:0 auto; /* This is make div into center of screen*/
width: 720px;
height: 360px;
background: #ccc; /* Just for visibility */
position: relative; /* As we want to make other div into center of this */
}

#content {
display: block;
width: 180px;
height: 180px;
position: absolute;
left: 36.36%; /* You can calculate using math */
/*
Total Width - Width
So you will get end point now minus half
Width / 2 = 90
Then 720 - 180 = 540
And now your box will point to end but you need to divide
half of width again 90/2 = 45
Result is :
180/2/2 = 45
720-180-45 = 495
180/495*100 = 36.36
So this is your width position.
* */
top: 25%;
/*
Same for height but as you can see it's 25% of your value and very easy
* */
background: red;
}


</style>
<div id="main">
<div id="content"></div>
</div>

关于javascript - 围绕 div 对齐/环绕图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13263325/

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