【问题标题】:Align textarea and button without button moving down when value is inserted插入值时对齐文本区域和按钮而不向下移动按钮
【发布时间】:2016-07-20 06:40:37
【问题描述】:

我正在尝试将文本区域和按钮对齐在同一行。我已经成功地做到了,代码在下面的小提琴中(尽管由于某种原因小提琴不会对齐它们)。

问题:每当我在按钮中插入一个值时,按钮都会向下移动 30px,仍然在同一行,但略低于文本区域。只有在按钮中插入值时才会发生这种情况。

所有代码都在小提琴中:https://jsfiddle.net/13qy0acp

代码:

HTML

<div id="messagebox">
<p id="headings"><textarea name="msg" style="height:40px;text-align:center" id="message" placeholder="Insert message"></textarea></p>
<p id="button"><input type="button" value="Send" onclick="submitChat()" id="innerbutton"></p>
</div>

CSS

#headings {
text-align:center;
display:inline-block;
width:70% !important;
margin-top:20px;
}
#message {
width:100%;
}
#button {
text-align:center;
display:inline-block;
width:8%;
margin-top:-30px !important;
border:solid black;
height:50px;
}
#innerbutton {
width:100%;
height:20px;
text-decoration:none;
}

【问题讨论】:

标签: html forms alignment


【解决方案1】:

如果要水平对齐两个元素,请使用float 属性并设置一个不超过父元素宽度的 100% 的宽度。

示例:

textarea {
  width:90%;
  float: left;
}
button {
  width:10%;
  float: left;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-15
    • 2021-12-20
    • 2020-02-26
    相关资源
    最近更新 更多