gpt4 book ai didi

html - 计算器 HTML

转载 作者:行者123 更新时间:2023-11-28 13:53:10 25 4
gpt4 key购买 nike

我在高度、边距和对齐方面遇到问题。我想将我的计算器对齐到中间,将我的“C”按钮重新定位到靠近其他按钮的位置,并在不影响其他按钮的情况下自定义“=”等号按钮的高度。

  1. 如何在不影响其他按钮的情况下自定义“=”按钮的高度?
  2. 我的“C”按钮,我希望它靠近其他按钮。
  3. 我想将计算器居中对齐。

body {
background-image: linear-gradient(to right, #7b4397, #dc2430);
}

input[type=button] {
font-size: 20px;
width: 50px;
height: 50px;
margin-right: -6px;
margin-top: -6px;
border: color: none;
}

input[type=text] {
font-family: cursive;
margin-left: 3px;
margin-top: ;
margin-bottom: inherit;
width: 140px;
height: 42px;
}

#del {
height: 150px;
}
<form name="Calculator">

<table>
<tr>
<input type="text" name="Answer"> <input type="button" value="C" name="Delete" onclick="Calculator.Answer.value = ' ' ">
</tr>

<tr>
<td><input type="button" value="+" onclick="Calculator.Answer.value += '+' "></td>
<td><input type="button" value="-" onclick="Calculator.Answer.value += '-' "></td>
<td><input type="button" value="/" onclick="Calculator.Answer.value += '/' "></td>
<td><input type="button" value="*" onclick="Calculator.Answer.value += '*' "></td>
</tr>

<tr>
<td><input type="button" value="7" onclick="Calculator.Answer.value += '7' "></td>
<td><input type="button" value="9" onclick="Calculator.Answer.value += '8' "></td>
<td><input type="button" value="9" onclick="Calculator.Answer.value += '9' "></td>
<td><input type="button" value="=" id="del" onclick="Calculator.Answer.value = eval(Calculator.Answer.value) "></td>
</tr>

<tr>
<td><input type="button" value="4" onclick="Calculator.Answer.value += '4' "></td>
<td><input type="button" value="5" onclick="Calculator.Answer.value += '5' "></td>
<td><input type="button" value="6" onclick="Calculator.Answer.value += '6' "></td>
</tr>

<tr>
<td><input type="button" value="1" onclick="Calculator.Answer.value += '1' "></td>
<td><input type="button" value="2" onclick="Calculator.Answer.value += '2' "></td>
<td><input type="button" value="3" onclick="Calculator.Answer.value += '3' "></td>
</tr>

<table>

</form>

The result

最佳答案

  1. “=”按钮的重要之处在于在其 td 元素上使用了 rowspan
  2. 我添加了 td 元素(其中一个带有 colspan)并稍微调整了现有的 CSS 以重新定位“C”按钮。
  3. 可以使用 CSS flexbox 布局 使计算器居中。

查看下面的结果:

<!DOCTYPE html>
<html>
<style>
body {
background-image: linear-gradient(to right, #7b4397 ,#dc2430 );
height: 100vh;
}

div {
display: flex;
width: 100%;
height: 100%;
justify-content: center;
align-items: center;
}

input[type=button] {
font-size: 20px;
width: 50px;
height: 50px;
margin-right: -6px;
margin-top: -6px;
border:
color: none;
}

input[type=text] {
font-family: cursive;
margin-top: ;
margin-bottom: inherit;
width: 140px;
height: 42px;
margin-right: -6px;
margin-top: -6px;
}

#del {
height:150px;
}
</style>

<body>
<div>
<form name="Calculator">
<table>
<tr>
<td colspan="3"><input type="text" name="Answer"></td>
<td><input type="button" value="C" name="Delete" onclick="Calculator.Answer.value = ' ' "></td>
</tr>
<tr>
<td><input type="button" value="+" onclick="Calculator.Answer.value += '+' "></td>
<td><input type="button" value="-" onclick="Calculator.Answer.value += '-' "></td>
<td><input type="button" value="/" onclick="Calculator.Answer.value += '/' "></td>
<td><input type="button" value="*" onclick="Calculator.Answer.value += '*' "></td>
</tr>
<tr>
<td><input type="button" value="7" onclick="Calculator.Answer.value += '7' "></td>
<td><input type="button" value="8" onclick="Calculator.Answer.value += '8' "></td>
<td><input type="button" value="9" onclick="Calculator.Answer.value += '9' "></td>
<td rowspan="3"><input type="button" value="=" id="del" onclick="Calculator.Answer.value = eval(Calculator.Answer.value) "></td>
</tr>
<tr>
<td><input type="button" value="4" onclick="Calculator.Answer.value += '4' "></td>
<td><input type="button" value="5" onclick="Calculator.Answer.value += '5' "></td>
<td><input type="button" value="6" onclick="Calculator.Answer.value += '6' "></td>
</tr>
<tr>
<td><input type="button" value="1" onclick="Calculator.Answer.value += '1' "></td>
<td><input type="button" value="2" onclick="Calculator.Answer.value += '2' "></td>
<td><input type="button" value="3" onclick="Calculator.Answer.value += '3' "></td>
</tr>
<table>
</form>
</div>
</body>
</html>

关于html - 计算器 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59344109/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com