表格行不显示,具有 rowspan。

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

Table row is not showing with rowspan

问题

I am trying to display the full calculator but its not showing middle row:

其给出了以下输出:

表格行不显示,具有 rowspan。

But if I change the below line:

<td rowspan="1">
               <input id="buttonEnter" type="button" class="calcButton" value="enter" />
			</td>

It then show me full calculator but small enter button:

表格行不显示,具有 rowspan。

I understand that it looks rowspan is applying to all row but how to stop this,

[1]: https://i.stack.imgur.com/1hOYg.png
[2]: https://i.stack.imgur.com/c53jS.png

英文:

I am trying to display the full calculator but its not showing middle row:

Its giving me below output:

表格行不显示,具有 rowspan。

But if I change the below line:

<td rowspan="1">
               <input id="buttonEnter" type="button" class="calcButton" value="enter" />
			</td>

It then show me full calculator but small enter button:

表格行不显示,具有 rowspan。

I understand that it looks rowspan is applying to all row but how to stop this,

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

{
   -moz-box-sizing: border-box;
   -webkit-box-sizing: border-box;
   box-sizing: border-box;
}

/* reset rules */
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
   margin: 0;
   padding: 0;
   border: 0;
   font-size: 100%;
   font: inherit;
   vertical-align: baseline;
}

/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
   display: block;
}

body {
   line-height: 1;
   width: 960px;
   background: white;
   margin: 30px auto;
   font-family: Verdana, Geneva, sans-serif;
   position: relative;   
}

ol, ul {
   list-style: none;
}

/* page header */
header {
   background: #330570;
   width: 100%;
   color: #FFFFFF;
   font-size: 48px;
   text-align: center;
   line-height: 1.5em; 
}

/* main content */
article {
   width: 960px;
   height: 450px;
   text-align: left;
   background: #FFCF40;
   padding-top: 25px;
}

/* Calculator Table Styles */

table#calculator {
   background-color: rgb(211, 211, 211);

   border: 10px outset rgb(92, 92, 92);
   -moz-border-radius: 25px;
   -webkit-border-radius: 25px;
   border-radius: 25px;

   padding: 15px;
   margin: 0px auto;

   -moz-box-shadow: rgb(101, 101, 101) 20px 10px 20px;
   -webkit-box-shadow: rgb(101, 101, 101) 20px 10px 20px;
   box-shadow: rgb(101, 101, 101) 20px 10px 20px;
}


table#calculator td {
   width: 40px;
   height: 40px;
   margin: 10px;
}

table#calculator input {

   -moz-border-radius: 7px;
   -webkit-border-radius: 7px;
   border-radius: 7px;
   width: 100%;
   height: 100%;
}
table#calculator textarea {
   width: 100%;
   height: 100px;
   background-color: rgb(55, 105, 62);
   font-size: 1.4em;
   color: rgba(255, 255, 255, 0.7);
}

table#calculator td#decimalTD {
   font-size: 0.9em;
   text-align: right;
}

table#calculator input#decimals {
   width: 35px;
   height: 20px;
   background: transparent;
   text-align: center;
}

<!-- language: lang-html -->

