-1

I have a div tag with .col-xs-12 .col-md-4 and .left. I want that when the application is started in a pc, the application use the CSS for .col-md-4 .left, and when is started in a smarthphone, only use .col-xs-12 CSS.

I already test this:

.col-md-4.left {
  text-align: left;
}

.col-xs-12 {
  text-align: center;
}
<div class="col-xs-12 col-md-4 left">
  My Test
</div>

The idea is that when the application is in a pc, the div will be a .col-md-4 with text-align: left, and in a smarthphone will be -col-xs-12 with text-align: center

Kiran Mistry
  • 2,614
  • 3
  • 12
  • 28
jdflores
  • 407
  • 7
  • 25

4 Answers4

2

Try using media queries, you can put specific breakpoints.

Reference : https://www.w3schools.com/css/css_rwd_mediaqueries.asp

    <!DOCTYPE html>
    <html>
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
    .example {
      padding: 20px;
      color: white;
    }
    /* Extra small devices (phones, 600px and down) */
    @media only screen and (max-width: 600px) {
      .example {background: red;}
    }
    
    /* Small devices (portrait tablets and large phones, 600px and up) */
    @media only screen and (min-width: 600px) {
      .example {background: green;}
    }
    
    /* Medium devices (landscape tablets, 768px and up) */
    @media only screen and (min-width: 768px) {
      .example {background: blue;}
    } 
    
    /* Large devices (laptops/desktops, 992px and up) */
    @media only screen and (min-width: 992px) {
      .example {background: orange;}
    } 
    
    /* Extra large devices (large laptops and desktops, 1200px and up) */
    @media only screen and (min-width: 1200px) {
      .example {background: pink;}
    }
    </style>
    </head>
    <body>
    
    <h2>Typical Media Query Breakpoints</h2>
    <p class="example">Resize the browser window to see how the background color of this paragraph changes on different screen sizes.</p>
    
    </body>
    </html>
Charlene Vas
  • 723
  • 1
  • 9
  • 21
1

You can use both col-xs-12 and col-md-4, bootstrap works on both classes. Here is my bootstrap4 website, I am also a beginner of bootstrap-css developer, so I make this bootstrap-css website.

Hope you will be another good bootstraper!

Henry
  • 21
  • 1
  • 3
0

Use this class text-center text-md-left

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="col-xs-12 col-md-4 text-center text-md-left">
  My Test
</div>

more info

Lalji Tadhani
  • 14,041
  • 3
  • 23
  • 40
0

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="col-xs-12 col-md-4 text-md-left text-center">
  My Test
</div>

You can remove those css and add these two class text-md-left text-center. Note this only works in bootstrap4.

Prabin Sapal
  • 346
  • 1
  • 9