Vertical buttons with equal width

独自空忆成欢 提交于 2019-12-10 22:54:53

问题


It's two vertical arrangement buttons. I need them to be of equal width. I don't know:

  • what size will on wrap;
  • what text will appear on buttons (therefore I can't use pixel width);
  • what width will on buttons.

Buttons must be at left. Text on buttons must be center-aligned. I can't use 100% width cause it will not beauty :)

I can't use flexbox and specify width to buttons. And will be cool a solution on pure CSS.

IE8+

.wrap{
    width: 100%;
    border: 1px solid red;
}

.btn{
    height 40px;
    background-color: tomato;
    margin-bottom: 10px;
    display: block;
}
<div class="wrap">
  <button class="btn">small button</button>
  <button class="btn">super long button</button>
</div>

回答1:


Just make the container inline-block and then the buttons 100% width, that way they will take the width of the largest button:

.wrap{
    display: inline-block;
    border: 1px solid red;
}

.btn{
    height 40px;
    background-color: tomato;
    margin-bottom: 10px;
    display: block;
    width:100%;
}
<div class="wrap">
  <button class="btn">small button</button>
  <button class="btn">super long button</button>
</div>



回答2:


Use inline-block for your container div!



来源:https://stackoverflow.com/questions/41693225/vertical-buttons-with-equal-width

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!