&lt;article&gt;
  &lt;table id=&quot;calculator&quot;&gt;
    &lt;tr&gt;
      &lt;td colspan=&quot;5&quot;&gt;
        &lt;textarea id=&quot;calcWindow&quot; name=&quot;calcWindow&quot;&gt;&lt;/textarea&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;
        &lt;input id=&quot;button7&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;7&quot; /&gt;
      &lt;/td&gt;
      &lt;td&gt;
        &lt;input id=&quot;button8&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;8&quot; /&gt;
      &lt;/td&gt;
      &lt;td&gt;
        &lt;input id=&quot;button9&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;9&quot; /&gt;
      &lt;/td&gt;
      &lt;td&gt;
        &lt;input id=&quot;buttonDivide&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;/&quot; /&gt;
      &lt;/td&gt;
      &lt;td&gt;
        &lt;input id=&quot;buttonClear&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;C&quot; /&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;
        &lt;input id=&quot;button4&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;4&quot; /&gt;
      &lt;/td&gt;
      &lt;td&gt;
        &lt;input id=&quot;button5&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;5&quot; /&gt;
      &lt;/td&gt;
      &lt;td&gt;
        &lt;input id=&quot;button6&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;6&quot; /&gt;
      &lt;/td&gt;
      &lt;td&gt;
        &lt;input id=&quot;buttonMultiply&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;*&quot; /&gt;
      &lt;/td&gt;
      &lt;td rowspan=&quot;3&quot;&gt;
        &lt;input id=&quot;buttonEnter&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;enter&quot; /&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;
        &lt;input id=&quot;button1&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;1&quot; /&gt;
      &lt;/td&gt;
      &lt;td&gt;
        &lt;input id=&quot;button2&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;2&quot; /&gt;
      &lt;/td&gt;
      &lt;td&gt;
        &lt;input id=&quot;button3&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;3&quot; /&gt;
      &lt;/td&gt;
      &lt;td&gt;
        &lt;input id=&quot;buttonMinus&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;-&quot; /&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td colspan=&quot;2&quot;&gt;
        &lt;input id=&quot;button0&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;0&quot; /&gt;
      &lt;/td&gt;
      &lt;td&gt;
        &lt;input id=&quot;buttonDecimal&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;.&quot; /&gt;
      &lt;/td&gt;
      &lt;td&gt;
        &lt;input id=&quot;buttonAdd&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;+&quot; /&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;

<!-- end snippet -->

答案1

得分: 1

以下是翻译好的部分:

问题出在CSS中,而不是表格。第4/5/6/行对齐到"Enter"按钮的底部,因此被"0/./+"按钮覆盖。

在您的重置规则代码下,将这个:

vertical-align: baseline;

改为这个:

vertical-align: top;

这样就可以了。

英文:

The problem is in the CSS, not the table. The 4/5/6/ row is aligning to the bottom of the Enter button and is therefore covered by the 0/./+ buttons.

Under your reset rules code, change this:

> vertical-align: baseline;

to this:

> vertical-align: top;

and it'll work.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

{
   -moz-box-sizing: border-box;
   -webkit-box-sizing: border-box;
   box-sizing: border-box;
}

/* reset rules */
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
   margin: 0;
   padding: 0;
   border: 0;
   font-size: 100%;
   font: inherit;
   vertical-align: middle; /* &lt;--------------------------------------- HERE */
}

/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
   display: block;
}

body {
   line-height: 1;
   width: 960px;
   background: white;
   margin: 30px auto;
   font-family: Verdana, Geneva, sans-serif;
   position: relative;   
}

ol, ul {
   list-style: none;
}

/* page header */
header {
   background: #330570;
   width: 100%;
   color: #FFFFFF;
   font-size: 48px;
   text-align: center;
   line-height: 1.5em; 
}

/* main content */
article {
   width: 960px;
   height: 450px;
   text-align: left;
   background: #FFCF40;
   padding-top: 25px;
}

/* Calculator Table Styles */

table#calculator {
   background-color: rgb(211, 211, 211);

   border: 10px outset rgb(92, 92, 92);
   -moz-border-radius: 25px;
   -webkit-border-radius: 25px;
   border-radius: 25px;

   padding: 15px;
   margin: 0px auto;

   -moz-box-shadow: rgb(101, 101, 101) 20px 10px 20px;
   -webkit-box-shadow: rgb(101, 101, 101) 20px 10px 20px;
   box-shadow: rgb(101, 101, 101) 20px 10px 20px;
}


table#calculator td {
   width: 40px;
   height: 40px;
   margin: 10px;
}

table#calculator input {

   -moz-border-radius: 7px;
   -webkit-border-radius: 7px;
   border-radius: 7px;
   width: 100%;
   height: 100%;
}
table#calculator textarea {
   width: 100%;
   height: 100px;
   background-color: rgb(55, 105, 62);
   font-size: 1.4em;
   color: rgba(255, 255, 255, 0.7);
}

table#calculator td#decimalTD {
   font-size: 0.9em;
   text-align: right;
}

table#calculator input#decimals {
   width: 35px;
   height: 20px;
   background: transparent;
   text-align: center;
}

<!-- language: lang-html -->

