链接未出现在 div 类中,出现在其外部

发布于 2024-12-01 10:06:14 字数 1354 浏览 5 评论 0原文

我正在尝试重新创建一些我在网上看到的元素,并且我一直在使用元素检查器,但似乎无法弄清楚为什么这个 href 元素在我的 modalHeader 类之外加载。

这是一些 HTML:

<div id="modalContainer">
<div class="fakeModal">

    <div class="modalHeader"> 

        <h2>Fake Modal Heading</h2>
        <a href="#" class="close">x</a>

    </div> <!-- end modalHeader -->

</div> <!-- End fakeModal -->   

以及相应的CSS(使用Less

#modalContainer {
width: 700px;
height: 250px;
background: gray;
padding: 1px; }

.fakeModal {
    width: 500px;
    height: 150px;
    margin: 50px auto 50px auto;
    border-radius: 3px;
    //border: 3px solid black;
    background: white;
}

.modalHeader {
h2 {
    background: @dullGray;
    border-bottom: solid 1px #EEE; //This makes so much of a difference!!!!
    border-radius: 3px 3px 0 0;
    display: block;
    -webkit-margin-before: 1em;
    -webkit-margin-after: 1em;
    -webkit-margin-start: 0px;
    -webkit-margin-end: 0px;
    padding: 9px 15px;
}

a.close{
    position: absolute;
    top: 10px;
    right: 10px;
    color: gray;
    text-decoration: none;
    font-size: 18px;
}

a.close:hover {
    text-decoration: underline;
    color: gray;
    }
}

任何人都可以弄清楚为什么x没有在我定义的水平框中呈现在模态标题中?

I'm trying to re-create a few elements I've seen online and I've been using Element Inspector but can't seem to figure out why this a href element is loading outside of my modalHeader class.

Here's some HTML:

<div id="modalContainer">
<div class="fakeModal">

    <div class="modalHeader"> 

        <h2>Fake Modal Heading</h2>
        <a href="#" class="close">x</a>

    </div> <!-- end modalHeader -->

</div> <!-- End fakeModal -->   

And corresponding CSS (using Less)

#modalContainer {
width: 700px;
height: 250px;
background: gray;
padding: 1px; }

.fakeModal {
    width: 500px;
    height: 150px;
    margin: 50px auto 50px auto;
    border-radius: 3px;
    //border: 3px solid black;
    background: white;
}

.modalHeader {
h2 {
    background: @dullGray;
    border-bottom: solid 1px #EEE; //This makes so much of a difference!!!!
    border-radius: 3px 3px 0 0;
    display: block;
    -webkit-margin-before: 1em;
    -webkit-margin-after: 1em;
    -webkit-margin-start: 0px;
    -webkit-margin-end: 0px;
    padding: 9px 15px;
}

a.close{
    position: absolute;
    top: 10px;
    right: 10px;
    color: gray;
    text-decoration: none;
    font-size: 18px;
}

a.close:hover {
    text-decoration: underline;
    color: gray;
    }
}

Can anyone figure out why the x isn't rendering in the horizontal box I've defined in modalHeader?

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

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

发布评论

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

评论(3

输什么也不输骨气 2024-12-08 10:06:14

@扎克;您将 position:absolute; 赋予您的 a 标签,因此将 position:relative; 赋予您的父 div modalHeader这对你有用。

CSS:

.modalHeader {position: relative;}

有关更多信息,请阅读这篇文章 http://css-tricks.com /791-绝对定位-内部相对定位/

@zack; you give position: absolute; to your a tag so, give position: relative; to your parent div modalHeader that's work for you .

CSS:

.modalHeader {position: relative;}

for more read this article http://css-tricks.com/791-absolute-positioning-inside-relative-positioning/

小兔几 2024-12-08 10:06:14

您已将链接设置为绝对位置,而不是相对于其父容器。删除该位置,并将顶部和右侧更改为边距。

You've set the link to be position absolute, not relative to it's parent container. Remove the position, and change the top and right to margins.

抚你发端 2024-12-08 10:06:14

绝对位置始终指的是相对或绝对位于其上方的元素。若无,则指身体。尝试将 position:absolute; 更改为 position:relative; 或将 modalHeader 定义为 position:relative;

An absolute position always refers to the element above which is positioned relative or absolute. If there isn't one, it refers to the body. Try to change position: absolute; to position: relative; or define the modalHeader as position: relative;.

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