Wrap the jagged keys in your own containers for flexible containers and from there ...
* { box-sizing: border-box; } .flexBoxContainer { display: flex; justify-content: space-around; align-items: center; width: 100%; } .calculator { display: flex; flex-wrap: wrap; justify-content: center; align-content: center; width: 100%; } .calculator .keys { border: red 1px solid; height: 50px; width: 25%; break-inside: avoid; } .calculator input { height: 100px; width: 100%; direction: rtl; } #anomaly-keys-wrapper { display: flex; width: 100%; } #anomaly-keys-wrapper > section:first-child { display: flex; flex-wrap: wrap; width: 75%; } #anomaly-keys-wrapper > section:first-child > div { flex: 1 0 33.33%; } #anomaly-keys-wrapper > section:first-child > div:nth-child(4) { flex-basis: 66.67%; } #anomaly-keys-wrapper > section:last-child { width: 25%; display: flex; flex-direction: column; } #anomaly-keys-wrapper .tall { width: 100%; flex: 1; } @media (min-width: 321px) { .calculator { width: 320px; } }
<div class="flexBoxContainer"> <div class="calculator"> <input /> <div class="keys"></div> <div class="keys"></div> <div class="keys"></div> <div class="keys"></div> <div class="keys"></div> <div class="keys"></div> <div class="keys"></div> <div class="keys"></div> <div class="keys"></div> <div class="keys"></div> <div class="keys"></div> <div class="keys"></div> <section id="anomaly-keys-wrapper"> <section> <div class="keys"></div> <div class="keys"></div> <div class="keys"></div> <div class="keys long"></div> <div class="keys"></div> </section> <section> <div class="keys tall"></div> </section> </section> </div> </div>
Revised Codepen (with compiled CSS)
Notes:
- Include padding and borders in
width
/ height
calculations. - Wrap the jagged keys in a separate container for flexible containers (default
flex-direction: row
and flex-wrap: nowrap
) - Wrap the long key in a separate flexible container with the packaging on (and take enough siblings to create an equal height with a high key).
- Configure the three keys on the max string.
- Make a long key twice the width of your siblings. (Did not use a simpler
long
selector due to weaker specificity.) - Insert the high key into a separate floppy disk container with a vertical orientation.
- Making a high key consumes the entire available width and height of the container.
UPDATE
From the comments:
Hi 1. Can you explain to me how the bend base works? and why you used it instead of giving width to a long button. 2. Why is it necessary to give flex: 1; to the high button, since I read this default value.
Question number 1:
The keys in the first subsection container (containing .long
) have a flex: 1 0 33.33%
size of flex: 1 0 33.33%
.
This is short for flex-grow: 1
, flex-shrink: 0
and flex-basis: 33.33%
.
For the .long
key .long
we simply redefine the flex-basis
component 66.67%
. (no need to re-declare two other components).
In addition, there is no difference in this case between width
and flex-basis
, but since we are redefining flex-basis
, I used flex-basis
.
Using width
will leave the original flex-basis: 33.33%
intact, creating two width
rules that may therefore not expand the .long
, depending on which rule prevails in the cascade.
For a full explanation of flex-basis
vs. width
see. What is the difference between a flexible base and a width?
Question number 2:
Since the initial value of the flex-grow
component is 0
( source ).
source share