&lt;article&gt;
  &lt;table id=&quot;calculator&quot;&gt;
    &lt;tr&gt;
      &lt;td colspan=&quot;5&quot;&gt;
        &lt;textarea id=&quot;calcWindow&quot; name=&quot;calcWindow&quot;&gt;&lt;/textarea&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;
        &lt;input id=&quot;button7&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;7&quot; /&gt;
      &lt;/td&gt;
      &lt;td&gt;
        &lt;input id=&quot;button8&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;8&quot; /&gt;
      &lt;/td&gt;
      &lt;td&gt;
        &lt;input id=&quot;button9&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;9&quot; /&gt;
      &lt;/td&gt;
      &lt;td&gt;
        &lt;input id=&quot;buttonDivide&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;/&quot; /&gt;
      &lt;/td&gt;
      &lt;td&gt;
        &lt;input id=&quot;buttonClear&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;C&quot; /&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;
        &lt;input id=&quot;button4&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;4&quot; /&gt;
      &lt;/td&gt;
      &lt;td&gt;
        &lt;input id=&quot;button5&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;5&quot; /&gt;
      &lt;/td&gt;
      &lt;td&gt;
        &lt;input id=&quot;button6&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;6&quot; /&gt;
      &lt;/td&gt;
      &lt;td&gt;
        &lt;input id=&quot;buttonMultiply&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;*&quot; /&gt;
      &lt;/td&gt;
      &lt;td rowspan=&quot;3&quot;&gt;
        &lt;input id=&quot;buttonEnter&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;enter&quot; /&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;
        &lt;input id=&quot;button1&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;1&quot; /&gt;
      &lt;/td&gt;
      &lt;td&gt;
        &lt;input id=&quot;button2&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;2&quot; /&gt;
      &lt;/td&gt;
      &lt;td&gt;
        &lt;input id=&quot;button3&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;3&quot; /&gt;
      &lt;/td&gt;
      &lt;td&gt;
        &lt;input id=&quot;buttonMinus&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;-&quot; /&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td colspan=&quot;2&quot;&gt;
        &lt;input id=&quot;button0&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;0&quot; /&gt;
      &lt;/td&gt;
      &lt;td&gt;
        &lt;input id=&quot;buttonDecimal&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;.&quot; /&gt;
      &lt;/td&gt;
      &lt;td&gt;
        &lt;input id=&quot;buttonAdd&quot; type=&quot;button&quot; class=&quot;calcButton&quot; value=&quot;+&quot; /&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;

<!-- end snippet -->

答案2

得分: 0

Use CSS Grid(5列)代替,然后,只需为所需的按钮(和display)设置跨列或跨行,使用:grid-column grid-row

* { margin: 0; box-sizing: border-box; }

.calculator {
  display: inline-grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.4rem;
  padding: 1rem;
  background-color: lightgray;
  border: 0.25rem solid darkgray;
  border-radius: 0.4rem;
}

.result {
  padding: 1rem;
  grid-column: 1 / 6;
  height: 6rem;
  background-color: #374;
  color: #fff;
  font-size: 1.4rem;
  text-align: right;
}

[data-btn] {
  padding: 1rem;
  border: 0.2rem solid #777;
  border-radius: 0.5rem;
}

[data-btn="0"] {
  grid-column: 1 / 3;
}

[data-btn="enter"] {
  grid-column: 5;
  grid-row: 3 / 6;
}

此外,使用首选的语义元素,如<button>data-*属性和类,而不是ID - 用于可重复使用的组件单元,如calculator

英文:

Use CSS Grid (of 5 columns) instead
then, all you need is to set for the the desired buttons (and the display) the spanning columns or rows using: grid-column grid-row:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

* { margin: 0; box-sizing: border-box; }

.calculator {
  display: inline-grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.4rem;
  padding: 1rem;
  background-color: lightgray;
  border: 0.25rem solid darkgray;
  border-radius: 0.4rem;
}

.result {
  padding: 1rem;
  grid-column: 1 / 6;
  height: 6rem;
  background-color: #374;
  color: #fff;
  font-size: 1.4rem;
  text-align: right;
}

[data-btn] {
  padding: 1rem;
  border: 0.2rem solid #777;
  border-radius: 0.5rem;
}

