With Bootstrap CSS you can define buttons to be large, small, or normal. However, in some cases I would like to use large buttons (that is, add the btn-lg
class) conditionally, as in, only if the screen size is md
or larger.
A clumsy workaround is to include the button twice: once with btn-lg
and once without, the regular one with visible-xs-(something)
and the large one with hidden-xs
, see live example.
Is there a smarter way to do this? Can I define a button to use the btn-lg
class only on certain display sizes, or is there some kind of ‘auto size class’ that effectively results in btn-lg in some cases and regular buttons in others?
2
Answers
I think you can use CSS for this:
Example (btn-sm on xs screen, btn on sm screen and btn-lg on md and lg screen)
HTML:
CSS:
Create a new custom class and apply the rules you want to the media breakpoints you’d like them to trigger on. Then you can use that class and also use the individual classes without them colliding with one another.
See working example Snippet.