将div放在div而不使用绝对值(Putting div on div without using absolute)

编程入门 行业动态 更新时间:2024-10-23 08:24:26
将div放在div而不使用绝对值(Putting div on div without using absolute)

这是我正在研究的我的网站: http : //mamgrow.lt/pagrindinis.html

在最底部,您可以看到红色div块。 我需要它在内容上移到顶部。 是否可以不使用position:absolute(因为我失去了中心对齐)和top:x?

问题是,在我滚动某个点之后,这个红色div将变得固定(将使用jQuery)。

对于信息div我用这个css:

.konteineris { margin-left: auto; margin-right: auto; width: 960px; overflow:hidden; background-color:#F0F0F0; position:relative; }

对于red div,我使用了这个css:

.konteineris2{ margin-left: auto; margin-right: auto; width: 960px; overflow:hidden; background-color:red; height:700px; position:relative; }

Here the website of mine that I'm working on: http://mamgrow.lt/pagrindinis.html

At the very bottom you can see red div block. I need it to move to the top on content. Is it possible without using position:absolute (because I lose center alignment) and top:x?

The thing is, that after I scroll at some point this red div will become fixed (will use jQuery).

For the information div I used this css:

.konteineris { margin-left: auto; margin-right: auto; width: 960px; overflow:hidden; background-color:#F0F0F0; position:relative; }

For the red div I used this css:

.konteineris2{ margin-left: auto; margin-right: auto; width: 960px; overflow:hidden; background-color:red; height:700px; position:relative; }

最满意答案

这就是你如何使用绝对定位将一个div居中对齐另一个div的顶部(或者在另一个div中,你应该发布你的html或做一个小提琴)。这不应该影响你的jquery

假设HTML

<div class="konteineris"> <div class="konteineris2"></div> </div>

垂直和水平居中对齐

.konteineris2{ position:absolute; left: 50%; top: 50%; margin: -350px 0 0 -430px; }

水平居中对齐

.konteineris2{ position:absolute; left: 50%; top: 0%; margin: 0 0 0 -430px; }

This is how you use absolute positioning to center align a div on top of another div (or inside another div, you should post your html or make a fiddle).This should not effect your jquery

Assumed HTML

<div class="konteineris"> <div class="konteineris2"></div> </div>

Vertically and Horizontally center aligned

.konteineris2{ position:absolute; left: 50%; top: 50%; margin: -350px 0 0 -430px; }

Horizontally center aligned

.konteineris2{ position:absolute; left: 50%; top: 0%; margin: 0 0 0 -430px; }

更多推荐

本文发布于:2023-08-07 00:26:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1458824.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:放在   绝对值   而不   div   Putting

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!