Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertical buttons with equal width

Tags:

css

button

width

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>
like image 773
frontEndNoob Avatar asked Mar 11 '23 03:03

frontEndNoob


1 Answers

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>
like image 95
Pete Avatar answered Apr 01 '23 14:04

Pete