【问题标题】:Unable to remove underline from li elements using CSS无法使用 CSS 从 li 元素中删除下划线
【发布时间】:2022-11-24 16:38:12
【问题描述】:

我正在使用 NextJs 框架进行前端开发 我是前端的新手 我正在尝试创建导航栏,其中我在菜单项下方加下划线。我尝试了几个 CSS 属性,但没有成功。

下面是我的代码:

导航栏.js

import Link from 'next/link';

const Navbar =  () => {

return(
    <nav className='navigation'>
        <div className="logo">
            <h1>My logo</h1>
        </div> 
        <div className="menu">
            <ul>
                <li className="menu-items"><Link href="/">Home</Link></li>
                <li className="menu-items"><Link href="/about">About</Link></li>
                <li className="menu-items"><Link href="/contact">Contact</Link></li>
            </ul>
        </div>     
    </nav>
  );
}

export default Navbar;

全局.css

 html,
 body {
  padding: 0;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
   Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
 }

 .navigation {
 display: flex;
 justify-content: space-between;
}

 .menu-items {
 list-style-type: none;
 display: inline;
 margin-right: 20px;
 background-color: coral;
 color: white;
 padding: 10px;
 border-radius: 3px; 
}

有人让我知道我怎样才能达到预期的结果任何帮助将不胜感激。

【问题讨论】:

  • 下划线来自&lt;a&gt;&lt;/a&gt; 标签。在 css 中,试试a { text-decoration: none }
  • 我没有使用 &lt;a&gt; 标签,我使用的是 Link 属性。
  • Nextjs &lt;Link&gt; 正在使用 &lt;a&gt; 标签。
  • 检查你的&lt;Link&gt; 元素,你会看到。

标签: javascript html css reactjs next.js


【解决方案1】:

尝试使用“文字装饰”。

.menu-items {
 list-style-type: none;
 display: inline;
 margin-right: 20px;
 background-color: coral;
 color: white;
 padding: 10px;
 border-radius: 3px;
 text-decoration: none; /* <=== add this */
}

如果不起作用,试试这个。

.menu-items > a {
  text-decoration: none;
}

【讨论】:

  • 我尝试了您的解决方案,但它不起作用。
  • 我刚刚更新了我的代码。请尝试修复它。我希望这次能工作。
猜你喜欢
  • 2021-03-08
  • 1970-01-01
  • 2015-11-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多