css - 将字段集元素定位在其他元素下

标签 css html forms format fieldset

我下载了一个网站模板,我正尝试对其部分显示方式进行一些更改。默认格式适用于大多数输入框,但在尝试进行一些小的更改时,我完全打破了它。

enter image description here

IP 分配字段没问题。对于 Inventory,我试图组合 Fieldsets 以使两个框之间没有间隙,但我所做的任何更改都会导致这个损坏的 CSS。红线显示了我期望的位置,但不知道如何正确放置它们。

                <fieldset style="width:30%; float:left; margin-left: 19%; margin-right: 2%;"> <!-- to make two field float next to one another, adjust values accordingly -->
                    <label>IP Allocation</label>
                    <input type="text" style="width:92%;">
                </fieldset>
                <fieldset style="width:30%; float:left;"> <!-- to make two field float next to one another, adjust values accordingly -->
                    <label>IP Allocation</label>
                    <input type="text" style="width:92%;">
                </fieldset><div class="clear"></div>

                <p><div align="center"><h2>Inventory</h2></div><p>

                <fieldset style="width:62%; float:left; margin-left: 19%;"> <!-- to make two field float next to one another, adjust values accordingly -->
                    <label>Type</label>
                    <input type="text" style="width:25%; float:left; margin-right: 2%;">
                    <label>Item</label>
                    <input type="text" style="width:25%; float:left;">
                </fieldset><div class="clear"></div>

更新

在对代码和样式进行一些修改后,我能够使其接近目标布局。但是,做 2 个标签然后 2 个输入是否“合法”?可以更精确地定位吗?

enter image description here

                <fieldset style="width:62%; float:left; margin-left: 19%;"> <!-- to make two field float next to one another, adjust values accordingly -->
                    <label style="width:45%;">Type</label>
                    <label style="width:45%;">Item</label>
                    <input type="text" style="width:45%; clear: left;">
                    <input type="text" style="width:45%;">
                </fieldset><div class="clear"></div>

最佳答案

您不必 float 输入元素,因为它们包含在 float 字段集中。

您可以通过删除输入 float (因此它显示为 block )或带有标签的 clear: left 来解决这个问题。

关于css - 将字段集元素定位在其他元素下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17983474/

相关文章:

html - Div 放置在 fullscreen-img 之上并相对于 fullscreen-img

javascript - 当我的 script.js 在 Codecademy 上运行时无法制作它

html - 如何调整 Bootstrap 网格以与我在移动设备中的示例不同地显示

javascript - 有条件执行 PHP 脚本来发送电子邮件

php - 表单提交在 Firefox 中不起作用,在 chrome 中工作正常

javascript - 您将如何使用 jquery 将事件类添加到跨度类链接

javascript - Canvas 调整大小和处理JS绘制功能不同步

javascript - 无法获取父 ID

javascript - 使用 PreventDefault 函数重新加载表单提交

javascript - 如何使用 javascript 将内容传递到新页面?