html5 – 如何在bootstrap3中创建响应按钮?

前端之家收集整理的这篇文章主要介绍了html5 – 如何在bootstrap3中创建响应按钮?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图为768px屏幕显示btn-sm,但它一直向我显示btn-xs.

这是我的HTML代码

<div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3 col-sm-offset-3">
    <button name="magnet" class="btn btn-success btn-sm btn-xs btn-lg">
        <em class="glyphicon glyphicon-home"></em>
        Home
    </button>

    <button name="magnet" class="btn btn-danger btn-sm btn-xs">
        <em class="glyphicon glyphicon-download"></em>
        Download
    </button>
</div>

是否可以在不使用媒体查询的情况下完成此任务?

解决方法

您的按钮不会仅使用HTML进行神奇缩放.所以你有两个选择.

选项#1:重复

这个是最丑陋的,但它不符合您的需求,因为它不需要额外的媒体查询

<div class="container">
  <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3 col-sm-offset-3">
    <button name="magnet" class="btn btn-success btn-xs visible-xs"><em class="glyphicon glyphicon-home"></em> Home</button>
    <button name="magnet" class="btn btn-success btn-sm visible-sm"><em class="glyphicon glyphicon-home"></em> Home</button>
    <button name="magnet" class="btn btn-success btn-lg visible-md visible-lg"><em class="glyphicon glyphicon-home"></em> Home</button>

    <button name="magnet" class="btn btn-danger btn-xs visible-xs"><em class="glyphicon glyphicon-download"></em> Download</button>
    <button name="magnet" class="btn btn-danger btn-sm visible-sm"><em class="glyphicon glyphicon-download"></em> Download</button>
    <button name="magnet" class="btn btn-danger btn-lg visible-md visible-lg"><em class="glyphicon glyphicon-download"></em> Download</button>
  </div>
</div>

Bootply

选项#2:媒体查询

而且……最后.这是执行此操作的正确方法.

<div class="container">
  <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3 col-sm-offset-3">
    <button name="magnet" class="btn btn-success btn-autosize">
      <em class="glyphicon glyphicon-home"></em> 
      Home
    </button>

    <button name="magnet" class="btn btn-danger btn-autosize">
      <em class="glyphicon glyphicon-download"></em> 
      Download
    </button>
  </div>
</div>
.btn-autosize {
  padding: 1px 5px;
  font-size: 12px;
  line-height: 1.5;
  border-radius: 3px;
}
@media screen and (min-width: 768px) {
  .btn-autosize {
    padding: 5px 10px;
    font-size: 12px;
    line-height: 1.5;
    border-radius: 3px;
  }
}
@media screen and (min-width: 992px) {
  .btn-autosize {
    padding: 10px 16px;
    font-size: 18px;
    line-height: 1.33;
    border-radius: 6px;
  }
}

Bootply

原文链接:/html5/241014.html

猜你在找的HTML5相关文章