简体   繁体   English

菜单项中svg图像之间的间隙填充

[英]Gap filler between svg images in menu items

I have a menu that is made up of ul and li the list items nest SVGs as the items that will show up in the menu. 我有一个由ul和li组成的菜单列表项嵌套SVG作为将显示在菜单中的项目。 inside the first ul, li nested another ul,li that shows up on hover as a submenu, everything works fine but I want to create a gap filler around my SVGs in the item menu so that when I hover a little bit away from the image, the sub menu would still appear. 在第一个ul里面,li嵌套了另一个ul,li,它显示为悬停为子菜单,一切正常,但我想在项目菜单中围绕我的SVG创建一个填隙填充,这样当我稍微离开图像时,子菜单仍然会出现。

I searched that and find some ways involved using the pseudo class ::after, but did not manage to make it work 我搜索了一下并找到了一些使用伪类:: after的方法,但没有设法让它工作

This is my code 这是我的代码

<div id="menu">
<ul>
 <li> <img  src="this is just for code"/>
 <ul>
 <li> <a href="#">link</a></li>
 <li> <a href="#">link2</a>/li>
 </ul>
 </li>
 <li> <img  src="this is just for code"/>
  <ul>
  <li> <a href="#">link</a></li>
  <li> <a href="#">link</a></li>
 </ul>
  </li>

the css is css是

#menu ul li{
    width:auto;   
    height:2.5em;   
    list-style:none;
    float:left;
    margin: 0em 20px 0em 20px ;
    padding: 0px  ;   
    cursor:pointer;
    justify-content:space-between;

 #menu ul ul li{
float:none;
width:100%;
height:auto;
padding: 1em 0;
text-align:center;

 #menu ul li:hover > ul{

display:block;  }

   #menu ul li img{
        width:inhrtit;
        height:inherit;
        margin: 0 0 60px 0;
        position:relative;
        bottom:0.6em;


        }   

   #menu ul li:hover > ul::after{
        width:auto;
        height:2.5em;
        padding:0px 100px;
        margin: 90px;
        position:absolute;
        right:70px; left:90px;
        pointer-events: none;
        -webkit-transform: translateX(-110%);
        transform: translateX(-110%);

        }
    #menu ul li:hover > ul::after   {
pointer-events: auto;

    }

Sorry my code is lousy. 对不起,我的代码很糟糕。 as the first question I hope this is not an enough dump one. 作为第一个问题,我希望这不是一个足够的转储。

Since you're looking to increase the hover area of <li> elements, you can add padding to them. 由于您希望增加<li>元素的悬停区域,因此可以为它们添加填充。

For example, below is an example of using padding to increase the clickable area. 例如,下面是使用填充来增加可点击区域的示例。 Increasing hover area is similar. 增加悬停区域是类似的。

https://jsfiddle.net/gazg1yuy/ https://jsfiddle.net/gazg1yuy/

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

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