html - 在表单中并排放置 html 按钮时出现问题

标签 html css forms button

这是我的第一个问题。

我在并排获取我的 html 表单按钮时遇到问题。有人可以看一下并告诉我哪里出了问题吗?看起来它们应该默认放置在行内,但我想情况并非如此。

这是我的 html 代码。

        <input type="submit" name="1" formtarget="" value="1">
        <input type="submit" name="2" formtarget="" value="2">
        <input type="submit" name="3" formtarget="" value="3">
        <input type="submit" name="4" formtarget="" value="4">

这是表单输入和个人姓名的 CSS

#form input {
position: relative;
display: inline;
margin: 0;
padding: 0;
border: none;
outline: none;
-webkit-box-shadow: none;
box-shadow: none;
-webkit-border-radius: 4px;
border-radius: 4px;
text-shadow: none;
line-height: 44px;
-webkit-appearance: none;
}

除了颜色变化之外,每个按钮都是一样的。

#form input[name="1"] {
margin-top: 8px;
height: 44px;
width: 50%;
background: #A901DB;
border-bottom: 1px solid #B404AE;
color: #FFF;
font-size: 18px;
text-align: center;
}
#form input[name="2"] {
margin-top: 8px;
height: 44px;
width: 50%;
background: #A901DB;
border-bottom: 1px solid #B404AE;
color: #FFF;
font-size: 18px;
text-align: center;
}

谁能帮我设置一下,让它们并排内联?

编辑:这就是它显示的内容。

http://jsfiddle.net/g01juc2z/2/

最佳答案

您将 4 个元素设置为 width:50%,这等于 200% 宽度。将它们更改为 width: 24%(inline-block 元素的自然间距为 1 或 2px)或更小,它们将对齐:

#form input[name="1"] {
  margin-top: 8px;
  height: 44px;
  width: 24%; <---------------
  background: #A901DB;
  border-bottom: 1px solid #B404AE;
  color: #FFF;
  font-size: 18px;
  text-align: center;
}

FIDDLE

关于html - 在表单中并排放置 html 按钮时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27715921/

相关文章:

javascript - 展平/展开对象 : am I on the right tracks?

javascript - 如果 HTML5 表单中的文本框值为 x,则 y : Is that possible?

css - 有没有像blueprint、960.gs这样专门针对移动网站的CSS网格框架?

javascript - Flot 轴标签在 Canvas 中的位置

ruby-on-rails - 显示配置文件名称而不是配置文件 ID

javascript - 表单中的 angularjs 复选框

c# - Html Agility Pack 结束于不起作用

javascript - jQuery .change() 对带有 1 个选项的选择没有反应

php - 帖子链接在 768px 以下不起作用

javascript - 偏移量不能将 div 返回到 0,0?