input 标签为什么会多出1像素?

clipboard.png

 * {        
            margin: 0px;
            padding: 0px;
        }
         .box {
             width: 200px;
             border: black 1px solid;
         }
         input {
             width: 198px;
             height: 18px;
             border: solid 1px red;
         }
   

<div class="box">
        <input type="text"/>
</div>
阅读 5.5k
2 个回答

input默认是是 inline-block 并默认与基线对齐,也就是baseline,加上 vertical-align: top;就行 或者 改成 display: block;

楼上正解,你也可以设置

.box{font- size:0;}
.box input {font- size:14px;}

当然input的字体根据你的需要进行设置

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进