Solved

bootstrap add a css class in media query

Posted on 2014-09-30
3
1,521 Views
Last Modified: 2014-10-04
I have a button group div #xxx

In side my css class file , I am trying to write a media query

@media (min-width: 768px) and (max-width: 992px) {
    div#xxx {
         - here I need to add "btn-group-lg" class
    }
}


@media (min-width: 992px) {
     div#xxx {
         - here I need to add "btn-group-sm" class
   
}

I am not able to do so, is there any way of adding a css class inside css file
0
Comment
Question by:yadavdep
  • 2
3 Comments
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 40351631
I'm not sure if I understood what you want but...
You're using SASS?
And you have to style a div like: <div id="xxx" class="btn-group-sm">

In SASS you can do:
@media (min-width: 992px) {
     div#xxx {
         &.btn-group-sm {

         }
}

Open in new window

& before the class name means that that class is at the same level as the "container"
0
 

Author Comment

by:yadavdep
ID: 40351644
I am in an asp.net project and in  an css file I want to add a specific class to my div on a specific screen size .
If the screen is small then I want to add other class  "btn-group-sm"
0
 
LVL 30

Accepted Solution

by:
Alexandre Simões earned 500 total points
ID: 40351661
Well, it doesn't work like that.
Unless you want to do that with javascript, your pure css way to do that is to hide/show the groups depending on the media size:
  <body>
    <div class="hidden-xs btn-group btn-group-lg">
      <button type="button" class="btn btn-default">Left</button>
      <button type="button" class="btn btn-default">Middle</button>
      <button type="button" class="btn btn-default">Right</button>
    </div>
    <br/>
    <div class="hidden-lg btn-group btn-group-xs">
      <button type="button" class="btn btn-default">Left</button>
      <button type="button" class="btn btn-default">Middle</button>
      <button type="button" class="btn btn-default">Right</button>
    </div>
  </body>

Open in new window

0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question