解决input框上下偏移问题

问题描述:

input框和后边的按钮不能对齐

如下图所示:

采用的布局是

<div class="header">
    <div class="header-text">全息画像查询系统</div>
    <div class="header-search">
        <div class="input-box">
            <input class="search-input" type="text" placeholder="请输企业名称/法定代表人等关键词" />
        </div>
        <div class="search-btn">搜索</div>
    </div>
</div>

样式

.header-search {
    height: 40px;
    width: 34%;
    line-height: 40px;
    /* background-color: #f2f8fc; */
    border: solid 1px #d4e2f5;
    box-sizing: border-box;
    float: right;
    margin-top: -60px;
    margin-right: 20px
}

.input-box {
    height: 100%;
    width: calc(100% - 90px);
    box-sizing: border-box;
    float: left;
}

.search-input {
    height: 100%;
    width: 100%;
    border: 0;
    padding-left: 30px;
    box-sizing: border-box;
    font-size: 14px;
    color: #000;
    background-color: #f2f8fc;
    background-image: url('../img/serch.png');
    background-repeat: no-repeat;
    background-position: 10px 13px;;
}

.search-btn {
    width: 90px;
    height: 100%;
    text-align: center;
    float: right;
    cursor: pointer;
    color: #fff;
    background-color: #5c9df1;
}

解决办法:

将input标签转化为块级元素即可

具体操作:

为.search-input添加display: block;

解析原因:

input为行内元素,设置的padding:0;不会起作用,而后边的div为块级元素故二者不可能对齐

 

  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值