[data-btn=&quot;0&quot;] {
  grid-column: 1 / 3;
}

[data-btn=&quot;enter&quot;] {
  grid-column: 5;
  grid-row: 3 / 6;
}

<!-- language: lang-html -->

&lt;div class=&quot;calculator&quot;&gt;
  &lt;textarea class=&quot;result&quot; readonly&gt;123567.50&lt;/textarea&gt;
  &lt;button type=&quot;button&quot; data-btn=&quot;7&quot;&gt;7&lt;/button&gt;
  &lt;button type=&quot;button&quot; data-btn=&quot;8&quot;&gt;8&lt;/button&gt;
  &lt;button type=&quot;button&quot; data-btn=&quot;9&quot;&gt;9&lt;/button&gt;
  &lt;button type=&quot;button&quot; data-btn=&quot;/&quot;&gt;/&lt;/button&gt;
  &lt;button type=&quot;button&quot; data-btn=&quot;clear&quot;&gt;C&lt;/button&gt;
  &lt;button type=&quot;button&quot; data-btn=&quot;4&quot;&gt;4&lt;/button&gt;
  &lt;button type=&quot;button&quot; data-btn=&quot;5&quot;&gt;5&lt;/button&gt;
  &lt;button type=&quot;button&quot; data-btn=&quot;6&quot;&gt;6&lt;/button&gt;
  &lt;button type=&quot;button&quot; data-btn=&quot;*&quot;&gt;*&lt;/button&gt;
  &lt;button type=&quot;button&quot; data-btn=&quot;1&quot;&gt;1&lt;/button&gt;
  &lt;button type=&quot;button&quot; data-btn=&quot;2&quot;&gt;2&lt;/button&gt;
  &lt;button type=&quot;button&quot; data-btn=&quot;3&quot;&gt;3&lt;/button&gt;
  &lt;button type=&quot;button&quot; data-btn=&quot;-&quot;&gt;-&lt;/button&gt;
  &lt;button type=&quot;button&quot; data-btn=&quot;0&quot;&gt;0&lt;/button&gt;
  &lt;button type=&quot;button&quot; data-btn=&quot;.&quot;&gt;.&lt;/button&gt;
  &lt;button type=&quot;button&quot; data-btn=&quot;+&quot;&gt;+&lt;/button&gt;
  &lt;button type=&quot;button&quot; data-btn=&quot;enter&quot;&gt;&amp;#x23CE;&lt;/button&gt;
&lt;/div&gt;

<!-- end snippet -->

Also, use the preferred semantic elements like &lt;button&gt;, the data-* attribute, and classes instead of IDs - for potentially repeatable component units, like a calculator.

答案3

得分: -1

以下是您要翻译的内容:

"I know here it's not a code free website but I found the idea interesting to see how it can be done with a grid.
As several comments is saying, it would be the right way to do that instead of table.

I made a snippet, it's one possibility several different could be done.
For grid, using repeat 5 for row and col, and using span keyword on 0 on x axis and enter on y axis
also I put data attribute for each, you can read directly dataset of ekement cliked.


#calcContainer {
  display: inline-block;
  padding: 1em;
  background-color: lightgray;
  border: 0.25em solid darkgray;
  border-radius: 15px;
}

#calculator {
  display: grid;
  grid-template-rows: 2fr 1fr 1fr 1fr 1fr;
  grid-template-columns: repeat(5, auto);
  gap: 10px;
}

#div1 {
  grid-area: 1 / 1 / 2 / 6;
}

#div2 {
  grid-area: 2 / 1 / 3 / 2;
}

#div3 {
  grid-area: 2 / 2 / 3 / 3;
}

#div4 {
  grid-area: 2 / 3 / 3 / 4;
}

#div5 {
  grid-area: 2 / 4 / 3 / 5;
}

#div6 {
  grid-area: 2 / 5 / 3 / 6;
}

#div7 {
  grid-area: 3 / 1 / 4 / 2;
}

#div8 {
  grid-area: 3 / 2 / 4 / 3;
}

#div9 {
  grid-area: 3 / 3 / 4 / 4;
}

