如何更改调整大小手柄的外观?
我不想完全关闭调整大小,但文本区域上的调整大小手柄不适合页面样式的其余部分。有没有办法改变它的外观,也许用我自己的图像替换它?对于不支持 HTML5 的浏览器,不必向后兼容。
I don't want to turn off resizing completely, but the resize handles on textareas don't fit with the rest of the page style. Is there a way I can change how it looks, perhaps replacing it with an image of my own? There doesn't have to be backward compatibility for browsers that don't support HTML5.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我通过将文本区域包装在 DIV 中,然后在该 div 中放置一个 ::after 元素来实现此目的,该元素包含一个符号并且具有与文本区域相同的背景颜色。
重要的是给 ::after 元素“pointer-events: none;”因为否则用户无法点击它。这适用于所有现代浏览器(http://caniuse.com/#feat=pointer-events)。
这是一个小提琴:http://jsfiddle.net/herrfischerhamburg/59wy0ttj/7/
I made this by wrapping the textarea in a DIV, then placing a ::after element in that div which contains a symbol and has the same background-color as the textarea.
It is important to give the ::after element "pointer-events: none;" because otherwise the user can not click through it. This works in all modern browsers (http://caniuse.com/#feat=pointer-events).
Here is a fiddle: http://jsfiddle.net/herrfischerhamburg/59wy0ttj/7/
这是一项艰难的任务。无法设置此特定控件的样式。即使你在 webkit 下强制使用不同的外观,你仍然可以获得调整大小手柄:
但是,您可以解决这个问题,并将背景图像放置在左下角:
但处理程序仍会出现在其顶部。
恐怕唯一的选择是使用 javascript。
This is a tough one. There is no way of styling this specific control. Even if you force a different appearance under webkit you still get the resize handle:
You can, however, work around it and place a background image in the bottom left corner:
But the handler will still appear on top of it.
I'm afraid the only alternative is using javascript.
这样做:
将图像放置在默认手柄所在的右下角顶部!绝对位置等。
然后在图片上设置指针事件:无,您就完成了!就像指针完全忽略图像并且事件在文本区域本身上进行。
干杯!!
注意:也许您必须使用 resize: 垂直于文本区域,因为行为因浏览器而异!
请参阅:https://jsfiddle.net/1bsoffu3/1/
a
Do it like this:
Place an image on top of the bottom right corner where the default handle is! Position absolute etc.
Then on the picture set pointer-events: none and you are done! It is like the pointer ignores completely the image and the events go on the textarea itself.
Cheers!!
NOTE: Maybe you have to use resize: vertical to the textarea because the behavior changes from browser to browser!!
SEE THIS: https://jsfiddle.net/1bsoffu3/1/
a
这在浏览器中不可能。
我们必须在其顶部添加一个元素并使用
pointer-event: none
。由于浏览器在调整大小时以内联样式设置div
高度(以像素为单位),因此使用position:absolute
或将元素粘贴在其上位置:固定
很难。因为我们的相对定位单位vh vw rem em %
不知道最新的height
值。这需要 JavaScript 或动态 CSS 变量之类的东西来读取元素的当前高度。修改是可行的,但通常会导致错位以及有趣且不受欢迎的视差效果。
或者,我们必须在 HTML 中添加额外的标记。
因为对眼睛有好处,我们可以使用水平线,即
元素。这样可以保持级联效应。此示例将 ↕️ 设置为调整大小句柄,方法是在下一个
上添加::after
规则,单击槽。当然,必须为此用途保留
,或者使用类。、
和
元素的使用在这里并不重要,但它与元素之间的
用于调整大小手柄效果。我们还可以使用
! 以外的其他内容。This is NOT possible across browsers.
We have to add an element on top of it and use
pointer-event: none
. Because the browser set thediv
height in pixel in a inline style at resizing, sticking an element over it usingposition: absolute
orposition: fixed
is difficult. Because our relative positioning unitsvh vw rem em %
have no clue of the newestheight
value.This would require JavaScript, or something like dynamic CSS variables to read the current height of the element. Hacks around are doable but often leads to misalignments, and funny and unwanted parallax effects.
Alternatively, we have to add an extra markup in the HTML.
Because good for the eyes, we can use horizontal lines, the
<hr>
element. This way the cascading effect is kept. This example sets ↕️ as a resize handle, by adding a::after
rule on the next<hr>
, clicking trough. Of course<hr>
has to be reserved for this usage, or use a class.The use of
<dd>
,<dl>
and<dt>
elements is not important here, but it's about the use of a<hr>
between elements for the resizing handle effect. Also we can use something else than<hr>
!.