表格将横向增长而非纵向。

huangapple go评论70阅读模式
英文:

Form Will Grow Horizontally Not Vertically

问题

我正在尝试制作一个计算器,目前正在处理HTML和CSS。我正在尝试使计算器在垂直和水平方向上变大。我可以轻松增加宽度以适应容器,可以使用width: 100%或flex: 1 1 100%; 但是,每当我尝试增加高度,使用height: 100%; 它就会超出容器,并且输入按钮变得非常大。我已经尝试使用flex-basis和flex-grow来使其垂直增长,但没有成功。

<body>
    <div class="container">
        <form>
            <div class="display">
                <input type="text" name="display">
            </div>
            <div class="column1">
                <input type="button" value="AC">
                <input type="button" value="+/-">
                <input type="button" value="%">
                <input type="button" value="/">
            </div>
            <div class="column2">
                <input type="button" value="7">
                <input type="button" value="8">
                <input type="button" value="9">
                <input type="button" value="*">
            </div>
            <div class="column3">
                <input type="button" value="4">
                <input type="button" value="5">
                <input type="button" value="6">
                <input type="button" value="-">
            </div>
            <div class="column4">
                <input type="button" value="1">
                <input type="button" value="2">
                <input type="button" value="3">
                <input type="button" value="+">
            </div>
            <div class="column5">
                <input type="button" value="0">
                <input type="button" value=".">
                <input type="button" value="=">
            </div>
        </form>
    </div>
</body>
html {
    height: 100%;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0;
    height: 100%;
}

.container {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    height: 50%;
    width: 30%;
}

form {
    flex: 0 1 100%;
}

.column1, .column2, .column3, .column4, .column5, .display {
    display: flex;
    height: 100%;
}

.column1 input, .column2 input, .column3 input, .column4 input, .column5 input, .display input {
    flex: 1 1 100%;
}
英文:

I am attempting to make a calculator and I am working through the HTML and CSS currently. I am trying to make the calculator bigger both vertically and horizontally. I can easily increase the width to fit the container either using width: 100% or flex: 1 1 100%; However, whenever I try to increase the height with height: 100%; it goes outside of its container and the input buttons become huge. I have tried to use flex-basis and flex-grow to make it grow vertically as well and I can not.

&lt;body&gt;
&lt;div class=&quot;container&quot;&gt;
&lt;form&gt;
&lt;div class=&quot;display&quot;&gt;
&lt;input type=&quot;text&quot; name=&quot;display&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;column1&quot;&gt;
&lt;input type=&quot;button&quot; value=&quot;AC&quot;&gt;
&lt;input type=&quot;button&quot; value=&quot;+/-&quot;&gt;
&lt;input type=&quot;button&quot; value=&quot;%&quot;&gt;
&lt;input type=&quot;button&quot; value=&quot;/&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;column2&quot;&gt;
&lt;input type=&quot;button&quot; value=&quot;7&quot;&gt;
&lt;input type=&quot;button&quot; value=&quot;8&quot;&gt;
&lt;input type=&quot;button&quot; value=&quot;9&quot;&gt;
&lt;input type=&quot;button&quot; value=&quot;*&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;column3&quot;&gt;
&lt;input type=&quot;button&quot; value=&quot;4&quot;&gt;
&lt;input type=&quot;button&quot; value=&quot;5&quot;&gt;
&lt;input type=&quot;button&quot; value=&quot;6&quot;&gt;
&lt;input type=&quot;button&quot; value=&quot;-&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;column4&quot;&gt;
&lt;input type=&quot;button&quot; value=&quot;1&quot;&gt;
&lt;input type=&quot;button&quot; value=&quot;2&quot;&gt;
&lt;input type=&quot;button&quot; value=&quot;3&quot;&gt;
&lt;input type=&quot;button&quot; value=&quot;+&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;column5&quot;&gt;
&lt;input type=&quot;button&quot; value=&quot;0&quot;&gt;
&lt;input type=&quot;button&quot; value=&quot;.&quot;&gt;
&lt;input type=&quot;button&quot; value=&quot;=&quot;&gt;
&lt;/div&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;/body&gt;
html {
height: 100%;
}
body {
display: flex;
justify-content: center;
align-items: center;
margin: 0;
height: 100%;
}
.container {
display: flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
height: 50%;
width: 30%;
}
form {
flex: 0 1 100%;
}
.column1, .column2, .column3, .column4, .column5, .display {
display: flex;
height: 100%;
}
.column1 input, .column2 input, .column3 input, .column4 input, .column5 input, .display input {
flex: 1 1 100%;
}

答案1

得分: 1

这是如何做到的:

.container{
    /* 高度: 50%; */
    宽度: 100%;
}

.column1, .column2, .column3, .column4, .column5, .display{
    高度: calc(100vh/6);
    /* 将视窗高度分配给6个列 */
}
英文:

Here is how you can do it:

.container{
/* height: 50%; */
width: 100%;
}
.column1, .column2, .column3, .column4, .column5, .display{
height: calc(100vh/6);
/* Distributing the viewport height within 6 columns */
}

huangapple
  • 本文由 发表于 2023年6月26日 01:28:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76551651.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定