locked
how to use media queries with nested div RRS feed

  • Question

  • User569149469 posted

    hi,

    I have a html and css as shown 

    https://codepen.io/aspnetgal/pen/vaoNPz

    I want for desktop the div content which as text (heading and paragraph) and controls to be displayed in single line

    I want for table the div content which as test(heading/paragragh vertically aligned) and controls to be displayed in single line

    I want for a mobile the div content which has test heading,paragraph and controls to be displayed in vertical line.

    Friday, August 17, 2018 7:49 AM

Answers

  • User283571144 posted

    Hi phmaspnet,

    According to your description and code, I suggest that you could set the style separately for different window size.

    For example, if you want to display the div in single line, you may use the style inline-block.

    For more, you could refer to the code below.

    Notice: The solution is applicable to IE9 and later versions.

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title></title>
        <style type="text/css">
            * {
                margin: 0;
                padding: 0;
                box-sizing: border-box;
            }
            .adv-signup {
                ;
                background-image: linear-gradient( #fff, #eff1f1);
                width: 100%;
                height: 20%;
            }
    
            .contents .bg {
                background: #ffffff url("https://s6.postimg.cc/ugw1p1pcx/sprite.png ") no-repeat left top;
                margin: 0;
            }
    
            .contents{
                width:100%;
            }
    
    
    
            .btn {
                background: #0c5382;
                color: white;
            }
    
            h3, h1 {
                padding: 0px;
                margin: 0px !important;
            }
            /* Extra small devices (phones, 600px and down) */
            @media only screen and (max-width: 600px) {
                .adv-signup {
                    background: red;
                }
                .text h3 {
                    width: 100%;
                }
                .text p {
                    width: 100%;
                }
                .text {
                    width: 100%;
                }
                .controls {
                    width: 100%;
                }
            }
    
            /* Small devices (portrait tablets and large phones, 600px and up) */
            @media only screen and (min-width: 600px) {
                .contents {
                    background: green;
                }
                .text {
                    display: inline-block;
                    width: 50%;
                }
    
                .controls {
                    display: inline-block;
                }
            }
    
            /* Medium devices (landscape tablets, 768px and up) */
            @media only screen and (min-width: 768px) {
                .contents {
                    background: blue;
                }
                .text {
                    display: inline-block;
                    width: 50%;
                }
    
                .controls {
                    display: inline-block;
                }
            }
    
            /* Large devices (laptops/desktops, 992px and up) */
            @media only screen and (min-width: 992px) {
                .contents {
                    background: orange;
                }
                .text h3 {
                    display: inline;
                }
    
                .text p {
                    display: inline;
                }
    
                .text {
                    display: inline-block;
                    width: 50%;
                }
    
                .controls {
                    display: inline-block;
                }
            }
    
            /* Extra large devices (large laptops and desktops, 1200px and up) */
            @media only screen and (min-width: 1200px) {
                .contents {
                    background: pink;
                }
                .text h3 {
                    display: inline;
                }
    
                .text p {
                    display: inline;
                }
    
                .text {
                    display: inline-block;
                    width: 50%;
                }
    
                .controls {
                    display: inline-block;
                }
            }
        </style>
    </head>
    <body>
        <div class="adv-signup">
            <div class="contents">
                <div class="bg">
                    <h1>test</h1>
                </div>
                <div class="text">
                    <h3>Sign up for E-News</h3>
                    <p>Leave your email and we’ll send you regular updates on programs, events and news.</p>
                </div>
    
                <div class="controls">
                    <input name="adv-sign-up-email-field" id="adv-sign-up-email-field" type="text" maxlength="255" value="Enter your email" />
                    <a href="#" class="btn"> &gt;</a>
                </div>
            </div>
        </div>
    </body>
    </html>
    
    

    Result:

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 20, 2018 9:26 AM