简体   繁体   中英

How to position two text fields with margins in one line?

I'm trying to position two input fields in one line, by applying the float: left; property in an .inline class.

However, because all input[type="text"] have a margin: 5px; , it will only work with width: 50% only if I remove the margins.

With margin of 5:

图片1

Without any margin:

在此处输入图片说明

What would be an ideal solution?

Here's a codepen link: http://codepen.io/biskotaki/pen/YXdYYE?editors=110

input[type="text"]
{
  box-sizing: border-box;
  padding: 5px;
  width: 100%;
}

.inline input {
  float: left;
  width: calc(50% - 10px);
  margin:5px;
}

http://fiddle.jshell.net/fL0gm3h9/

Reduce width to 48%

 input[type="text"] { box-sizing: border-box; padding: 5px; width: 100%; } .inline input { float: left; width: 48%; margin:5px;} 
 <div class="inline"> <input type="text" placeholder="text 1"> <input type="text" placeholder="text 2"> </div> 

Since you already have a .inline class, consider adding this:

.inline>input[type="text"] {margin:0}

This will disable the margin on the appropriate input boxes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM