Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Css id's don't change on media queries

My media query isn't updating properly. Here is test html:

 <!DOCTYPE HTML>

<html>
    <head>
        <link rel="stylesheet" type="text/css" href="main.css">
        <title>Test </title>
    </head>
    <body>
        <div class="row">
            <div id="verde" class="col-5">
                <h2>Lorem Site</h2>
                <h3>Test Site</h3>
            </div>
        </div>
        <div class="row">
<div class="col-12">
    <p>Bacon ipsum dolor sit amet pastrami ribeye sausage, sirloin short ribs pork belly strip steak tenderloin boudin. Landjaeger beef ham hock, doner bacon pork belly filet mignon tenderloin short loin beef ribs tongue. Bresaola salami short ribs venison, pastrami jerky landjaeger. Hamburger meatball cow pork loin ham. Sirloin tail venison jerky kevin. Turducken ribeye sirloin fatback tenderloin short loin. Boudin sirloin tail venison filet mignon rump leberkas landjaeger bacon shank beef ribs ground round. Tail boudin landjaeger rump, chuck shankle leberkas pork belly pork tongue brisket short ribs ground round. Strip steak jowl pork loin beef ribs, ribeye tail spare ribs rump</p>
</div>
        </div>
        <div class="row">

<div id="verde" class="col-4">
                <p> Col 4Bacon ipsum dolor sit amet pastrami ribeye sausage, sirloin short ribs pork belly strip steak tenderloin boudin. Landjaeger beef ham hock, doner bacon pork belly filet mignon tenderloin short loin beef ribs tongue. Bresaola salami short ribs venison, pastrami jerky landjaeger. Hamburger meatball cow pork loin ham. Sirloin tail venison jerky kevin. Turducken ribeye sirloin fatback tenderloin short loin. Boudin sirloin tail venison filet mignon rump leberkas landjaeger bacon shank beef ribs ground round. Tail boudin landjaeger rump, chuck shankle leberkas pork belly pork tongue brisket short ribs ground round. Strip steak jowl pork loin beef ribs, ribeye tail spare ribs rump</p>
            </div>
            <div id="verde" class="col-4">
                <p>Bacon ipsum dolor sit amet pastrami ribeye sausage, sirloin short ribs pork belly strip steak tenderloin boudin. Landjaeger beef ham hock, doner bacon pork belly filet mignon tenderloin short loin beef ribs tongue. Bresaola salami short ribs venison, pastrami jerky landjaeger. Hamburger meatball cow pork loin ham. Sirloin tail venison jerky kevin. Turducken ribeye sirloin fatback tenderloin short loin. Boudin sirloin tail venison filet mignon rump leberkas landjaeger bacon shank beef ribs ground round. Tail boudin landjaeger rump, chuck shankle leberkas pork belly pork tongue brisket short ribs ground round. Strip steak jowl pork loin beef ribs, ribeye tail spare ribs rump</p>
            </div>
            <div class="col-4">cOL4
                <p>Bacon ipsum dolor sit amet pastrami ribeye sausage, sirloin short ribs pork belly strip steak tenderloin boudin. Landjaeger beef ham hock, doner bacon pork belly filet mignon tenderloin short loin beef ribs tongue. Bresaola salami short ribs venison, pastrami jerky landjaeger. Hamburger meatball cow pork loin ham. Sirloin tail venison jerky kevin. Turducken ribeye sirloin fatback tenderloin short loin. Boudin sirloin tail venison filet mignon rump leberkas landjaeger bacon shank beef ribs ground round. Tail boudin landjaeger rump, chuck shankle leberkas pork belly pork tongue brisket short ribs ground round. Strip steak jowl pork loin beef ribs, ribeye tail spare ribs rump</p>
            </div>
        </div>
    </body>

</html>

Here is my CSS

    @media screen and (max-width:760px){
     #verde{
        color:red;
    }
}
*{
    border: 1px solid red !important;
}
*{
    box-sizing:border-box;
}

p {
    margin: 10px;
}
#verde{
    color:green;
}
.row{
    width: 100%;
    margin:auto;
    display: flex;
    flex-wrap:wrap;
}
.col-1{
    width: 8.33%;
}
.col-2{
    width: 16.66%;
}
.col-3{
    width: 25%;
}
.col-4{
    width: 33.33%;

}
.col-5{
    width: 41.66%;
    margin-left:auto;
}
.col-6{
    width: 50%;
}
.col-7{
    width: 58.33%;
}
.col-8{
    width: 66.66%;
}
.col-9{
    width: 75%;
}
.col-10{
    width: 83.33%;
}
.col-11{
    width: 91.66%;
}
.col-12{
    width: 100%;
    margin-left:20%;
}

Now,in the media query i want to change the id #verde to the color red. This method don't work,it only works if i am more specific for example i use

 body #verde

or I specific the class and the id. The question is Why it works only if i'm more specific?

Thanks in Advance

like image 723
cdm Avatar asked Dec 08 '22 03:12

cdm


1 Answers

You need to place the media query at the end of your stylesheet as that's the way the styles are "cascading"

Currently your media queries are first, so anything after that isn't more specific is getting overwritten.

...Everything before...

 @media screen and (max-width:760px){
     #verde{
        color:red;
    }
}

Here's a JSFiddle where I rearranged your CSS.

like image 97
Mathias Rechtzigel Avatar answered Dec 23 '22 15:12

Mathias Rechtzigel