Search code examples
csstwitter-bootstrapmedia-queries

Set CSS class equal BootStrap class with media query


Hoping this is a simple CSS question. I have the following BootStrap button which I want to make smaller for smaller screen sizes (see below). In essence I what to change the class to "btn btn-default btn-xs"

<button type="button" class="btn btn-default btn-sm" id="myButton" >
    <span class="glyphicon glyphicon-envelope"></span>
</button>

I assume I have to use a media query. Can I somehow set my class to be equal to the bootstrap classes by using the ID selector? ( see pseudo code below )

@media only screen and (max-width: 450px) {

    #myButton {
        .btn .btn-default .btn-xs // Inject magic here
    }
}

Thanks


Solution

  • Here is the way that you would control the css of #myButton via @media queries.

    <button type="button" class="btn btn-default btn-sm" id="myButton" >
        <span class="glyphicon glyphicon-envelope"></span>
    </button>
    
    @media only screen and (max-width: 450px) {
    
        #myButton {
            font-size: 12px;
        }
    }
    
    @media only screen and (max-width: 768px) {
    
        #myButton {
               font-size: 16px; 
        }
    }