【问题标题】:How to set a background opacity without affecting the text [duplicate]如何在不影响文本的情况下设置背景不透明度[重复]
【发布时间】:2016-12-23 23:50:57
【问题描述】:

我基本上是在尝试创建这个:

添加了一个带有背景图像的父容器,然后是一个需要透明的子容器。

这是我的 HTML:

<div class="scent-brand-contact">
    <div class="scent-brand-container">               
       <section id="black-studio-tinymce-8" class="widget-1 widget-first widget-odd widget widget_black_studio_tinymce">
            <div class="textwidget">
                <p>All our fragrances are developed in compliance with the International Fragrance Association ensuring strict adherence to safety purity and manufacturing standards.</p>
                <p>LEARN MORE ABOUT HOW SCENT BRANDING CAN BENEFIT YOUR BUSINESS</p>
            </div>
        </section>
        <section id="text-4" class="widget-2 widget-last widget-even widget widget_text">
            <div class="textwidget">
            <button type="button">contact us today</button>
            </div>
        </section>                    
   </div>
</div>

还有 CSS:

.scent-brand-contact{
    position:relative;
    background-image: url(images/lemon.jpg);
    background-position: center center;
    background-attachment: fixed;
    background-size: cover;
    min-height:380px;
}
.scent-brand-container {
    background-color: #fff9c0;
    padding: 10px;
    opacity: 0.7;
    padding-top: 5%;
    margin: auto;
    position: absolute;
    top: 12%;
    width: 100%;
    min-height: 285px;
}

目前,按钮和文本也变得不透明。 如何在不影响文本和按钮的情况下获得透明背景?

【问题讨论】:

    标签: html css transparency


    【解决方案1】:

    您可以使用rgba 仅使背景颜色透明,例如:

    background: rgba(255, 249, 192, 0.7); 
    

    【讨论】:

    • 嗨 Andreas,如果我们将动态颜色设为主题 = #4e74f0(十六进制格式),我们如何添加 alpha。我们将它添加到元素中 - $().css('background", theme) , $().css('opacity',0.1)。在这里,我们如何赋予 alpha 与 rgba 相同的而不是不透明度/跨度>
    • 好吧,如果浏览器兼容性不是问题,您可以使用 alpha 十六进制值(检查 herehere
    猜你喜欢
    • 2014-05-16
    • 2016-03-25
    • 1970-01-01
    • 2019-04-12
    • 2015-07-18
    • 2011-06-27
    相关资源
    最近更新 更多