html - 如何确保一个元素不被另一个(CSS)覆盖?
问题描述
我是网络开发的新手。试图使网站标志看起来不错。有两个元素,其中一个被另一个覆盖,因此用户无法单击其中的第一个。
请帮我把它们放在另一个之上。我怎样才能只使用 CSS 来做这些事情?
代码笔: https ://codepen.io/h071/pen/YOeXaw
这是 HTML 部分:
<header>
<link rel="stylesheet" type="text/css" href="/a/www/css/style_header.css">
<nav class="container-fluid">
<a class="logo" href="/a/www/index.php">
<span>Sitename</span>
</a>
<p id="reg-auth-title"><a href="/a/include/reg_auth.php">Login|Registration</a></p>
这是CSS:
header {
width: 100%;
height: 5em;
position: relative;
}
nav {
width: 100%;
}
.logo {
display: block;
float: left;
position: absolute;
margin-top: 0.4em;
margin-left: 1em;
}
.logo span {
font-size: 5em;
color: black;
display: inline-block;
/*line-height: 1em;*/
}
#reg-auth-title {
/* width: 20%; */
padding: 0;
margin: 0;
float: left;
}
#reg-auth-title a.top-auth {
font: bold 15px sans-serif;
text-decoration: none;
padding-left: 8px;
padding-right: 8px;
padding-top: 4px;
padding-bottom: 4px;
border: 1px solid red;
border-radius: 5px; /*other browsers*/
-webkit-border-radius: 5px; /*safari*/
-moz-border-radius: 5px;
cursor: pointer;
color: black;
}
#reg-auth-title a.top-auth:hover {
text-decoration: none;
}
#reg-auth-title a {
font: 15px sans-serif;
font-weight: bold;
text-decoration: none;
color: #58ACFA;
margin-left: 1em;
border-bottom-style: dashed;
border-bottom-color: #58ACFA;
border-bottom-width: 1px;
}
解决方案
您需要使用 z-index将链接放在徽标上方。
#reg-auth-title {
z-index: 10;
position: relative; // z-index works only with non-static positioned elements
}
推荐阅读
- ios - Xcode中opencascade库的IOS示例Lex编译错误
- c# - 基于现有标准解决方案的 Xamarin Forms 解决方案
- java - RecyclerView 不接受来自模型的构造函数
- php - 如何从 Doctrine 的 2 个表中获取数据?
- path - 如何在 Siteground 上指定 cron 脚本的路径?
- vue.js - 通过单击按钮添加组件
- hibernate - 如何在多边形内找到点?
- java - 从 java 运行 bat 文件时,有什么方法可以模拟用户输入?
- location - Twilio API 未通过 WhatsApp 频道接收当前位置
- c++ - 从自定义目录运行 ctest