简体   繁体   English

影响父div在儿童悬停时

[英]affect parent div on child hover

I have a usage of react simple tabs https://github.com/pedronauck/react-simpletabs , which generates 我有一个使用react简单标签的用法https://github.com/pedronauck/react-simpletabs ,它会生成

<div class='tabs'>
    <nav class='tabs-navigation'>
      <ul class='tabs-menu'>
        <li class='tabs-menu-item is-active'>Tab #1</li>
        <li class='tabs-menu-item'>Tab #2</li>
      </ul>
    </nav>
    <article class='tab-panel'>
      The content of active panel here
    </article>
  <div>

My goal is to hover over a non-active tab and make the border (top, left, right) a darker grey so users know it's a tab. 我的目标是将鼠标悬停在非活动的标签上,并使边框(顶部,左侧,右侧)变深,以便用户知道它是标签。

I tried using pointer events like How to style the parent element when hovering a child element? 我试过使用指针事件,例如如何在悬停子元素时设置父元素的样式? and it didn't break anything, but it didn't work. 它没有破坏任何东西,但是没有用。

I have css now 我现在有CSS

.tabs-menu {
  display: table;
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 1.5em;
}

.tabs-menu-item {
  float: left;
  margin-right: 20px;
  padding: 10px 10px 0px;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  pointer-events: none;

  /*background-color: white;*/
}

.tabs-menu-item:hover {
    border-top: 2px solid #808080;
    border-left: 1px solid #808080;
    border-right: 1px solid #808080;
}

.tabs-menu-item a {
  cursor: pointer;
  display: block;
  color: #A9A9A9;
  pointer-events: auto;
}

.tabs-menu-item:not(.is-active) a {
    color: #f96302;
}

.tabs-menu-item:not(.is-active) a:hover {
    color: #ff8000
}

.tabs-menu-item.is-active a {
    color: #3498DB;
}

.tabs-menu-item.is-active {
    border-top: 3px solid orange;
    border-left: 1px solid grey;
    border-right: 1px solid grey;
}

.tabs-menu-item:not(.is-active) {
    border-top: 2px solid #e6e6e6;
    border-left: 1px solid #e6e6e6;
    border-right: 1px solid #e6e6e6;
}

.tabs-menu-item.is-active a {
color   : black;
}

.tabs-menu-item.is-active a:hover {
    cursor: default;
    text-decoration: none;
}

article .tab-panel {
    margin-top: 0px;
}
/*.tab-panel {
  padding: 10px 50px;
}*/

Checking you code for "tabs-menu-item" class pointer-event is set to none. 检查代码是否为“ tabs-menu-item”类的指针事件设置为none。 I overrode it here ".tabs-menu-item:not(.is-active)". 我在这里覆盖了“ .tabs-menu-item:not(.is-active)”。 I don't know whether it was intentionally put. 我不知道它是否被故意放了。 See code below 见下面的代码

 .tabs-menu { display: table; list-style: none; padding: 0; margin: 0; font-size: 1.5em; } .tabs-menu-item { float: left; margin-right: 20px; padding: 10px 10px 0px; font-size: 15px; font-weight: 600; text-align: center; pointer-events: none; /*background-color: white;*/ } .tabs-menu-item:hover { border-top: 2px solid #808080; border-left: 1px solid #808080; border-right: 1px solid #808080; } .tabs-menu-item a { cursor: pointer; display: block; color: #A9A9A9; pointer-events: auto; } .tabs-menu-item:not(.is-active) a { color: #f96302; } .tabs-menu-item:not(.is-active) a:hover { color: #ff8000 } .tabs-menu-item.is-active a { color: #3498DB; } .tabs-menu-item.is-active { border-top: 3px solid orange; border-left: 1px solid grey; border-right: 1px solid grey; } .tabs-menu-item:not(.is-active):hover { border-top: 2px solid #e6e6e6; border-left: 1px solid #e6e6e6; border-right: 1px solid #e6e6e6; } .tabs-menu-item:not(.is-active) { pointer-events: visible; cursor: default; } .tabs-menu-item.is-active a { color : black; } .tabs-menu-item.is-active a:hover { cursor: default; text-decoration: none; } article .tab-panel { margin-top: 0px; } /*.tab-panel { padding: 10px 50px; }*/ 
 <div class='tabs'> <nav class='tabs-navigation'> <ul class='tabs-menu'> <li class='tabs-menu-item is-active'>Tab #1</li> <li class='tabs-menu-item'>Tab #2</li> </ul> </nav> <article class='tab-panel'> The content of active panel here </article> <div> 

This question has been asked before, please see here: 之前已经问过这个问题,请在这里查看:

How to style the parent element when hovering a child element? 悬停子元素时如何设置父元素的样式?

Just as mentioned, cascading stylesheets implements a direct logical flow. 如前所述,级联样式表实现了直接的逻辑流程。 There are usually other possibilities to get the same thing done however, such as giving it a sibling and a parent like the example when you follow the link. 但是,通常还有其他方法可以完成相同的工作,例如当您跟随链接时,给它一个兄弟姐妹和一个像示例一样的父对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM