我有一个 <textarea>
对象,50 cols width
.我想要一个 <button>
和<textarea>
一样宽目的。这可能吗?。如果不是,一个 cols
有多少像素.或者我很困惑 cols
不要阻止 width
的 <textarea>
根本。在这种情况下,默认值是多少 width
的 <textarea>
对象?
(我不想使用 javascript 来获取宽度,因为我正在构建一个 chrome 扩展,所以它必须是轻量级的)
提前致谢!
编辑:
如果我必须使用 width
为此,好的。但我想要与现在完全相同的宽度,因为它非常适合。那么如何将 cols 转换为 width 呢?我使用最新的 CSS 版本(以及最新的 HTML),并且该页面仅在 chrome 上运行。
最佳答案
无论元素的 padding 或 border-width 有多么不同,要使一个元素与另一个元素的宽度相同,您可以重置 box-sizing
:
https://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing
The
box-sizing
CSS property sets how the total width and height of an element is calculated.
textarea,
button {
box-sizing: border-box;/* includes border and padding into size calculation */
width: 200px;
}
/* demo purpose to show where both textarea/button stand and take width */
div {
display:table;
border:solid 1px;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div>
<textarea></textarea><br/>
<button>Click</button>
</div>
</body>
</html>
关于html - 在css中使用cols的度量单位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57331700/