HTML - 无法定义正确的边距

标签 html css

我想要连续 2 个具有定义宽度的输入元素。我计算了边距和填充,但它不适合父元素。

js fiddle

HTML

<div class="wrap">
<input class="input-text left"type="text" name="name" placeholder="name" />
<input class="input-text" type="text" name="surname" placeholder="surname" />

 </div>

CSS

.wrap{
   width: 400px;
   background: lightgrey;
}

.input-text{
   width: 145px;
   padding: 0 20px;
   border: 0;
   background: grey;
 }

.left{
    margin-right: 30px;
}

最佳答案

您必须消除元素之间的空白,因为它也被计算在内。

<div class="wrap">
    <input class="input-text left" type="text" name="name" placeholder="name" /><!--
    --><input class="input-text" type="text" name="surname" placeholder="surname" />
</div>

fiddle :http://jsfiddle.net/bLz5s6kh/7/

引用:Fighting the Space Between Inline Block Elements

关于HTML - 无法定义正确的边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27503624/

相关文章:

html - Bootstrap 3.0 : How to have text and input on same line?

html - 滚动条聚焦在 HTML div 的底部

javascript - 什么是 facebook 状态输入元素?

javascript - 固定的元素位置与父项相关,而不是与视口(viewport)相关

jquery - 基于 jquery 中的 css 属性的条件更改(if/then)

javascript - 创建新的待办事项代码生成错误

html - 水平滚动的 html 框

css - Bootstrap 轮播控件选项

html - 标题 li 元素不会并排对齐

html - 从上到右而不是从左到右对列表进行排序