html - 使div元素背景对背景图片CSS透明

标签 html css web transparent

我想在我的网站中制作视差效果,但是我无法将 DIV 元素的背景设置为透明,尽管使用了 background-color: transparent.

基本上,我只想在 DIV 中显示文本,并删除背景色。

通过使用 W3School..

    body, html {
        height: 100%;
    }
    
    .parallax {
        /* The image used */
        background-image: url('http://www.zastavki.com/pictures/originals/2013/Photoshop_Image_of_the_horse_053857_.jpg');
    
        /* Full height */
        height: 100%; 
    
        /* Create the parallax scrolling effect */
        background-attachment: fixed;
        background-position: center;
        background-repeat: no-repeat;
        background-size: cover;
    }
    
    .parallax2 {
        /* The image used */
        background-image: url('http://www.qygjxz.com/data/out/114/4676052-image.png');
    
        /* Full height */
        height: 100%; 
    
        /* Create the parallax scrolling effect */
        background-attachment: fixed;
        background-position: center;
        background-repeat: no-repeat;
        background-size: cover;
    }
    
    /* Turn off parallax scrolling for tablets and phones. Increase the pixels if needed */
    @media only screen and (max-device-width: 1024px) {
        .parallax {
            background-attachment: scroll;
        }
    }>
    
    <div class="parallax"></div>
    
    <div style="height:100px;background-color:transparent;font-size:36px">
    Some text goes here, need to try to make the background of this transparent? Any ideas?
    </div>
    
    <div class="parallax2"></div>

谢谢

最佳答案

如果您想将背景颜色设置为透明,您可以执行所有这些操作。

背景颜色:; 背景颜色:透明; 背景色:rgba(0, 0, 0, 0);

但在这种情况下,您需要在此处设置不同的位置是我希望这就是您要找的代码

<div style="height:100px;font-size:36px; border:1px solid red; position: absolute;">
  Some text goes here, need to try to make the background of this transparent? Any ideas?
</div>

关于html - 使div元素背景对背景图片CSS透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45265233/

相关文章:

html - 在整个页面上拉伸(stretch)元素,无论缩放/ View 如何

html - 制作html框 "stick out"

php - 发送电子邮件时未找到 laravel 类 'domdocument'

javascript - 如何将 dbfs 校准为 db spl?

html - 我在 HTML 和 CSS 上更改图像大小时遇到​​问题

javascript - Javascript 新手 - 改变元素的样式

javascript - 获取选择选项php的值

html - 伪类不适用于类

javascript - 用星号屏蔽 HTML 表单文本字段

html - 为什么我不能在下面的方案中对齐div/为什么最后一个容器不可见?