我可以设置文本区域的大小调整抓取器的样式吗?

问题描述 投票:0回答:7

我的设计师刚刚给了我带有带有样式调整大小抓取器的文本区域的设计。问题是:我可以设计它吗?

css resize textarea
7个回答
93
投票

WebKit 提供伪元素

::-webkit-resizer
用于调整大小控件,它会自动添加到
textarea
元素的右下角。

可以通过应用

display: none
-webkit-appearance: none
来隐藏它:

::-webkit-resizer {
  display: none;
}
<textarea></textarea>

在 OS X 上的 Chrome 26 中显示如下:

This displays as follows in Chrome 26 on OS X:

注意:将

display: none
添加到
::-webkit-resizer
实际上并不会阻止用户调整文本区域的大小,它只是隐藏控件。如果要禁用调整大小,请将
resize
CSS 属性设置为
none
。这也隐藏了控件,并且具有在所有支持调整文本区域大小的浏览器中工作的额外好处。

::-webkit-resizer
伪元素还允许一些基本的样式。如果您认为调整大小控件可以使用更多的颜色,您可以添加以下内容:

::-webkit-resizer {
  border: 2px solid black;
  background: red;
  box-shadow: 0 0 5px 5px blue;
  outline: 2px solid yellow;
}
<textarea></textarea>

在 OS X 上的 Chrome 26 中显示如下:

This displays as follows in Chrome 26 on OS X:


24
投票

您可以使用一些标记创建“自定义”句柄,而不是将 CSS 应用于

::-webkit-resizer
(这似乎在 Chrome 56 或 FireFox 51 中不起作用)。我在谷歌搜索后发现了这个例子:

自定义 CSS3 TextArea 调整大小手柄

复制标记以防将来出现死链接:

<div class="wrap">
  <div class="pull-tab"></div>
  <textarea placeholder="drag the cyan triangle..."></textarea>
</div>

以及示例中的 CSS - 当然,您可以应用您喜欢的任何样式:

textarea {
    position: relative;
    margin: 20px 0 0 20px;
    z-index: 1;
}
.wrap {
    position: relative;
    display: inline-block;
}
.wrap:after {
    content:"";
    border-top: 20px solid black;
    border-left: 20px solid transparent;
    border-right: 20px solid transparent;
    -webkit-transform: rotate(-45deg);
    z-index: 1;
    opacity: 0.5;
    position: absolute;
    right: -18px;
    bottom: -3px;
    pointer-events: none;
}
.pull-tab {
    height: 0px;
    width: 0px;
    border-top: 20px solid cyan;
    border-left: 20px solid transparent;
    border-right: 20px solid transparent;
    -webkit-transform: rotate(-45deg);
    position: absolute;
    bottom: 0px;
    right: -15px;
    pointer-events: none;
    z-index: 2;
}

12
投票

textarea::-webkit-resizer {
  border-width: 8px;
  border-style: solid;
  border-color: transparent orangered orangered transparent;
}
<textarea/>


5
投票

为什么不只显示背景图片? http://jsfiddle.net/1n0d529p/

textarea {
  background: url(https://image.flaticon.com/icons/svg/133/133889.svg)no-repeat rgba(71, 108, 193, 0.52) 99.9% 100%;
  background-size: 12px;
}

3
投票

使用@HorusKol 的方法设计文本区域的大小调整抓取器的样式

Codepen 网址

textarea {
    /* Ignore this part of code - basic textarea formatting */
    margin-top: 20px;
    margin-left: 20px;
    width:300px;
    padding:20px;
    border:1px solid #CCC;
    border-radius: 4px;
    /* Comment below line to resize horizontal + vertical */
    resize:vertical 
    /* Step 1 */
    position: relative;
}
    /* Step 2 */
.wrap {
    position: relative;
    display: inline-block;
}
    /* Step 3 - - Sets the 1st line of resize icon */
.wrap:after {
    content:"";
    border-top: 2px solid #555;
    width:16px;
    transform: rotate(-45deg);
    background:transparent;
    position: absolute;
    right: 1px;
    bottom: 14px;
    pointer-events: none;
    border-radius:25%;
}
    /* Step 4 - Sets the 2nd line of resize icon */
.pull-tab {
    border-top: 2px solid #555;
    width:10px;
    transform: rotate(-45deg);
    position: absolute;
    bottom: 10px;
    right: 1px;
    pointer-events: none;
    border-radius:25%;
}
    /* Step 5 - Removes the default resizer grabber icon */
::-webkit-resizer{
  display:none;
}
<div class="wrap">
    <div class="pull-tab"></div>
    <textarea placeholder="Customized resizer grabber...">
    </textarea>
</div>


2
投票

我设法这样做了:

.textarea-container:before {
    content: '';
    background-image: url('svg/textarea-resize.svg');
    background-size: 16px;
    background-repeat: no-repeat;
    position: absolute;
    width: 20px;
    height: 20px;
    bottom: 2px;
    right: 0;
    pointer-events: none;
}

-1
投票

textarea {
  resize: none;
}
<textarea cols="72" rows="14"></textarea>

© www.soinside.com 2019 - 2024. All rights reserved.