html - 横向和纵向的 CSS Bootstrap 设置按钮宽度

标签 html css twitter-bootstrap

我希望在容器中将多个按钮设置为等宽。我还希望让按钮在横向模式或更宽的屏幕下调整大小。我怎样才能做到这一点?

我想要实现的目标如下

enter image description here

enter image description here

但是当我把它切换回 Potrait 时我得到了什么

enter image description here

代码在 JSFiddle JSFiddle Code

    <!-- Bootstrap core CSS -->
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

   .card{
        border:0px solid;
        position:relative;
        height:200px;
        background:url("https://preview.ibb.co/kJvJ5e/1847p.png") no-repeat top center;
        background-size:cover;
    }
    
    .card img {
      width:100%;
    }
    
    .search-box {
      position : absolute;
      display:inline-block;
      bottom:-30px;
      left:0;
      right:0;
      padding:15px;
      text-align:center;
    }

    .drop-shadow {
        -webkit-box-shadow: 0 0 2px 2px rgba(0, 0, 0, .5);
        box-shadow: 0 0 10px 1px rgb(211, 211, 211, 0.8);
        border-radius:0px;
    }
    .container-fluid{
        width:auto
    }
    .container-fluid.drop-shadow {
        margin-top:2%;
        margin-left:5%;
        margin-right:5%

    }

    #child{
            width:100%;
            height: 20px;
            margin: auto;
            text-align: center;
            margin-top: 40px;
    }
    .form-group {
      width:100%;
      margin-bottom:10px;
    }
    .btn-checkin{
        display: inline-block;
        text-align: center;
        white-space: nowrap;
        color: #fff;
        border-color: #EC008c;
        text-transform: uppercase;
        background-color: #EC008c;
        font-family:'Open Sans','Helvetica Neue',Arial,sans-serif;
        padding: 0.375rem .75rem;
        font-size: 13px;
        border-radius: .25rem;
    }

    .icon-addon {
      position:relative;
    }
    .icon-addon label {
        position: absolute;
        left: 2px;
        top: 2px;
        padding: 8px;
        font-size: 20px;
    }
    .icon-addon input {
        height:40px;
        padding-left:35px;
    }
    .currentposition{
        position: -webkit-sticky;
        position: sticky;
        right:20px
    }

    .wrap {
        width: 100%;
        height: 50px;
        padding-top: 10px;
        padding-bottom:10px;
        text-align: center;
    }
    button{
        margin-left: 15px;
        display: inline-block;
        text-align: center;
        white-space: nowrap;
        color: #000000;
        border-color: #B9E5fB;
        text-transform: uppercase;
        background-color: #B9E5fB;
        font-family:'Open Sans','Helvetica Neue',Arial,sans-serif;
        padding: 10px 10px;
        font-size: 13px;
        border-radius: 10px;
        width:20%;
    }
     button:first-child{
        margin-left: 0;
    } 

  <body id="page-top" style="font-family:Arial">

 <div class="card" >
    <div class="search-box">
        <div class="form-group">
            <div class="icon-addon addon-lg">
                <input type="text" placeholder="Search classes" class="form-control" id="searchBar">
                <label for="searchBar" class="glyphicon glyphicon-search" rel="tooltip" title="searchBar"></label>
            </div>
        </div>
        <button class="btn-checkin" style="font-family:Arial">Check in</button>
    </div>
</div>
<div id="child">
    <div class="container-fluid">
        <img src="img/location.png" class="pull-left" style="width:25px;height:20px;padding-left:10px" />
        <p class="pull-left" style="padding-left:10px;font-family:Arial">Current Location <b>Sri Petaling</b></p>
    </div>
    <div class="container-fluid drop-shadow">
        <div class="media">
          <div class="media-left">
            <a href="#">
              <img class="media-object" src="img/7557.jpg" style="width:104px;height:64px;padding:10px 10px 10px 5px" alt="Generic placeholder image">
            </a>
          </div>
          <div class="media-body">
            <h5 class="media-left" style="padding-top:12px;color:#B9E5fB;font-family:Arial" >PERSONAL TRAINING</h5>
            <p class="pull-left" style="font-size:12px;font-family:Arial;padding-top:3px">Strike Academy Fitness</p>
          </div>
        </div>
    </div>
    <div class="container-fluid drop-shadow" style="margin-top:20px">
        <div class="container">
            <p class="pull-left" style="font-size:12px;font-family:Arial;padding-top:3px">Plan your time</p>
        </div>
        <div class="wrap"> 
            <button>All</button>
            <button >Morning</button>
            <button >Afternoon</button>
        </div>
        <div class="wrap"> 
            <button>Evening</button>  
            <button>Tomorrow</button>
            <button>This Week</button>
        </div>
    </div>
</div> 


</body>

结果仍然无效?请帮忙

enter image description here

最佳答案

您可以使用 Bootstrap 网格来实现您的目标。将您的按钮包裹在 Bootstrap 列中,如下所示。这会创建等宽的列,并且您的按钮位于每个列中。

<div class="row">
  <div class="col"> <button class="mybtn"> All </button> </div>
  <div class="col"> <button class="mybtn">Morning</button> </div>
  <div class="col"> <button class="mybtn">Afternoon</button> </div>
</div>

您可以通过提供边距来增加按钮之间的间距:

.mybtn
{
  margin:0 5px;
}

阅读更多 Here

关于html - 横向和纵向的 CSS Bootstrap 设置按钮宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51700592/

相关文章:

javascript - 如何在不使用 <form> 的情况下将 action = "/#"添加到按钮?

javascript - 在 AngularJS 中获取选定的选项

html - 根据数量自动在包装器中隔开 div

html - 查询和背景图像的 css 层次结构

HTML/CSS - 打印样式,背景不会显示?

css - 在窗口调整大小时垂直移动 div block

html - 使用 HTML5 的 Windows 8 AdControl

javascript - 检索完整的 HTML 标签 'signature'

javascript - 如何防止打开多个弹出窗口?

css - Twitter bootstrap RC2 和 jquery 选择 2 个意外的边距和填充