javascript - 将 anchor 链接添加到 Div 及其伪元素(CSS 或 Javascript/jQuery)

标签 javascript jquery css anchor pseudo-element

我在菜单上有一个 anchor 链接,上面有一个图标。我需要它,以便当有人单击菜单项或它上面带有图标的伪元素时,链接会起作用。

我这里有一个代码笔:http://codepen.io/emilychews/pen/wJrqaR

红色方 block 是将包含图标的伪元素。

代码是:

CSS

.menu {
    position: relative;
    left: 50px;
    top: 50px;
    height: 30px;
    width: 100px;
    background: blue;
    line-height: 30px;
    text-align: center;
}

.menu:before {
    content:'';
    position: absolute;
    width: 100%;
    height: 100%;
    background: red;
    bottom: 40px;
    right: 0px;
}

.menu-item1 a { color: white; text-decoration: none; }

HTML

<div class="menu menu-item1"><a href="//google.com">Menu Item</a></div>

任何帮助都会很棒。

艾米丽。

最佳答案

a {
  position: relative;
  display: inline-block;
  left: 50px;
  top: 50px;
  height: 30px;
  width: 100px;
  background: blue;
  line-height: 30px;
  text-align: center;
  color: white; 
  text-decoration: none;
}

a:before {
  content:'icon';
  position: absolute;
  width: 100%;
  height: 100%;
  background: red;
  bottom: 40px;
  right: 0px;
}
<div class="menu">
  <a href="//google.com">Google</a>
  <a href="//yandex.com">Yandex</a>
</div>

关于javascript - 将 anchor 链接添加到 Div 及其伪元素(CSS 或 Javascript/jQuery),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42819126/

相关文章:

javascript - javascript对象中的平等?

javascript - 合并 Canvas 和背景

css - Google Chrome 开发者工具有时无法打开 css 文件?

css - 垂直降低盒子阴影

javascript - 如果我声明 CSS 中的 id 与 Javascript 中的 id 重复,会发生什么情况?

javascript - 动画div定位重排

javascript - Firefox 和 Chrome 窗口宽度/高度显示不同

jquery 单击处理程序将单击对象的属性传递给函数?

javascript - 点击功能上的简单 Jquery 动画位置

css - 如何在 CSS 中根据高度(默认情况下根据宽度)设置边距/填充百分比 ..?