#div10 {
  grid-area: 3 / 4 / 4 / 5;
}

#div11 {
  grid-area: 4 / 1 / 5 / 2;
}

#div12 {
  grid-area: 4 / 2 / 5 / 3;
}

#div13 {
  grid-area: 4 / 3 / 5 / 4;
}

#div14 {
  grid-area: 4 / 4 / 5 / 5;
}

#div15 {
  grid-area: 5 / 1 / 6 / 3;
}

#div16 {
  grid-area: 5 / 3 / 6 / 4;
}

#div17 {
  grid-area: 5 / 4 / 6 / 5;
}

#div18 {
  grid-area: 3 / 5 / 6 / 6;
}

.calcResult {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  background-color: lightgreen;
  border: 2px solid black;
}

.calcButton {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  background-color: #e6eaea;
  border: 2px solid black;
  border-radius: 10px;
}

.simple {
  width: 50px;
  height: 50px;
}

.doubleWidth {
  width: 114px;
  /* 2*50px + 1 grip gap 10px + 2 border 2px */
  height: 50px;
}

.tripleHeight {
  width: 50px;
  height: 178px;
  /* 3*50px + 2 grid gap 2*10px + 4 border 2*4px */
}

<div id="calcContainer">
  <div id="calculator">
    <div id="div1" class="calcResult">
      <div data-val="result">result</div>
    </div>
    <div id="div2">
      <div data-val="7" class="calcButton simple">7</div>
    </div>
    <div id="div3">
      <div data-val="8" class="calcButton simple">8</div>
    </div>
    <div id="div4">
      <div data-val="9" class="calcButton simple">9</div>
    </div>
    <div id="div5">
      <div data-val="/" class="calcButton simple">/</div>
    </div>
    <div id="div6">
      <div data-val="clear" class="calcButton simple">C</div>
    </div>
    <div id="div7">
      <div data-val="4" class="calcButton simple">4</div>
    </div>
    <div id="div8">
      <div data-val="5" class="calcButton simple">5</div>
    </div>
    <div id="div9">
      <div data-val="6" class="calcButton simple">6</div>
    </div>
    <div id="div10">
      <div data-val="*" class="calcButton simple">*</div>
    </div>
    <div id="div11">
      <div data-val="1" class="calcButton simple">1</div>
    </div>
    <div id="div12">
      <div data-val="2" class="calcButton simple">2</div>
    </div>
    <div id="div13">
      <div data-val="3" class="calcButton simple">3</div>
    </div>
    <div id="div14">
      <div data-val="-" class="calcButton simple">-</div>
    </div>
    <div id="div15">
      <div data-val="0" class="calcButton doubleWidth">0</div>
    </div>
    <div id="div16">
      <div data-val="." class="calcButton simple">.</div>
    </div>
    <div id="div17">
      <div data-val="+" class="calcButton simple">+</div>
    </div>
    <div id="div18">
      <div data-val="enter" class="calcButton tripleHeight">enter</div>
    </div>
  </div>
</div>

"

英文:

I know here it's not a code free website but I found the idea interesting to see how it can be done with a grid.
As several comments is saying, it would be the right way to do that instead of table.

I made a snippet, it's one possibility several different could be done.
For grid, using repeat 5 for row and col, and using span keyword on 0 on x axis and enter on y axis
also I put data attribute for each, you can read directly dataset of ekement cliked.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

