I’m trying to test bootstrap 3 grid system. Two columns in a row. In extra small devices like mobiles, it’ll be stacked in one column and in small devices like in tablets, it’ll be in 2 columns. But it’s not working accordingly in mobile devices. In mobile devices, it’ showing in 2 columns whereas it should show in 1 column. Anything wrong in my code? Thanks.
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" />
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-xs-12 col-sm-6">
<p>Item 1</p>
</div>
<div class="col-xs-12 col-sm-6">
<p>Item 2</p>
</div>
</div>
</div>
</body>
</html>
3
Answers
hidden-xs
will hide the things in small screen.col-sm-6
will automatically takewidth:100%
for screen below767px
; So.col-xs-12
not required to include.HTML:
Remove the
class="hidden-xs"
B’coz its hide the content when screen size is extra-small.you are close but you are using wrong column sizes.
If you want column to be 100% on tablets (small devices) and below you shouldn’t use
col-sm-6
as it will still be on 2 columns on tablets, you should usecol-sm-12
, orcol-md-6
–col-md-6
is saying that on desktop (medium) devices, 992px and above, that column width should be 50%, and below it should be 100%.You also hide everything on mobiles (extra small ‘xs’ devices) with
hidden-xs
!So try this code:
Again we don’t need to use
col-sm-12
as all sizes below smallest specified (in this case md-medium) are automatically 100%, this comes from mobile first design principle.