I am building a calculator with flexbox. I want one of its keys twice the height and another key twice the width.
I googled much about it but couldn't find both cases together.
For twice height key, only answers I found was to make flex-direction
as column
. But in that case I will not be able to make double width key.
Here is my code (on codepen.io). Please help.
$(function() {
var curr = "",
prev = "";
var updateView = function() {
$('#curr').html(curr);
$('#prev').html(prev);
};
$('.keysNum').on('click', function(e) {
curr += $(this).html();
console.log(this);
updateView();
});
$('.keysOp').on('click', function(e) {
});
});
.flexBoxContainer {
-webkit-touch-callout: none;
-webkit-user-select: none;
user-select: none;
display: flex;
justify-content: space-around;
align-items: center;
width: 100%;
min-height: 100vh;
}
.calculator {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-content: center;
width: 100%;
min-height: 100vh;
}
@media (min-width: 321px) {
.calculator {
width: 320px;
}
}
.calculator .keys {
border: #d3d2cb 0.5px solid;
background: #fefdff;
color: #33393d;
height: 50px;
height: 14.2857142857vh;
width: 25%;
line-height: 14.2857142857vh;
text-align: center;
font-size: 1.4rem;
font-weight: bold;
transition: background 0.2s linear;
}
.calculator .keysOp {
background: #f1f1ef;
}
.calculator .keysC {
color: #f94913;
}
.calculator .keys:hover {
background: #d3d2cb;
transition: background 0s linear;
}
.calculator .keys:focus {
outline: none;
}
.calculator .keys:active {
background: #93938E;
}
.calculator .screen {
background: #e9e8e5;
height: 14.2857142857vh;
width: 100%;
line-height: 14.2857142857vh;
direction: rtl;
}
.calculator .screen:last-child {
font-size: 4rem;
}
.calculator #anomaly-keys-wrapper {
display: flex;
width: 100%;
}
.calculator #anomaly-keys-wrapper>section:first-child {
display: flex;
flex-wrap: wrap;
width: 75%;
}
.calculator #anomaly-keys-wrapper>section:first-child>div.keys {
flex: 1 0 33.33%;
}
.calculator #anomaly-keys-wrapper>section:first-child>div.long {
flex-basis: 66.67%;
}
.calculator #anomaly-keys-wrapper>section:last-child {
width: 25%;
display: flex;
flex-direction: column;
}
.calculator #anomaly-keys-wrapper>section:last-child>.tall {
background: #f94913;
color: #fefdff;
width: 100%;
line-height: 28.5714285714vh;
flex: 1;
}
.calculator #anomaly-keys-wrapper>section:last-child>.tall:hover {
background: #c73a0f;
}
.calculator #anomaly-keys-wrapper>section:last-child>.tall:focus {
outline: none;
}
.calculator #anomaly-keys-wrapper>section:last-child>.tall:active {
background: #8b280a;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="flexBoxContainer">
<div class="calculator">
<div class="screen" id="prev"></div>
<div class="screen" id="curr"></div>
<!-- <div class="keys keysC keysOp" tabindex="2">C</div> -->
<div class="keys keysC keysOp" tabindex="2">C</div>
<div class="keys keysOp" tabindex="3"><i class="icon ion-backspace-outline"></i></div>
<div class="keys keysOp" tabindex="4">÷</div>
<div class="keys keysOp" tabindex="5">×</div>
<div class="keys keysNum" tabindex="6">7</div>
<div class="keys keysNum" tabindex="7">8</div>
<div class="keys keysNum" tabindex="8">9</div>
<div class="keys keysOp" tabindex="9">-</div>
<div class="keys keysNum" tabindex="10">4</div>
<div class="keys keysNum" tabindex="11">5</div>
<div class="keys keysNum" tabindex="12">6</div>
<div class="keys keysOp" tabindex="13">+</div>
<section id="anomaly-keys-wrapper">
<section>
<div class="keys keysNum" tabindex="14">1</div>
<div class="keys keysNum" tabindex="15">2</div>
<div class="keys keysNum" tabindex="16">3</div>
<div class="keys long keysNum" tabindex="17">0</div>
<div class="keys" tabindex="18">.</div>
</section>
<section>
<div class="keys tall" tabindex="19">=</div>
</section>
</section>
</div>
</div>
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…