#calcContainer {
display: inline-block;
padding: 1em;
background-color: lightgray;
border: 0.25em solid darkgray;
border-radius: 15px;
}
#calculator {
display: grid;
grid-template-rows: 2fr 1fr 1fr 1fr 1fr;
grid-template-columns: repeat(5, auto);
gap: 10px;
}
#div1 {
grid-area: 1 / 1 / 2 / 6;
}
#div2 {
grid-area: 2 / 1 / 3 / 2;
}
#div3 {
grid-area: 2 / 2 / 3 / 3;
}
#div4 {
grid-area: 2 / 3 / 3 / 4;
}
#div5 {
grid-area: 2 / 4 / 3 / 5;
}
#div6 {
grid-area: 2 / 5 / 3 / 6;
}
#div7 {
grid-area: 3 / 1 / 4 / 2;
}
#div8 {
grid-area: 3 / 2 / 4 / 3;
}
#div9 {
grid-area: 3 / 3 / 4 / 4;
}
#div10 {
grid-area: 3 / 4 / 4 / 5;
}
#div11 {
grid-area: 4 / 1 / 5 / 2;
}
#div12 {
grid-area: 4 / 2 / 5 / 3;
}
#div13 {
grid-area: 4 / 3 / 5 / 4;
}
#div14 {
grid-area: 4 / 4 / 5 / 5;
}
#div15 {
grid-area: 5 / 1 / 6 / 3;
}
#div16 {
grid-area: 5 / 3 / 6 / 4;
}
#div17 {
grid-area: 5 / 4 / 6 / 5;
}
#div18 {
grid-area: 3 / 5 / 6 / 6;
}
.calcResult {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
background-color: lightgreen;
border: 2px solid black;
}
.calcButton {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
background-color: #e6eaea;
border: 2px solid black;
border-radius: 10px;
}
.simple {
width: 50px;
height: 50px;
}
.doubleWidth {
width: 114px;
/* 2*50px + 1 grip gap 10px + 2 border 2px */
height: 50px;
}
.tripleHeight {
width: 50px;
height: 178px;
/* 3*50px + 2 grid gap 2*10px + 4 border 2*4px */
}

<!-- language: lang-html -->

&lt;div id=&quot;calcContainer&quot;&gt;
&lt;div id=&quot;calculator&quot;&gt;
&lt;div id=&quot;div1&quot; class=&quot;calcResult&quot;&gt;
&lt;div data-val=&quot;result&quot;&gt;result&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&quot;div2&quot;&gt;
&lt;div data-val=&quot;7&quot; class=&quot;calcButton simple&quot;&gt;7&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&quot;div3&quot;&gt;
&lt;div data-val=&quot;8&quot; class=&quot;calcButton simple&quot;&gt;8&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&quot;div4&quot;&gt;
&lt;div data-val=&quot;9&quot; class=&quot;calcButton simple&quot;&gt;9&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&quot;div5&quot;&gt;
&lt;div data-val=&quot;/&quot; class=&quot;calcButton simple&quot;&gt;/&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&quot;div6&quot;&gt;
&lt;div data-val=&quot;clear&quot; class=&quot;calcButton simple&quot;&gt;C&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&quot;div7&quot;&gt;
&lt;div data-val=&quot;4&quot; class=&quot;calcButton simple&quot;&gt;4&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&quot;div8&quot;&gt;
&lt;div data-val=&quot;5&quot; class=&quot;calcButton simple&quot;&gt;5&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&quot;div9&quot;&gt;
&lt;div data-val=&quot;6&quot; class=&quot;calcButton simple&quot;&gt;6&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&quot;div10&quot;&gt;
&lt;div data-val=&quot;*&quot; class=&quot;calcButton simple&quot;&gt;*&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&quot;div11&quot;&gt;
&lt;div data-val=&quot;1&quot; class=&quot;calcButton simple&quot;&gt;1&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&quot;div12&quot;&gt;
&lt;div data-val=&quot;2&quot; class=&quot;calcButton simple&quot;&gt;2&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&quot;div13&quot;&gt;
&lt;div data-val=&quot;3&quot; class=&quot;calcButton simple&quot;&gt;3&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&quot;div14&quot;&gt;
&lt;div data-val=&quot;-&quot; class=&quot;calcButton simple&quot;&gt;-&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&quot;div15&quot;&gt;
&lt;div data-val=&quot;0&quot; class=&quot;calcButton doubleWidth&quot;&gt;0&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&quot;div16&quot;&gt;
&lt;div data-val=&quot;.&quot; class=&quot;calcButton simple&quot;&gt;.&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&quot;div17&quot;&gt;
&lt;div data-val=&quot;+&quot; class=&quot;calcButton simple&quot;&gt;+&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&quot;div18&quot;&gt;
&lt;div data-val=&quot;enter&quot; class=&quot;calcButton tripleHeight&quot;&gt;enter&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年5月25日 23:43:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76334110.html
匿名

发表评论

匿名网友

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

确定