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 to auto padding?

How to make like anchor, button auto padding fill entire parent available space? I think this problem already exist long time ago.

body { margin: initial }

.grid {
  display: grid;
  grid-template-columns: auto auto auto;
  column-gap: 10px;
}

.grid > div {
  text-align: center;
  background-color: bisque;
}

.grid > div > a {
  box-sizing: border-box;
  background-color: red;
  padding: 0 10px 0 10px;
}
<div class="grid">
  <div><a href="">1</a></div>
  <div><a href="">2</a></div>
  <div><a href="">3</a></div>
</div>

>Solution :

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

Just add flex-grow: 1 to the anchor to fill out the entire parents space. However this requires that the parent is declared as flexbox: display: flex

.grid > div {
  display: flex;
}

.grid > div > a {
  flex-grow: 1;
}


/* original CSS */
body { margin: initial }

.grid {
  display: grid;
  grid-template-columns: auto auto auto;
  column-gap: 10px;
}

.grid > div {
  text-align: center;
  background-color: bisque;
}

.grid > div > a {
  box-sizing: border-box;
  background-color: red;
  padding: 0 10px 0 10px;
}
<div class="grid">
  <div><a href="">1</a></div>
  <div><a href="">2</a></div>
  <div><a href="">3</a></div>
</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