html - How to scale multiple <div> dynamically using min- and max-width? -
i have bunch of divs specific height. want width scale 2rem 2.75 rem, dependent on available space. it's noobie question can't figure out how - tried using this answer, divs don't resize. desired behaviour is:
- each of div elements use max-width, when there enough space
- when there not enough space fit divs min-space inside, should wrap
- in between 2 cases, should resize equally
html:
<div class="pagination-number--demo-multiple-numbers"> <div class="pagination-number pagination-number--smaller pagination-number--narrow-to-wide pagination-number--active "> 42 </div> ... (more elements)
css:
.pagination-number--demo-multiple-numbers { width: 100%; margin: 0 auto; } .pagination-number { font-size: 0.875rem; box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; border: 0.0625rem solid #ffffff; border-radius: 4px; display: inline-block; text-align: center; vertical-align: middle; } .pagination-number--smaller { height: 2.25rem; line-height: 2.125rem; } .pagination-number--narrow-to-wide { min-width: 2rem; max-width: 2.75rem; width: 100%; margin: 0 auto; } .pagination-number--active { font-weight: 700; background-color: #eeeeee; }
jsfiddle: https://jsfiddle.net/q5omjujd/
you flexbox. add css following 2 updated classes
css
.pagination-number--demo-multiple-numbers { width: 100%; margin: 0 auto; display: flex; flex-flow: wrap; justify-content: center; } .pagination-number { font-size: 0.875rem; border: 0.0625rem solid #ffffff; border-radius: 4px; text-align: center; flex: 1; margin: 10px; }
.pagination-number--demo-multiple-numbers { width: 100%; margin: 0 auto; display: flex; flex-flow: wrap; justify-content: center; } .pagination-number { font-size: 0.875rem; border: 0.0625rem solid #ffffff; border-radius: 4px; text-align: center; flex: 1; margin: 10px; } .pagination-number--smaller { height: 2.25rem; line-height: 2.125rem; } .pagination-number--narrow-to-wide { min-width: 2rem; max-width: 2.75rem; width: 100%; } .pagination-number--active { font-weight: 700; background-color: #eeeeee; }
<div class="pagination-number--demo-multiple-numbers"> <div class="pagination-number pagination-number--smaller pagination-number--narrow-to-wide pagination-number--active "> 42 </div> <div class="pagination-number pagination-number--smaller pagination-number--narrow-to-wide pagination-number--active "> 42 </div> <div class="pagination-number pagination-number--smaller pagination-number--narrow-to-wide pagination-number--active "> 42 </div> <div class="pagination-number pagination-number--smaller pagination-number--narrow-to-wide pagination-number--active "> 42 </div> <div class="pagination-number pagination-number--smaller pagination-number--narrow-to-wide pagination-number--active "> 42 </div> <div class="pagination-number pagination-number--smaller pagination-number--narrow-to-wide pagination-number--active "> 42 </div> <div class="pagination-number pagination-number--smaller pagination-number--narrow-to-wide pagination-number--active "> 42 </div> <div class="pagination-number pagination-number--smaller pagination-number--narrow-to-wide pagination-number--active "> 42 </div> <div class="pagination-number pagination-number--smaller pagination-number--narrow-to-wide pagination-number--active "> 42 </div> <div class="pagination-number pagination-number--smaller pagination-number--narrow-to-wide pagination-number--active "> 42 </div> </div>
Comments
Post a Comment