Mohan Dere
Mohan Dere

Reputation: 4597

How to make all buttons of same height via CSS?

There is an option to do it via Javascript. Also another option is by giving height through CSS height: 60px; But what if text is more?

.slider {
  width: 323px;
}
.yo-btn {
  display: inline-block;
  padding-top: 2px;
  padding-bottom: 2px;
  padding-left: 0;
  padding-right: 0;
  margin-bottom: 0;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.42857143;
  text-align: center;
  vertical-align: middle;
  -ms-touch-action: manipulation;
  touch-action: manipulation;
  cursor: pointer;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  border-radius: 0;
  background: #fff;
  border-color: #e0e0e0;
}
<div class="slider">
  <button type="button" class="yo-btn yo-btn-range" value="1" style="width: 25%;">Small</button>
  <button type="button" class="yo-btn yo-btn-range" value="3" style="width: 25%;">Slightly Large</button>
  <button type="button" class="yo-btn yo-btn-range" value="4" style="width: 25%;">Large</button>
</div>

The current output is:

Group of buttons

Upvotes: 0

Views: 4125

Answers (2)

Mohan Dere
Mohan Dere

Reputation: 4597

With cross browser solution -

.slider{
  display: -webkit-box;      /* OLD - iOS 6-, Safari 3.1-6 */
  display: -moz-box;         /* OLD - Firefox 19- (buggy but mostly works) */
  display: -ms-flexbox;      /* TWEENER - IE 10 */
  display: -webkit-flex;     /* NEW - Chrome */
  display: flex;

}

Upvotes: 0

Stickers
Stickers

Reputation: 78706

I would suggest using flexbox.

.slider {
  display: flex;
}

.slider {
  display: flex; /*ADDED*/
  width: 323px;
}
.yo-btn {
  display: inline-block;
  padding-top: 2px;
  padding-bottom: 2px;
  padding-left: 0;
  padding-right: 0;
  margin: 0 2px; /*EDITED*/
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.42857143;
  text-align: center;
  vertical-align: middle;
  -ms-touch-action: manipulation;
  touch-action: manipulation;
  cursor: pointer;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  border-radius: 0;
  background: #fff;
  border-color: #e0e0e0;
}
<div class="slider">
  <button type="button" class="yo-btn yo-btn-range" value="1" style="width: 25%;">Small</button>
  <button type="button" class="yo-btn yo-btn-range" value="3" style="width: 25%;">Slightly Large</button>
  <button type="button" class="yo-btn yo-btn-range" value="4" style="width: 25%;">Large</button>
</div>

Upvotes: 5

Related Questions