gpt4 book ai didi

javascript - 根据窗口大小设置文本区域元素高度

转载 作者:行者123 更新时间:2023-11-30 09:23:28 25 4
gpt4 key购买 nike

我正在尝试使用 css 根据窗口大小设置 textarea 元素的高度。问题是,如果我使用 height 设置它,在一台显示器上观看效果就足够了,但在另一台显示器上就不行了。示例:

textarea {
resize: none;
margin: 5px 10px 5px 10px;
border-radius: 8px;
height: 900px;
}

这可以仅使用 CSS 来完成还是需要 JS 才能完成?

编辑:

我的目标是让 2 个 textarea 元素彼此相邻,它们之间的距离很小,与底部/顶部的距离也很小(因此留出边距)。希望这两个元素的高度应该几乎与窗口大小相同,使用 height: 100%; 后不会出现这种情况。

一个链接 jsfiddle ,其中 height: 100%; 没有成功。

/* Commented out because of background img
body {
background-image: url(./images/background.jpg);
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
*/

.btn-group button {
background: #DF6C6C;
border-color: transparent;
color: white;
padding: 10px 24px;
cursor: pointer;
float: left;
outline: 0px !important;
-webkit-appearance: none;
}

.btn-group button:not(:last-child) {
border-right: none;
/* Prevent double borders */
}


/* Clear floats (clearfix hack) */

.btn-group:after {
content: "";
clear: both;
display: table;
}


/* Add a background color on hover */

.btn-group button:hover {
background-color: #E58B8B;
}


/* Align buttons */

.wrapper {
text-align: center;
}

textarea {
resize: none;
margin: 5px 10px 5px 10px;
border-radius: 8px;
outline: 0px !important;
-webkit-appearance: none;
height: 100%;
}
<body>
<div class="wrapper">
<div class="btn-group">
<button>Button1</button>
<button>Button2</button>
<button>Button3</button>
<button>Button4</button>
<button>Button5</button>
<button>Button6</button>
</div>
</div>
<textarea></textarea>
</body>

最佳答案

也许可以作为开始,我使用了一个带有绿色边框的包装器,这样您就可以看到发生了什么。

您可能(我的假设)不想要 100% 的高度,而是“剩余 100% 的高度”还有其他答案,例如 https://stackoverflow.com/a/11226029/125981

.btn-group button {
background: #DF6C6C;
border-color: transparent;
color: white;
padding: 10px 24px;
cursor: pointer;
float: left;
outline: 0px !important;
-webkit-appearance: none;
}

.btn-group button:not(:last-child) {
border-right: none;
/* Prevent double borders */
}


/* Clear floats (clearfix hack) */

.btn-group:after {
content: "";
clear: both;
display: table;
}


/* Add a background color on hover */

.btn-group button:hover {
background-color: #E58B8B;
}


/* Align buttons */

.wrapper {
text-align: center;
}

.txtcontainer {
border: solid lime 1px;
text-align: center;
height: 140px;
padding-top: 5%;
padding-bottom: 5%;
}

.spacer {
width: 5%;
}

.myfunones{
resize: none;
border-radius: 8px;
outline: 0px !important;
-webkit-appearance: none;
height: 100%;
width: 45%;
}
<body>
<div class="wrapper">
<div class="btn-group">
<button>Button1</button>
<button>Button2</button>
<button>Button3</button>
<button>Button4</button>
<button>Button5</button>
<button>Button6</button>
</div>
</div>
<div class='txtcontainer'>
<textarea class='myfunones'>text</textarea><span class='spacer'>&nbsp;</span><textarea class='myfunones'>text2</textarea>
</div>
</body>

关于javascript - 根据窗口大小设置文本区域元素高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50304580/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com