【问题标题】:Why can't I make button's height equal their width? [duplicate]为什么我不能让按钮的高度等于它们的宽度? [复制]
【发布时间】:2019-02-18 02:42:25
【问题描述】:

在我的网页上应该有一个面板(左侧,屏幕宽度的 25%),上面有方形按钮。 应该是这样的: My UI's design
但目前这些按钮是水平拉伸的。我需要以某种方式垂直拉伸它们。
我试图设置min-width: 100%; height: auto 使高度=宽度,但它什么也没做。还尝试使用 jquery 均衡它们 - 仍然没有。

这是我的代码:

#left_panel {
  float: left;
  width: 25%;
  text-align: center;
}

.btn {
  border-radius: 25px;
  padding: 1%;
  margin: 1%;
  background-color: green;
}

.item {
  border-radius: 10px;
  float: right;
  width: 71%;
  padding: 1%;
  margin: 1%;
  background-color: grey;
}

checkbox {
  display: inline-block;
  width: auto;
}

.name {
  display: inline-block;
  background-color: white;
  width: auto;
}

.del {
  border-radius: 25px;
  display: inline-block;
  float: right;
  background-color: red;
  width: auto;
}
<div id="left_panel">
  <div class="btn" id="open">Open</div>
  <div class="btn" id="add">Add</div>
  <div class="btn" id="info">Info</div>
</div>
<div id="list">
  <!--space for list-->
</div>

【问题讨论】:

    标签: html css css-float height


    【解决方案1】:

    您可以使用 padding-bottom: 100% 方法使它们成正方形。

    #left_panel {
      float: left;
      width: 25%;
      text-align: center;
    }
    
    .btn {
      border-radius: 25px;
      padding: 1%;
      margin: 1%;
      background-color: green;
      position: relative;
    }
    .btn span {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
    }
    .btn::after {
      content: '';
      display: block;
      padding-bottom: 100%;
    }
    
    .item {
      border-radius: 10px;
      float: right;
      width: 71%;
      padding: 1%;
      margin: 1%;
      background-color: grey;
    }
    
    checkbox {
      display: inline-block;
      width: auto;
    }
    
    .name {
      display: inline-block;
      background-color: white;
      width: auto;
    }
    
    .del {
      border-radius: 25px;
      display: inline-block;
      float: right;
      background-color: red;
      width: auto;
    }
    <div id="left_panel">
      <div class="btn" id="open"><span>Open</span></div>
      <div class="btn" id="add"><span>Add</span></div>
      <div class="btn" id="info"><span>Info</span></div>
    </div>
    <div id="list">
      <!--space for list-->
    </div>

    【讨论】:

      猜你喜欢
      • 2015-06-24
      • 2023-03-23
      • 2014-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-11
      • 2016-03-18
      相关资源
      最近更新 更多