html - 如何填补垂直子菜单上的空白?

标签 html css

<!DOCTYPE html>

<html>
    <head>
        <title>Test</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
        <style>

            h1{

                background: blueviolet;

                font-size:70px;
                font-weight: bolder;
                margin:0 auto;
                padding:15px;
                text-align: center;

            }  

         ul ul {
    display: none;

          }



         ul li:hover > ul{

        display: block;


    }

         .ul1  {
            position:absolute;
            top: 15px;
            width:50%;
            font-size: 30px;

            }





       .ul1 li{

             /* display: block;*/
              list-style-type: none;  
              background: black;
              border-right: 1px solid white;
              color:white;
              width: 90px;
              float:left;
              text-align: center;
              text-decoration: none;

              padding: 5px;

            }




        .sub1 li  a{
          list-style-type:none;  
          background: black;

          color:white;
          text-align: center;
          text-decoration: none;    





      }

       .ul1 li:last-child {
        border-right: none;

        }

        .sub1 li,a{

            border-right: none;  


        }



         .ul1 :hover {

               background: black; 
               color: yellow;

            }  


            .sub1 li{


                position: relative;
                right:45px;

            } 



        .sub1 li:hover {
         background: white;
         color:black;

      }   

        .sub1 a:hover {
         background: white;
         color: black;
         text-decoration: underline;

     } 
            img{

                width: 200px;
                height: 200px;
              /*  position: absolute;*/
                top:270px;
                float: left;

                transition: all .2s ease-in-out;
            }   

            img:hover{


         transform:scale(1.9);

            }




            .p2{

            font-size:24px;
            margin: 0px;
            color:blue;
            margin-right: 25px;




            } 





       body{

           background: grey;



       }

     /*  @media(max-width:500px){
           h1 {

         float: right; 

           }
       }*/


        </style> 



    </head>
    <body>
       <div id="div0">



            <h1 >Καλήμερα Ελλάδα!!</h1>


                <ul class="ul1">

                    <li>Home</li>
                    <li>Menu</li>

                    <li>Menu2
                    <ul class="sub1">
                    <li>Home</li>
                    <li>Menu</li>
                    <li id="ok"><a href="testindex.html" target="_blank">Menu2</a></li> 

                    </ul>
                    </li>



                </ul>









                <p class="p1">

                <img src="./images/im1.png"  > 



                </p>


                  <p class="p2"> 


            </p>








        </div>


    </body>
</html>

在子菜单 Menu2 链接上,我如何填补空白? 如果将鼠标指向 Menu2,您将看到它没有正确填充。

最佳答案

我删除了“.sub1 li a”上的黑色背景,并创建了一个新的选择器“.sub1 li:hover a”,并将颜色设置为黑色。可以在下面找到更新的代码。

h1 {
  background: blueviolet;
  font-size:70px;
  font-weight: bolder;
  margin:0 auto;
  padding:15px;
  text-align: center;
}

ul ul {
  display: none;
}

ul li:hover > ul {
  display: block;
}

.ul1 {
  position:absolute;
  top: 15px;
  width:50%;
  font-size: 30px;
}

.ul1 li {
  /* display: block;*/
  list-style-type: none;
  background: black;
  border-right: 1px solid white;
  color: white;
  width: 90px;
  float: left;
  text-align: center;
  text-decoration: none;
  padding: 5px;
}
.sub1 li a {
  list-style-type: none;
  color: white;
  text-align: center;
  text-decoration: none;
}

.ul1 li:last-child {
  border-right: none;
}

.sub1 li, a {
  border-right: none;
}

.ul1 :hover {
  background: black;
  color: yellow;
}

.sub1 li {
  position: relative;
  right:45px;
}

.sub1 li:hover {
  background: white;
  color:black;
}

.sub1 li:hover a {
  color: black;
}

.sub1 a:hover {
  background: white;
  color: black;
  text-decoration: underline;
}

img {
  width: 200px;
  height: 200px;
  /*  position: absolute;*/
  top: 270px;
  float: left;
  transition: all .2s ease-in-out;
}

img:hover {
  transform: scale(1.9);
}

.p2 {
  font-size: 24px;
  margin: 0px;
  color: blue;
  margin-right: 25px;
}

body {
  background: grey;
}

/*  @media(max-width:500px){
  h1 {
    float: right;
      }
  }*/
<div id="div0">
  <h1>Καλήμερα Ελλάδα!!</h1>
  <ul class="ul1">
    <li>Home</li>
    <li>Menu</li>
    <li>Menu2
      <ul class="sub1">
        <li>Home</li>
        <li>Menu</li>
        <li id="ok"><a href="testindex.html" target="_blank">Menu2</a></li>
      </ul>
    </li>
  </ul>
  <p class="p1">
    <img src="./images/im1.png">
  </p>
  <p class="p2">
  </p>
</div>

关于html - 如何填补垂直子菜单上的空白?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39851087/

相关文章:

html - 获取导航栏的元素居中

html - chrome 上的 css 填充问题

html - 为什么绝对 parent 得到 child 的高度而相对 parent 没有?

html - 创建 slider 但无法将图像置于绝对 div 的中心

javascript - Jquery onclick 关闭按钮,隐藏整个范围包括关闭按钮

html - IE 不会用行高计算文本区域的高度

css - 在 bootstrap 4 中关闭折叠的导航栏后,导航栏元素仍然可见一段时间

html - 边缘白色条纹

html - 内联 block 元素的水平滚动

html - 为 2 个部分添加相同的背景