2018年2月16日 星期五

【Bootstrap4】media-query(lg、md、sm、xs)


<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
    <style>
      .col,.col-12{
        border:1px solid #000;
      }
      .mediaQuery{
        font-size: 50px;
      }
    </style>
  </head>
  <body>
    <div class="mediaQuery"></div>
    <div class="container">
      <div class="row justify-content-md-center"> <!--在992~1200px是置中的-->
        <div class="col col-lg-2"> 1 of 3 </div> <!--在1200px以上flex-basis是16.66%-->
        <div class="col-12 col-md-auto"> Variable width content </div> <!--在992~1200px寬度自動--->
        <div class="col col-lg-2"> 3 of 3 </div><!--在1200px以上flex-basis是16.66%-->
      </div>
      <div class="row"><!--justify-content預設是flex-start-->
        <div class="col"> 1 of 3 </div>
        <div class="col-12 col-md-auto"> Variable width content </div><!--在992~1200px寬度自動--->
        <div class="col col-lg-2"> 3 of 3 </div><!--在1200px以上flex-basis是16.66%-->
      </div>
    </div>
    <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
    <script>
      $(window).resize(function(){
        var width = $(window).width();
        if( width >= 1200){
           $('.mediaQuery').text('lg');
        }else if(width < 1200 && width >= 992){
           $('.mediaQuery').text('md');
        }else if(width < 992 && width >= 768){
           $('.mediaQuery').text('sm');
        }else if(width < 767){
           $('.mediaQuery').text('xs');
        }
      });
    </script>
  </body>
</html>

See the Pen QQOowL by Jerry (@fenture) on CodePen.

沒有留言:

張貼留言