Set CSS class equal BootStrap class with media query [duplicate]

做~自己de王妃 提交于 2019-12-12 04:49:51

问题


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


回答1:


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; 
    }
}



回答2:


There are some great answers to your question here: resize buttons responsively in bootstrap

Personally, I like to make buttons size responsively using the view width attribute.

#myButton {
    width: 20vw;
    padding: 10px;
    }


来源:https://stackoverflow.com/questions/45045611/set-css-class-equal-bootstrap-class-with-media-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!