【问题标题】:how to change the resize property icon and the cursor on hover如何更改调整大小属性图标和悬停光标
【发布时间】:2017-11-24 11:39:28
【问题描述】:

我想更改以下 div 右下角的调整大小图标(参见下面的代码 sn-p),我还想更改悬停时的光标(例如 e-resize 光标)

我尝试添加:

#resizableDiv::-webkit-resizer {
cursor:e-resize;
background-image: url(some_image.png);
}

但徒劳无功,我怎么能做到这一点,毕竟有可能吗?

#resizableDiv {
overflow:auto;
border:1px;
height:100px;
width:200px;
resize:horizontal;
display:inline-block;
background-color:yellow;
}
<div id="resizableDiv">
Resizable div for a single user working with Chrome
</div>

【问题讨论】:

标签: html css


【解决方案1】:

考虑在单独嵌套的元素中使用图标元素。
pseudo-element 的帮助下,您将能够实现预期的行为,如下面的代码 sn-p 所示。

代码片段演示:

#resizableDiv {
  overflow:auto;
  border:1px;
  height:100px;
  width:200px;
  resize:horizontal;
  display:inline-block;
  background-color:yellow;
  position: relative; /* required */
}

/* Additional */

div#resizableDiv:after {
    content: "";
    resize: horizontal;
    bottom: 0;
    right: 0;
    cursor: e-resize;
    position: absolute;
    z-index: 9;
    width: 20px;
    height: 20px;
}

.resizeUI {
  position: absolute;
  bottom: 0;
  right: 0;
  background: inherit;
  padding: 0px 3px;
  pointer-events: none;
  cursor: e-resize;
}
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.css">
<div id="resizableDiv">
Resizable div for a single user working with Chrome
<div class="resizeUI"><i class="fa fa-arrows-h"></i></div>
</div>

【讨论】:

  • 您应该使用光标文件/图像进行演示,而不是使用浏览器内置光标,例如e-resize(取决于浏览器)。
  • 当这是 OP 建议的时候,为什么不使用 e-resize? “我还想更改悬停时的光标(例如 e-resize 光标)”
  • @AndreiGheorghiu 为什么文件图像比使用支持的样式规则更好?此外,刚刚在 MDN (developer.mozilla.org/en-US/docs/Web/CSS/cursor) 上快速查看了 cursor 属性的值,我看不到在这方面对浏览器特定规则的引用。您能否扩展您的推理并提供参考链接?不仅为我自己,也为任何可能好奇的人。
  • @MehdiSouregi 你为我提出了一个有价值的挑战 :)
  • 根据我对问题的理解,OP 希望将光标更改为自定义图像并且在所有浏览器中都相同(这将支持该功能),而不是使用不同的图像来调整光标大小,取决于浏览器。既然 OP 接受了你的回答,我一定是把他们的问题理解错了。
最近更新 更多