简体   繁体   English

与上述元素相同的 CSS 下划线

[英]CSS underline with same with as above element

I am trying to create the following look:我正在尝试创建以下外观:

在此处输入图片说明

As you can see on this picture even if there is some padding on the "sub" menu item the border still works.正如您在这张图片上看到的,即使“子”菜单项上有一些填充,边框仍然有效。

So here is what I've attempted:所以这是我尝试过的:

 .menu-ul { list-style-type: none; } .menu-li { padding: 10px 0; border-bottom: 1px solid rgba(50, 50, 50, 0.3); width: 100%; } a { font-family: Titillium Web; font-style: normal; font-weight: 600; font-size: 16px; line-height: 24px; letter-spacing: 0.02em; color: #323232; text-decoration: none; } a:hover { color: #DB091C; } .sub-menu-ul { padding: 0px; list-style-type: none; border-top: 1px solid rgba(50, 50, 50, 0.3); } .sub-menu-li { padding: 10px; width: calc(100% - 20px); border-top: 1px solid rgba(50, 50, 50, 0.3); } hr.solid { border-top: 3px solid #bbb; }
 <link href="https://pro.fontawesome.com/releases/v5.14.0/css/all.css" rel="stylesheet"/> <nav style="width: 300px"> <ul class="menu-ul"> <li class="menu-li"> <a href="" >Title </a> <span style="float: right"><i class="fa fa-angle-down"></i></span> <div style="display: block"> <ul class="sub-menu-ul"> <li class="sub-menu-li"> <a href="#"> Sub menu item2 </a> <span style="float: right"><i class="fa fa-angle-right"></i></span> </li> </li> <li class="sub-menu-li"> <a href="#"> Sub menu item2 </a> </li> </ul> </div> </li> <li class="menu-li"><a href="" >Title 2</a> </li> <li class="menu-li"><a href="" >Title 2</a> </li> </ul> </nav>

But I can't seem to get the border right.但我似乎无法正确设置边界。

Try this, I have changed the padding for menu-li and width of sub-menu-li试试这个,我已经改变了menu-li的内边距和sub-menu-li宽度

.menu-li {
  padding: 10px 0;
  border-bottom: 1px solid rgba(50, 50, 50, 0.3);
  width: 100%;
}
.sub-menu-li {
  padding: 10px;
  padding-right: 0;
  width: calc(100% - 10px);
  border-top: 1px solid rgba(50, 50, 50, 0.3);
}

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

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