如何用CSS控制字段集的定位?
我有以下代码:
<fieldset>
<legend>
<strong>Personal Information</strong>
</legend>
<ul>
<li>
<label for="first_name">First Name</label><br />
<input type="text" id="first_name" name="first_name" value="" maxlength="30" />
</li>
...
</ul>
</fieldset>
<fieldset>
<legend>
<strong>Car Information</strong>
</legend>
<ul>
<li>
<label for="car_make">Make</label><br />
<input type="text" id="car_make" name="car_make" value="" maxlength="30" />
</li>
...
</ul>
</fieldset>
现在所有内容都在左侧,其中第二个字段集(汽车信息)位于第一个字段集(个人信息)的正下方。
我希望汽车信息字段集位于个人信息字段集的右侧,以便它们并排。 使用CSS,我该如何做到这一点?
I have the following code:
<fieldset>
<legend>
<strong>Personal Information</strong>
</legend>
<ul>
<li>
<label for="first_name">First Name</label><br />
<input type="text" id="first_name" name="first_name" value="" maxlength="30" />
</li>
...
</ul>
</fieldset>
<fieldset>
<legend>
<strong>Car Information</strong>
</legend>
<ul>
<li>
<label for="car_make">Make</label><br />
<input type="text" id="car_make" name="car_make" value="" maxlength="30" />
</li>
...
</ul>
</fieldset>
Right now everything is on the left hand side where the second fieldset (car information) is right below the first fieldset (personal information).
I would like the car information fieldset to be on the right hand side of the personal information fieldset so they are side by side. Using css, how would I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
由于字段集被视为块,因此您需要使用
Or 任何您想要的字段集宽度。
Since fieldsets are considered blocks, you need to use
Or whatever you want for the width of the fieldsets.
您可以做的是将两个字段集浮动到左侧。 css 看起来像这样:
这将影响页面上的每个字段集,因此如果您只想隔离特定字段集,请使用 CSS 类:
What you can do is float both fieldsets to the left. The css would look like this:
This is going to effect every fieldset on the page, so if you want to isolate only specific fieldsets use css classes:
正如他们所说,但您也可以将汽车信息浮动到右侧,这使您的优势是无论宽度如何,都始终与该边缘齐平(如果这很重要)。
What they said, but you can also float the car information right, which gives you the advantage of always being flush against that edge no matter the width, if that's important.
如果您为字段集指定宽度并将其向左浮动,则如下所示:
HTML:
CSS:
If you assign a width to your fieldsets and float the to the left, something like this:
HTML:
CSS: