Bootstrap 3 only for mobile

后端 未结 3 754
余生分开走
余生分开走 2021-01-30 16:10

I have a site 1600px wide and I want to make that fit nicely on mobile only. How can I do with Bootstrap 3. I tried to use col-sm-*. but also effects o

相关标签:
3条回答
  • 2021-01-30 16:51

    You can create a jQuery function to unload Bootstrap CSS files at the size of 768px, and load it back when resized to lower width. This way you can design a mobile website without touching the desktop version, by using col-xs-* only

    function resize() {
    if ($(window).width() > 767) {
    $('link[rel=stylesheet][href~="bootstrap.min.css"]').prop('disabled', true);
    $('link[rel=stylesheet][href~="bootstrap-theme.min.css"]').prop('disabled', true);
    }   
    else {
    $('link[rel=stylesheet][href~="bootstrap.min.css"]').prop('disabled', false);
    $('link[rel=stylesheet][href~="bootstrap-theme.min.css"]').prop('disabled', false);
    }
    }
    

    and

    $(document).ready(function() {
    $(window).resize(resize);
    resize();   
    
    if ($(window).width() > 767) {
    $('link[rel=stylesheet][href~="bootstrap.min.css"]').prop('disabled', true);
    $('link[rel=stylesheet][href~="bootstrap-theme.min.css"]').prop('disabled', true);
    }
    });
    
    0 讨论(0)
  • 2021-01-30 16:59

    If you're looking to make the elements be 33.3% only on small devices and lower:

    This is backwards from what Bootstrap is designed for, but you can do this:

    <div class="row">
        <div class="col-xs-4 col-md-12">.col-xs-4 .col-md-12</div>
        <div class="col-xs-4 col-md-12">.col-xs-4 .col-md-12</div>
        <div class="col-xs-4 col-md-12">.col-xs-4 .col-md-12</div>
    </div>
    

    This will make each element 33.3% wide on small and extra small devices but 100% wide on medium and larger devices.

    JSFiddle: http://jsfiddle.net/jdwire/sggt8/embedded/result/

    If you're only looking to hide elements for smaller devices:

    I think you're looking for the visible-xs and/or visible-sm classes. These will let you make certain elements only visible to small screen devices.

    For example, if you want a element to only be visible to small and extra-small devices, do this:

    <div class="visible-xs visible-sm">You're using a fairly small device.</div>
    

    To show it only for larger screens, use this:

    <div class="hidden-xs hidden-sm">You're probably not using a phone.</div>
    

    See http://getbootstrap.com/css/#responsive-utilities-classes for more information.

    0 讨论(0)
  • 2021-01-30 17:00

    I found a solution wich is to do:

    <span class="visible-sm"> your code without col </span>
    <span class="visible-xs"> your code with col </span>
    

    It's not very optimized but it works. Did you find something better? It really miss a class like col-sm-0 to apply colons just to the xs size...

    0 讨论(0)
提交回复
热议问题