html - 如何将一个元素重叠在另一个元素上

标签 html css

嗨,我有一个 <hr>线在页面上延伸,但我认为它一直被它上面的图像切断。有谁知道我怎样才能做到 <hr>线条与图像重叠?

<img src=".\pncwelcome.png" 
    style="float:right; clear:right; margin-top:-40px;" 
    alt="PNC Welcome Logo"/>
<hr color="black" 
    style="margin-top:30px;" />

最佳答案

使用position: absolute;

Check the fiddle.

这样的事情应该可行。

CSS:

.parent {
    position: relative;
}

img {
    width: 200px;
}

hr {
    position: absolute;
    z-index: 50;
    top: 30px;
    right: 0;
    left: 0;
}

HTML:

<div class="parent">
    <hr>
    <img src="http://fanumusic.com/wp-content/uploads/2012/10/Free.jpg">
</div>

关于html - 如何将一个元素重叠在另一个元素上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16799063/

相关文章:

javascript - 根据其中的文本设置大小内容可编辑的 div

javascript - 为什么悬停没有效果?

html - 如何修改仅属于特定类的链接?

jquery - CSS 悬停在图像上的效果不起作用

html - 调整窗口大小时如何使背景图像缩放以适合整个窗口?

html - 使用 CSS 将句子中的大写字母转换为小写字母和第一个大写字母

javascript - LocalStorage、JavaScript 和对象

html - 页脚位置固定在页面底部

javascript - 通过 Onclick 使用 appendChild/replaceChild 函数切换图像堆栈

javascript - 无法将 mousedown 事件附加到嵌入元素