css - 在所有元素上叠加图案

标签 css

是否可以将图像(图案)放在 2 个或更多元素(具有不同背景)上? (类似于 Adob​​e Photoshop 中的图案填充)

截图如下: enter image description here

注意:元素内容应可供用户选择。我不想要一个覆盖在其他元素上的 div。

最佳答案

制作一个 .png 文件(或者 .gif,如果你喜欢的话),然后简单地将它覆盖在你想要这个图案的 div 上。

You need to set the parent element using position relative then use position absolute on the element you want to position. So if you want it to be positioned based on the table you need to add position: relative to the table (which won't do anything because it is already positioned relative) and position: absolute to the overlay. Absolute positioning takes the element out of the document flow and relative positioning leaves it in the document flow which is why stuff is being moved around. The reason for this is based off how CSS works: http://www.w3schools.com/css/pr_class_position.asp

relative The element is positioned relative to its normal position, so "left:20" adds 20 pixels to the element's LEFT position

absolute The element is positioned relative to its first positioned (not static) ancestor element

Source: Position overlay div

代码示例:

<div class="overlay">
    <div class="overlay-content">
    </div>
    Content goes here
</div>

对于 CSS:

div.overlay{
    position: relative;
}

div.overlay-content{
    position: absolute;
    top: 0;
    left :0;
    width: 100%;
    height: 100%;
    background: url(path/to/image.png) repeat top left;
    pointer-events:none; /* To be able to click through */
}

关于点击槽,看看这个答案:Click through a DIV to underlying elements

关于css - 在所有元素上叠加图案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14030373/

相关文章:

html - 如何让 3 个 div 在另一个 div 之上相互对齐?

javascript - 当 div 到达窗口底部时停止滚动

html - 背景图像在顶部和底部被剪切

javascript - 响应式菜单无法在 320 像素屏幕上打开

javascript - 临时更改输入框样式

css - 尝试为 IE 中的页脚栏提供 float 效果时出现问题

php - 制作 PHP 图像表

css - 相对于父 div 定位颜色框

html - Fotorama 缩略图不显示 - 灰色 block ,点击时无图像

javascript - 如何使用javascript回到网站底部,如回到顶部?