Changing Jumbotron opacity and make it full width without affecting the font and button

后端 未结 2 1363
旧时难觅i
旧时难觅i 2021-01-27 07:31

would like to ask how to change Jumbotron opacity and make it full width without affecting the opacity of the font and the button?

.jumbotron-special{
    text-a         


        
相关标签:
2条回答
  • 2021-01-27 07:58

    See the following fiddle: http://jsfiddle.net/7ak3b0f4/

    Basically, have a parent element manage the page flow, make it relative, and create a child element for the background, and one for the content (order matters due to z-index, unless you manually change it). Then, have the children be absolutely positioned, and fill the entire parent.

    <div class="jumbotron">
        <div class="bg">
            I'm in the background.
        </div>
        <div class="content">
            <h1>Important stuff!</h1>
            <button>Yup.</button>
        </div>
    </div>
    

    and

    .jumbotron {
        width: 100%;
        height: 400px;
        position: relative;
    }
    
    .jumbotron .bg {
        opacity: 0.10;
        background-color: orange;
        position: absolute;
        width: 100%;
        height: 100%;
     }
    
    .jumbotron .content {
        position: absolute;
        width: 100%;
        height: 100%;
    }
    
    0 讨论(0)
  • 2021-01-27 08:14

    You can add the background in another element and decrease the opacity only for that element:

    .jumbotron-special {
       position: relative;
    }
    .jumbotron-special:after {
        content : "";
        display: block;
        position: absolute;
        top: 0;
        left: 0;
        background-image: url('header-bg.jpg'); 
        width: 100%;
        height: 100%;
        opacity : 0.3;
        z-index: -1;
    }
    
    0 讨论(0)
提交回复
热议问题