CSS 问题,位置:绝对

发布于 2024-09-12 13:34:14 字数 1761 浏览 2 评论 0原文

我不知道如果父母有一个立场:绝对,我应该宣布什么样的立场。

这是代码,

<div id="new_map">
                    <div id="map_nbc_pop">
                        <div class="nm_bubbletop1"></div>
                        <div id="nm_bubblebg">                          
                            <ul class="nm_left">
                            <li><a href="#">Chetwynd</a></li>
                                <li><a href="#">Fort St James</a></li>
                                <li><a href="#">Fort St John</a></li>
                            </ul>
                            <ul class="nm_right">
                            <li><a href="#">McBride</a></li>
                                <li><a href="#">Prince George</a></li>
                                <li><a href="#">Prince Rupert</a></li>
                            </ul>
                        </div>
                        <div class="nm_bubblebelow1"></div>
                    </div>
</div>

这是示例 CSS,我只是删除了其他内容以供查看...

#new_map { position: static }
#map_nbc_pop { position: absolute }

对我来说问题在于 .nm_bubbletop1、#nm_bubblebg、.nm_bubblebelow1 我该使用什么位置?因为它们在浏览器上没有正确分层。

<div class="nm_bubblebelow1"></div>
<div class="nm_bubbletop1"></div>
<div id="nm_bubblebg"></div>

我想要的是这个,

<div class="nm_bubbletop1"></div>
<div id="nm_bubblebg"></div>
<div class="nm_bubblebelow1"></div>

谢谢!

I don't know what kind of position shall I announce if the parent has a position: absolute.

Here's the code,

<div id="new_map">
                    <div id="map_nbc_pop">
                        <div class="nm_bubbletop1"></div>
                        <div id="nm_bubblebg">                          
                            <ul class="nm_left">
                            <li><a href="#">Chetwynd</a></li>
                                <li><a href="#">Fort St James</a></li>
                                <li><a href="#">Fort St John</a></li>
                            </ul>
                            <ul class="nm_right">
                            <li><a href="#">McBride</a></li>
                                <li><a href="#">Prince George</a></li>
                                <li><a href="#">Prince Rupert</a></li>
                            </ul>
                        </div>
                        <div class="nm_bubblebelow1"></div>
                    </div>
</div>

here's the sample CSS, I just remove the other for viewing...

#new_map { position: static }
#map_nbc_pop { position: absolute }

The problem for me is in .nm_bubbletop1, #nm_bubblebg, .nm_bubblebelow1
What position shall I use? Because they are not properly layered on the browser.

<div class="nm_bubblebelow1"></div>
<div class="nm_bubbletop1"></div>
<div id="nm_bubblebg"></div>

What I want is this,

<div class="nm_bubbletop1"></div>
<div id="nm_bubblebg"></div>
<div class="nm_bubblebelow1"></div>

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浮生面具三千个 2024-09-19 13:34:14

如果您需要在不更改代码的情况下更改

的显示方式,position:absolute 是您的最佳选择:

.nm_bubbletop1, #nm_bubblebg, .nm_bubblebelow1 [
   position: absolute;
   left: 0;
}

.nm_bubbletop1 {
   top: 0;     
}

#nm_bubblebg {
   top: 100px; /* this is .nm_bubbletop1's height */     
}

.nm_bubblebelow1 {
   top: 200px;  /* this is .nm_bubbletop1's height + #nm_bubblebg's  height */    
}

话虽这么说,但它很 hacky。如果您可以在 HTML 中按照您想要的方式对它们进行排序,那么您的生活将会更轻松。

If you need to change how the <div>'s appear without changing the code, position: absolute is your best option:

.nm_bubbletop1, #nm_bubblebg, .nm_bubblebelow1 [
   position: absolute;
   left: 0;
}

.nm_bubbletop1 {
   top: 0;     
}

#nm_bubblebg {
   top: 100px; /* this is .nm_bubbletop1's height */     
}

.nm_bubblebelow1 {
   top: 200px;  /* this is .nm_bubbletop1's height + #nm_bubblebg's  height */    
}

That being said, it's hacky. If there's anyway you can just order them the way you want in the HTML, it'll make your life easier.

青衫负雪 2024-09-19 13:34:14

如果您给 #new_map 一个 relative 位置,然后给您想要安排绝对位置的子项,这将使这些子项的位置相对于父项 #new_map 即坐标原点将是#new_map 的左上角。然后,您可以根据 #new_map 的位置更改子级的堆叠顺序 (z-index) 或位置(上、左、右、下)。

if you give #new_map a position of relative and then the children you want to arrange a position of absolute this will make the position of those children relative to the parent #new_map ie your origin for coordinates will be the top left corner of #new_map. You can then change the stacking order (z-index) or positioning (top, left, right, bottom) of the children as you like based on where #new_map is.

幻想少年梦 2024-09-19 13:34:14

我想这就是你的意思>

<div id="new_map">
                <div id="map_nbc_pop">
                    <div class="nm_bubbletop1"></div> 
                    <div id="nm_bubblebg">
                        <ul class="nm_left" >
                        <li><a href="#">Chetwynd</a></li>
                            <li><a href="#">Fort St James</a></li>
                            <li><a href="#">Fort St John</a></li>
                        </ul>
                        <ul class="nm_right">
                        <li><a href="#">McBride</a></li>
                            <li><a href="#">Prince George</a></li>
                            <li><a href="#">Prince Rupert</a></li>
                        </ul>
                    </div>
                    <div class="nm_bubblebelow1"></div>
                </div>

还有 css:

#new_map { position: static }
#map_nbc_pop { position: absolute }
.nm_bubbletop1, .nm_bubblebelow1 {  position:absolute; height:15px; background-color:#ccc; width:100%; }
.nm_bubbletop1 { top:0px; }
.nm_bubblebelow1 { bottom:0px; }
#nm_bubblebg { margin:15px 0px; }

这使得菜单变得灵活,并且顶部和底部始终就位。中间的边距使其无缝连接。

小提琴:http://jsfiddle.net/fmDhn/1/

This is what you mean i think >

<div id="new_map">
                <div id="map_nbc_pop">
                    <div class="nm_bubbletop1"></div> 
                    <div id="nm_bubblebg">
                        <ul class="nm_left" >
                        <li><a href="#">Chetwynd</a></li>
                            <li><a href="#">Fort St James</a></li>
                            <li><a href="#">Fort St John</a></li>
                        </ul>
                        <ul class="nm_right">
                        <li><a href="#">McBride</a></li>
                            <li><a href="#">Prince George</a></li>
                            <li><a href="#">Prince Rupert</a></li>
                        </ul>
                    </div>
                    <div class="nm_bubblebelow1"></div>
                </div>

And css:

#new_map { position: static }
#map_nbc_pop { position: absolute }
.nm_bubbletop1, .nm_bubblebelow1 {  position:absolute; height:15px; background-color:#ccc; width:100%; }
.nm_bubbletop1 { top:0px; }
.nm_bubblebelow1 { bottom:0px; }
#nm_bubblebg { margin:15px 0px; }

​This makes the menu flexible, and the top and bottom are always in place. The margin of the middle makes it seamlessly connect.

The fiddle: http://jsfiddle.net/fmDhn/1/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文