[英]HTML/CSS display-table for form layout
Wokring on the flexible HTML/CSS layout, where you just add form , row , cell label , cell input classes - and it handles everything (width, vertical align, etc.). 在灵活的HTML / CSS布局中工作,只需在其中添加form , row , 单元格标签 , 单元格输入类-它就可以处理所有内容(宽度,垂直对齐等)。
I've choses to use display: table
and its children table-row
, table-cell
- since it handles most of the issue smoothly without need the need of hacks. 我选择使用
display: table
及其子table-row
和table-cell
因为它可以顺利处理大多数问题,而无需黑客。 The goal is to have something like this (where I can just put 2 containers inside a cell and they will automatically have 50% width, or 33% for 3 containers, or 25% for 4, etc.): 我们的目标是具有这样的功能(在这里我可以将2个容器放入一个单元格中,它们将自动具有50%的宽度,或者3%用于33个容器,或者25%用于4个容器,等等):
The problem I've encountered is that tables inside a table-cell jump off the border: 我遇到的问题是表格单元中的表格跳出了边框:
Any suggestion how to fix this? 任何建议如何解决这个问题?
EDIT: JSFiddle example: https://jsfiddle.net/3gcnaetx/1/ 编辑: JSFiddle示例: https : //jsfiddle.net/3gcnaetx/1/
I would suggest using bootstrap for this since bootstrap provides a grid to solve this kind of issues. 我建议为此使用引导程序,因为引导程序提供了一个网格来解决此类问题。 If you would like to make an own css for this you can look at the idea in my snippet.
如果您想为此创建自己的CSS,可以在我的代码段中查看。 I don't know if it solves your issue, but I hope it will help you forward.
我不知道它是否能解决您的问题,但希望它能帮助您前进。
CSS & HTML Snippet: CSS和HTML代码段:
*{ box-sizing: border-box; } .formrow:after, .col-2:after{ display: table; content: " "; clear: both; } .col-2 { border: 1px dashed black; height: 100%; padding: 5px; width: 50%; min-width: 200px; float: left; } label { float: left; padding-right: 10px; }
<div class="form"> <form> <div class="formrow"> <div class="col-2"><label for="input1">Label</label></div> <div class="col-2"><input id="input1"></input></div> </div> <div class="formrow"> <div class="col-2"><label for="input2">Even longer label</label></div> <div class="col-2"><input id="input2"></input></div> </div> <div class="formrow"> <div class="col-2"> <label for="input3">Label</label> <input id="input3"></input> </div> <div class="col-2"> <label for="input4">Label</label> <input id="input4"></input> </div> </div> </form> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.