Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do you prevent a button from getting smaller, when changing from a div to a button?

I have no idea what would fix this.

https://jsfiddle.net/eL5gn73s/

That big one is a div, the small ones are the buttons that have shrunk.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The button should be the same size as the div, not the other way around.

After changing from a div to a button, the button shrunk smaller than the size of the div that was 47px.

.box {
  position: relative;
  background: red;
  width: 47px;
  height: 47px;
  border-radius: 4px;
  border-width: 4px;
  border-style: solid;
  border-top-color: rgba(255, 255, 255, 0.5);
  border-left-color: rgba(0, 0, 0, 0.3);
  border-right-color: rgba(0, 0, 0, 0.3);
  border-bottom-color: rgba(0, 0, 0, 0.8);
}

.box.box2 {
  background: red;
}
<button class="box box2" type="button"></button>
<button class="box " type="button"></button>

<div class="box"></div>

>Solution :

Give them both a display:block (or inline-block) and add box-sizing:content-box to both, then add box-sizing to both (border-box)

div.exit,
button.exit {
  display: block;
  box-sizing: content-box;
}
/*add element just for specificity here */
button.exit,
div.exit {
  box-sizing: border-box;
  margin: 0;
  background: red;
  width: 47px;
  height: 47px;
  border-radius: 4px;
  border-width: 4px;
  border-style: solid;
  border-top-color: rgba(255, 255, 255, 0.5);
  border-left-color: rgba(0, 0, 0, 0.3);
  border-right-color: rgba(0, 0, 0, 0.3);
  border-bottom-color: rgba(0, 0, 0, 0.8);
}

.exit.exitPage2 {
  background: red;
}
<button class="exit exitPage2" type="button"></button>
<button class="exit " type="button"></button>

<div class="exit"></div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading