链接未出现在 div 类中,出现在其外部
我正在尝试重新创建一些我在网上看到的元素,并且我一直在使用元素检查器,但似乎无法弄清楚为什么这个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
@扎克;您将
position:absolute;
赋予您的a
标签,因此将position:relative;
赋予您的父 divmodalHeader
这对你有用。CSS:
有关更多信息,请阅读这篇文章 http://css-tricks.com /791-绝对定位-内部相对定位/
@zack; you give
position: absolute;
to youra
tag so, giveposition: relative;
to your parent divmodalHeader
that's work for you .CSS:
for more read this article http://css-tricks.com/791-absolute-positioning-inside-relative-positioning/
您已将链接设置为绝对位置,而不是相对于其父容器。删除该位置,并将顶部和右侧更改为边距。
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.
绝对位置始终指的是相对或绝对位于其上方的元素。若无,则指身体。尝试将
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;
toposition: relative;
or define the modalHeader asposition: relative;
.