输入数字,里面有按钮

问题描述 投票:0回答:2

我知道我可以在输入中设置一个提交按钮,但我尝试自己构建它。

期望的结果是:

enter image description here

粉红色的盒子就是这个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有一些上边距并且没有与粉红色边缘垂直对齐,而按钮对齐得很好。

html css
2个回答
0
投票

固定。

  1. 你不能在html有空格: <input type="number" class="font" name="productPrice" placeholder="Enter Your Phone Number"><button type="submit" value="ab">
  2. 然后当使用inline-block时,你必须对齐顶部两个元素vertical-align:top

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>
© www.soinside.com 2019 - 2024. All rights reserved.