标题与描述出现紫色下划线及跳转异常问题求助
网页开发问题修复:移除标题/文本紫色下划线并修复跳转异常
问题现象
<h1>标题和<p>描述文本出现紫色下划线- 点击描述区域侧边会触发意外的页面跳转
问题根源
你的HTML代码中导航栏的<a>标签未正确闭合,导致<nav>之后的所有内容(包括<h1>、<p>)都被错误地包裹在<a>链接元素内。浏览器默认会给链接添加下划线样式,且点击这些被错误包含的区域时,会触发链接跳转行为。
原代码中的错误片段:
<li><a href="index.html">Home</li> <li><a href="Req&con.html">Requirments & Contacts</li>
这里的<a>标签缺少</a>闭合标签,浏览器自动补全逻辑出错,将后续页面内容全部纳入了链接范围。
修复步骤
- 闭合导航栏的
<a>标签,修正后的导航列表代码:
<li><a href="index.html">Home</a></li> <li><a href="Req&con.html">Requirments & Contacts</a></li>
- 移除CSS中
.col的text-decoration: none属性(该设置无效,并非问题根源)
修改后的完整代码
CSS代码
*{ margin: 0; padding: 0; font-family: 'Roboto', sans-serif; } .container{ width: 100%; height: 100vh; background-image: linear-gradient(rgba(0,0,0,0.7),rgba(0,0,0,0.7)),url(makati2.jpg); background-position: center; background-size: cover; padding-left: 5%; padding-right: 5%; box-sizing: border-box; overflow-y: hidden; } .navbar{ height: 20%; display: flex; align-items: center; } .logo{ width: 12%; cursor: pointer; } nav{ flex: 1; text-align: right; } nav ul li{ list-style: none; display: inline-block; margin-left: 60px; } nav ul li a{ text-decoration: none; color: #fff; font-size: 20px; } .row{ display: flex; height: 88%; align-items: center; } .col{ flex-basis: 50%; } h1{ color: #fff; font-size: 100px; } p{ color: #fff; font-size: 11px; line-height: 15px; }
HTML代码
<div class="container"> <div class="navbar"> <img src="logo.png" class="logo"> <nav> <ul> <li><a href="index.html">Home</a></li> <li><a href="Req&con.html">Requirments & Contacts</a></li> </ul> </nav> </div> <div class="row"> <div class="col"> <h1>Car Rental</h1> <p>XP Car Rental is your go-to choice for cheap and affordable car rentals in Metro Manila. Our well-maintained fleet offers a variety of options to suit your needs, from compact cars to spacious SUVs. We pride ourselves on transparent pricing, excellent customer service, and convenient locations for easy pick-up and drop-off. Enjoy a reliable and affordable rental experience with XP Car Rental.</p> </div> <div class="col"> </div> </div> </div>
内容的提问来源于stack exchange,提问作者Zsro
相关产品推荐
相关产品推荐

