我知道我可以在输入中设置一个“提交”按钮,但是我尝试自己构建它。
所需的结果是:
所以粉红色的盒子是这个div:
<div class="numberSubmittion SimpleInputBox buttonCorners brandBlue" >
<input type="number" class="font" name="productPrice" placeholder="Enter Your Phone Number">
<button type="submit" value=">">
</div>
css :
.numberSubmittion {
height: 100%;
}
.numberSubmittion input {
height: 100%;
width:75%;
margin-left: 0px;
font-size: 14;
border:0px solid clear;
outline-width: 0;
border-width: 0px;
background-color: rgba(255, 0, 0, 0.1);
}
.numberSubmittion button {
height: 100%;
width:25%;
display: inline-block;
outline-width: 0;
border-width: 0px;
background-color: rgba(255, 0, 255, 0.1);
}
所以我得到正确的输入,如何在右边找到按钮? 现在,该按钮位于粉红色div的外部,位于左侧。
编辑
修复我的html以删除空格后:
<input type="number" class="font" name="productPrice" placeholder="Enter Your Phone Number"><button type="submit" value="ab">
但是现在,当它们对齐时,输入div会有一些上边距,并且与粉红色的垂直对齐,而按钮没有对齐。
答案 0 :(得分:0)
* {
box-sizing: border-box;
font-family: inherit;
margin: 0;
padding: 0;
}
html {
font-size: 62.25%;
}
body {
font-family: sans-serif;
font-size: 1.6rem;
}
.num-box {
margin: 5rem auto;
width: 300px;
display: flex;
background-color: pink;
border-radius: 1rem;
overflow: hidden;
justify-content: center;
align-items: center;
}
.num-input {
width: calc(100% - 40px);
padding: 2rem;
border: 0;
background: transparent;
font-family: sans-serif;
font-size: 2rem;
outline: none;
}
.num-btn {
width: 40px;
height: 40px;
padding: 10px;
position: relative;
border: 0;
outline: none;
background: transparent;
}
.num-btn::after {
position: absolute;
top: 50%;
left: 50%;
width: 30px;
height: 30px;
display: flex;
justify-content: center;
align-items: center;
content: '✔';
transform: translate(-50%, -50%);
background-color: #fff;
border-radius: 50%;
color: #9e9b9b;
cursor: pointer;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello World From Gaurav</title>
</head>
<body>
<div class="num-box">
<input type="number" name="" id="" class="num-input" placeholder="Type number">
<button class="num-btn"></button>
</div>
</body>
</html>
答案 1 :(得分:0)
固定。
html
中不能有空格:
<input type="number" class="font" name="productPrice" placeholder="Enter Your Phone Number"><button type="submit" value="ab">
然后,在使用inline-block
时,必须对齐两个元素vertical-align:top