简体   繁体   English

HTML / CSS表单与按钮和文本区域对齐

[英]HTML/CSS form alignment with buttons and text area

I'm trying to achieve the following layout but I'm having trouble doing it in HTML and I am not sure what the correct way to implement this would usually be (I would assume CSS to be the case but maybe doing it in plain HTML is better/simpler) : 我正在尝试实现以下布局,但在用HTML进行处理时遇到了麻烦,而且我不确定通常会采用哪种正确的方式(我会假设CSS是这种情况,但也许可以在纯HTML中进行处理更好/更简单):

[-NameInput-] |-----------------------------------textarea-----------------------------------] [-NameInput-] | ----------------------------------- textarea -------- ---------------------------]
[-PhoneInput-] |-----------------------------------textarea-----------------------------------] [-PhoneInput-] | ----------------------------------- textarea -------- ---------------------------]
[Submit] [提交]
[-EmailInput- ] |-----------------------------------textarea-----------------------------------] [-EmailInput-] | ----------------------------------- textarea -------- ---------------------------]

Where the [ ] brackets represent a button and the | 其中[]括号代表一个按钮,而|则代表|。 | | represent one text area. 代表一个文本区域。 So far I'm kinda confused as some websites are doing this kind of stuff with the table tag, and other with block-align in CSS. 到目前为止,我有点困惑,因为有些网站使用table标记来进行此类操作,而另一些网站则使用CSS进行块对齐。 Any input on this? 有什么意见吗?

To start with, if you are seeing source code where tables are used to lay out page elements, leave that site immediately. 首先,如果您看到的是用于使用表格对页面元素进行布局的源代码,请立即离开该站点。 Do not go back. 不要回去。 It is a prehistoric dinosaur and on the verge of extinction. 它是史前恐龙,濒临灭绝。 You wouldn't want to go extinct with it. 您不会想要灭绝它。

Secondly, using CSS to lay out a form is quite easy and mobile-friendly as well. 其次,使用CSS布置表单非常容易并且对移动设备友好。

<form>
<div class="input-wrapper">
    <label for="name">Name:</label>
    <input id="name" type="text" placeholder="Name">
</div>
<div class="input-wrapper">
    <label for="phone">Phone:</label>
    <input id="phone" type="text" placeholder="Phone">
</div>
<div class="input-wrapper">
    <label for="email">Email:</label>
    <input id="email" type="email" placeholder="Email Address">
</div>

.input-wrapper {
    width:100%;
    clear:both;
    padding:1em 0;
}
label {
    display:inline-block;
    float:left;
    text-align:right;
    margin-right:1em;
}
input {
    display:block;
    float:left;
}

Here is a basic fiddle. 这是一个基本的小提琴。 https://jsfiddle.net/maguijo/j571a7j0/ https://jsfiddle.net/maguijo/j571a7j0/

This form is aligned on wider screens and go to stacked on smaller screens. 此表格在较宽的屏幕上对齐,然后在较小的屏幕上堆叠。 Boom. 繁荣。 Done. 做完了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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