我已经构建了一个展开的箭头,我希望"里面"的白色区域可以点击(整个红色矩形).

enter image description here

不幸的是,我不能在它周围添加一个div,所以我需要一个替代解决方案.

.sageata {
    height: 2px;
    width: 40px;
    position: relative;
    display: inline-block;
    cursor: pointer;
    margin-right: 15px;
    margin-bottom: 4px;
    transition: all .4s ease;
    background: #000000;
    padding: 0 !important;
}

.sageata:hover {
    width: 50px;
    margin-right: 5px;
    background: #000000 !important;
}

.sageata::before,
.sageata::after {
    content: "";
    background: #000000;
    position: absolute;
    height: 2px;
    width: 15px;
    border-radius: 30%;
}

.sageata::before {
    right: -2px;
    bottom: -5px;
    transform: rotate(-45deg);
    top: auto !important;
    left: auto !important;
}

.sageata::after {
    right: -2px;
    top: -5px;
    transform: rotate(45deg);
}
<a class="sageata" href="#"></a>

推荐答案

您可以增加锚点的高度,并使用背景gradient而不是全尺寸 colored颜色 .

.sageata {
  height: 24px;
  width: 40px;
  position: relative;
  display: inline-block;
  cursor: pointer;
  margin-right: 15px;
  margin-bottom: 4px;
  transition: all .4s ease;
  background: linear-gradient(to bottom, 
    transparent 0%, 
    transparent calc(50% - 1px),  
    #000 calc(50% - 1px), 
    #000 calc(50% + 1px), 
    transparent calc(50% + 1px), 
    transparent 100%
  );
  padding: 0 !important;
}

.sageata:hover {
  width: 50px;
  margin-right: 5px;
}

.sageata::before,
.sageata::after {
  content: "";
  background: #000000;
  position: absolute;
  height: 2px;
  width: 15px;
  border-radius: 30%;
}

.sageata::before {
  right: -2px;
  bottom: 5px;
  transform: rotate(-45deg);
  top: auto !important;
  left: auto !important;
}

.sageata::after {
  right: -2px;
  top: 5px;
  transform: rotate(45deg);
}
<a class="sageata" href="#"></a>

Html相关问答推荐

当在双引号|Angular .html文件中使用时,Pretier会将单引号字符替换为&;Quot;

如何使用css为动态用户输入矩阵添加背景色?

防止SVG边框半径zoom

将弹性容器设置为内容宽度

我应该怎么做才能显示出整个字符串?

不呈现孙子元素,使用R htmlTools::Taglist为分页的pdf生成HTML

如何在没有包装元素的情况下在React(Next.js)中呈现HTML注释

网格布局中的组件

如何在黑暗模式切换中添加图标

并排放置两个 div,同时 div2 环绕 div1

如何在CSS伪类函数中使用复合 Select 器:host-context()

为什么即使我点击其他地方,我的 contenteditable="true" 也会被激活?

如何消除线性渐变线的模糊?

调整窗口大小时文本重叠导航栏

为什么使用 Css 只能看到 1 列而不是 3 列?

无法使用 flexbox 裁剪图像

HTML 标记未在页面上展开

为什么将 p 元素的垂直边距设置为 1 px 会出现滚动条?

html tailwindcss 给 li 标签添加边框

左右图像,响应页面大小并居中