问题
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