我有两个标记的textareas(fiddle):
<body>
<h1>Header</h1>
<label for="ta1">label 1</label>
<textarea id="ta1">textarea 1</textarea>
<label for="ta2">label 2</label>
<textarea id="ta2">textarea 2</textarea>
</body>
这些textareas应该并排放置,并且应该在屏幕上获得尽可能多的空间:
如何使用CSS或JavaScript实现这一目标?
Textareas应该
答案 0 :(得分:2)
我找到了另一种使用灵活的盒子布局(fiddle)的纯CSS解决方案:
<强> HTML 强>
<body>
<h1>Header</h1>
<div class="row">
<div class="col">
<label for="ta1">label 1</label>
<textarea id="ta1">textarea 1</textarea>
</div>
<div class="col">
<label for="ta2">label 2</label>
<textarea id="ta2">textarea 2</textarea>
</div>
</div>
</body>
<强> CSS 强>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
body {
display: flex;
flex-flow: column;
}
h1 {
text-align: center;
}
.row {
flex: 1;
display: flex;
flex-flow: row;
}
.col {
flex: 1;
display: flex;
flex-flow: column;
margin: 0px 3px;
}
label {
display: block;
padding-left: 2px;
}
textarea {
flex: 1;
display: block;
margin: 2px 0;
padding: 1px;
border: 1px solid;
resize: none;
}
答案 1 :(得分:0)
为.col
和label
添加textarea
以正确并排排列row
至align-center
.col{
float:left;
padding-right:10px;
}
label, textarea{
width:100%;
}
.row {
display:inline-block;
}
修改强>
添加了jquery以找到身体的确切高度
function adjust() {
var a = $(window).height()
var b = $('header').height()
var c = a - b
$('.row').height(c)
}
adjust()
$(window).resize(function () {
adjust()
})
答案 2 :(得分:0)
我找到了使用calc
的纯CSS解决方案,最符合我的需求(fiddle):
<强> HTML 强>
<body>
<h1>Header</h1>
<div class="row">
<div class="col">
<label for="ta1">label 1</label>
<textarea id="ta1">textarea 1</textarea>
</div>
<div class="col">
<label for="ta2">label 2</label>
<textarea id="ta2">textarea 2</textarea>
</div>
</div>
</body>
<强> CSS 强>
html, body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
h1 {
text-align: center;
height: 40px;
margin: 0;
padding: 0;
}
.row {
width: 100%;
/* consider h1 height */
height: calc(100% - 40px);
}
.col {
margin: 0 3px;
/* consider column count (here 2) and margin (2 * 3px) */
width: calc(100% / 2 - 6px);
height: 100%;
float: left;
}
label {
display: block;
width: 100%;
height: 20px;
padding-left: 2px;
}
textarea {
display: block;
/* only subtract margin, padding and border of textarea */
width: calc(100% - 4px);
/* additionally consider label */
height: calc(100% - 20px - 8px);
margin: 2px 0;
padding: 1px;
border: 1px solid;
resize: none;
}