在css中使用cols的度量单位

用户11814338

我有一个<textarea>对象,50 cols width我想要一个<button><textarea>对象一样宽的这可能吗?。如果不是,多少像素是 1 cols或者我很困惑和cols不威慑的width<textarea>根本。在这种情况下,对象的默认值width<textarea>什么?

(我不想使用 javascript 来获取宽度,因为我正在构建一个 chrome 扩展,所以它必须是轻量级的)

先感谢您!

编辑:

如果我必须使用width它,好的。但我想要与现在完全相同的宽度,因为它非常适合。那么如何将列转换为宽度?我使用最新的 CSS 版本(以及最新的 HTML),并且该页面仅在 chrome 上运行。

大卫说恢复莫妮卡

根据您编写 HTML 的方式 - 请记住在您的问题中显示您的 [mcve] 代码,这使我们更容易提供帮助和提供实用建议 - 有一些选项:

*,
::before,
::after {
  /* forcing all elements, and the listed pseudo-elements,
     to use the border-box sizing; including padding and
     margins into the calculated width: */
  box-sizing: border-box;
  /* resetting margin and padding to zero for consistency: */
  margin: 0;
  padding: 0;
}

div {
  /* the default margin for all <div> elements, to move them
     apart from the left-edge of the viewport and away from
     their predecessor: */
  margin: 1em 0 0 1em;
}

div.withBlock {
  /* we want the <div> to collapse to the size of the
     <textarea>: */
  display: inline-block;
}

div.withBlock textarea {
  /* using display: block to force the <button> to a new
     line: */
  display: block;
}

div.withBlock button {
  /* specifying a 100% width, which will cause the
     <button> to be the full width of the parent -
     <div> - element, which is itself shrunk down 
     to the width of the <textarea>: */
  width: 100%;
  /* to separate the two elements for visibility: */
  margin-top: 10px;
}

div.withGrid {
  /* using CSS Grid layout: */
  display: grid;
  /* defining the one column as min-content, which
     causes the column to be the minimum width 
     required to display its largest content (in this
     case that is the <textarea> with its defined width:*/
  grid-template-columns: min-content;
  /* to separate the contents from each other with a
     10px gutter: */
  grid-gap: 10px;
}

div.withFlex {
  /* this emulates the previous 'display: inline,' but
     uses the flexbox layout within the <div>; causing
     the <div> to collapse to the size of its largest
     child element: */
  display: inline-flex;
  /* the automatic value of flex-direction is 'row,' so
     because we want columns (I think) we're specifying
     the following value: */
  flex-direction: column;
}

div.withFlex button {
  margin-top: 1em;
}
<!-- we wrap each <textarea> and <button> pair in a parent <div>,
     though in practice you may have them wrapped in something
     like a <fieldset>, or the <textarea> may be wrapped in a
     <label> with the <button> being a sibling of that <label> -->
<div class="withBlock">
  <textarea cols="50" rows="10"></textarea>
  <button>the button</button>
</div>

<div class="withGrid">
  <textarea cols="50" rows="10"></textarea>
  <button>the button</button>
</div>

<div class="withFlex">
  <textarea cols="50" rows="10"></textarea>
  <button>the button</button>
</div>

JS小提琴演示

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

css中的字体大小的度量单位

来自分类Dev

在System.Numerics.Vector <T>中使用F#度量单位

来自分类Dev

MySQL的空间缓冲区调用中使用的度量单位是什么?

来自分类Dev

MySQL的空间缓冲区调用中使用的度量单位是什么?

来自分类Dev

在视口单位中使用CSS Calc

来自分类Dev

使用度量单位计算轨迹

来自分类Dev

使用squants库,如何为方法指定特定的度量单位?

来自分类Dev

javascript中文件大小使用什么度量单位?

来自分类Dev

如何使用精确的单位和度量创建图

来自分类Dev

在度量中使用相关表值

来自分类Dev

Delphi中使用单位的顺序

来自分类Dev

在annotate()中使用npc单位

来自分类Dev

nltk标记化度量单位

来自分类Dev

/ proc / PID /预定的度量单位

来自分类Dev

nltk标记化度量单位

来自分类Dev

我可以在CSS3矩阵转换中使用百分比单位吗

来自分类Dev

我应该使用哪个度量单位进行响应式设计?

来自分类Dev

在熊猫中使用小时单位to_timedelta

来自分类Dev

如何在Excel中使用单位缩写?

来自分类Dev

在系统单位中使用动态日期

来自分类Dev

在pnorm命令中使用Y轴单位?

来自分类Dev

在 SVG 中使用不同的单位

来自分类Dev

在Weka中使用加权平均F度量有什么优势

来自分类Dev

何时在Power BI中使用计算字段与度量?

来自分类Dev

在SSRS的度量值组中使用多值参数

来自分类Dev

可以在Excel中使用度量“ k”表示法吗?

来自分类Dev

在度量中使用计算列时出错

来自分类Dev

Typedef将度量单位放入C

来自分类Dev

glVertex参数以什么单位度量?