我正在尝试对其进行格式化,以便问号标签“q”居中并位于问号框上方,而在下方也是“A”标签和框,其下方是按钮。任何帮助表示赞赏。
h1 {
text-align: center;
}
label,
input {
width: 120px;
display: block;
float: left;
margin-bottom: 10px;
}
label {
width: 240px;
text-align: right;
padding-right: 10px;
margin-top: 2px;
}
br {
clear: left;
}
.button {
width: 120px;
background: rgba(144, 255, 246, 0.42);
color: #0000a0;
padding: 5px;
border: none;
border-radius: 2px;
cursor: pointer;
margin-left: 250px;
}
body {
background-image: url(assets/bg1.png);
}
<form name="ThisForm">
<h1>Learning to multiply</h1>
Q:
<input type="text" name="question" id="question" disabled="disabled" />A:
<input type="text" name="Ans" id="Ans" maxlength="3" size="3" />
<input type="button" value="Check Answer" onclick="buttonPressed()"/>
<br />
</form>
答案 0 :(得分:0)
为text-align
元素设置center
到form
;将"Q:"
和"A:"
文本分别设置为html
元素的span
;从float: left
移除css
;将input
position
设为relative
;使用form input
函数将left
50%
设置为input
减去width
2
除以calc()
。
h1 {
text-align: center;
}
label,
input {
width: 120px;
position: relative;
display: block;
margin-bottom: 10px;
}
label {
width: 240px;
text-align: right;
padding-right: 10px;
margin-top: 2px;
}
.button {
width: 120px;
background: rgba(144, 255, 246, 0.42);
color: #0000a0;
padding: 5px;
border: none;
border-radius: 2px;
cursor: pointer;
margin-left: 250px;
}
form {
text-align:center;
}
form input {
left: calc(50% - 120px / 2);
}
&#13;
<form name="ThisForm">
<h1>Learning to multiply</h1>
<span>Q:</span>
<input type="text" name="question" id="question" disabled="disabled" />
<span>A:</span>
<input type="text" name="Ans" id="Ans" maxlength="3" size="3" /><br>
<input type="button" value="Check Answer" onclick="buttonPressed()" />
</form>
&#13;