javascript - 如何为元素及其边框设置不同的光标

标签 javascript html css

如何为一个元素和它的边框设置不同的光标? 伪元素?有办法吗? 注意:是的,它可以通过 JS 完成,我正在寻找一种使用纯 CSS 和单个元素的方法。

最佳答案

它有很多 HTML/CSS 代码,但类似的内容会对您有所帮助:

.container {
  position: relative;
}
.crop {
  position: absolute;
  top: 10px;
  left: 100px;
  width: 100px;
  height: 100px;
  transition: all 0.25s;
  cursor: move;
}

.crop .crop-line {
  position: absolute;
  transition: all 0.25s;
}
.crop:hover .crop-line {
  border-color: rgba(123,53,132,1);
}
.crop .crop-top-line {
  top: 0;
  left: 0;
  right: 0;
  height: 5px; /* 5px for the mouse cursor update size */
  border-top: 1px solid rgba(204,31,48,1); /* 1px for the "border" size */
  cursor: n-resize;
}
.crop .crop-bottom-line {
  bottom: 0;
  left: 0;
  right: 0;
  height: 5px; /* 5px for the mouse cursor update size */
  border-bottom: 1px solid rgba(204,31,48,1); /* 1px for the "border" size */
  cursor: s-resize;
}
.crop .crop-left-line {
  top: 0;
  left: 0;
  bottom: 0;
  width: 5px; /* 5px for the mouse cursor update size */
  border-left: 1px solid rgba(204,31,48,1); /* 1px for the "border" size */
  cursor: w-resize;
}
.crop .crop-right-line {
  top: 0;
  right: 0;
  bottom: 0;
  width: 5px; /* 5px for the mouse cursor update size */
  border-right: 1px solid rgba(204,31,48,1); /* 1px for the "border" size */
  cursor: e-resize;
}
.crop .crop-corner {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 2px;
  border: 1px solid #808080;
  background: #FFF;
  opacity: 0;
  transition: all 0.25s;
}
.crop .crop-top-left-corner {
  top: -3px;
  left: -3px;
  cursor: nw-resize;
}
.crop .crop-top-right-corner {
  top: -3px;
  right: -3px;
  cursor: ne-resize;
}
.crop .crop-bottom-left-corner {
  bottom: -3px;
  left: -3px;
  cursor: sw-resize;
}
.crop .crop-bottom-right-corner {
  bottom: -3px;
  right: -3px;
  cursor: se-resize;
}
.crop:hover .crop-corner {
  opacity: 1;
}
 <div class="container">
  <div class="crop">
   <div class="crop-line crop-top-line"></div>
   <div class="crop-line crop-right-line"></div>
   <div class="crop-line crop-bottom-line"></div>
   <div class="crop-line crop-left-line"></div>

   <div class="crop-corner crop-top-left-corner"></div>
   <div class="crop-corner crop-top-right-corner"></div>
   <div class="crop-corner crop-bottom-right-corner"></div>
   <div class="crop-corner crop-bottom-left-corner"></div>
  </div>
 </div>

关于javascript - 如何为元素及其边框设置不同的光标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12967876/

相关文章:

javascript - 如何在Javascript中从Azure Blob存储下载数据后将base64编码的数据嵌入图像中?

javascript - 使用 Javascript CSS 属性添加背景图片

python - 查找包含字符串的元素的xpath

html - CSS - 在环绕的跨度左侧填充

css - 将 css 类或 id 分配给 cakephp 中的工具提示

CSS on Wrap 全部清除

javascript - 如何引用 .json 文件中的 i18n 条目?

JavaScript 变量未通过 getElementById() 获取 id 的值

html - 为什么我的电话号码 href 链接重定向到 'About:Blank' 地址,我该如何解决这些问题?

html - 如何加载 HTML 页面的打印友好版本?