html - CSS类不起作用
问题描述
我对 html 和 css 有点陌生,想创建自己的投资组合。不过,我的课程有一些问题。每当我尝试在 css 中调用它们时,它似乎并没有做它应该做的事情。
当我在不使用类的情况下调用它时,它工作得很好。
希望有人可以帮助并找到我的错误,在此先感谢。
HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Xander Feliers - Portfolio</title>
<meta name="description" content="Portfolio - Xander Feliers">
<link rel="stylesheet" href="css/screen.css">
</head>
<body>
<div>
<nav>
<ul class="header_nav">
<li class="header_nav"><a href="contact.html">Contact</a></li>
<li class="header_nav"><a href="projects.html">Projects</a></li>
<li class="header_nav"><a href="about.html">About</a></li>
<li class="header_nav"><a href="index.html">Home</a></li>
</ul>
</nav>
</div>
</body>
</html>
CSS
body{
background-color: #f1f6fe;
}
.header_nav{
list-style-type: none;
margin: 0;
padding: 25px;
overflow: hidden;
background-color:#78aefa;
width: 250 px;
}
li.header_nav{
float: right;
padding-right: 20px;
}
a.header_nav {
font-family: arial;
display: block;
color:white;
text-align: center;
padding: 14 px 16 px;
text-decoration: none;
}
更新
更改了css,但仍然无法正常工作。
解决方案
这门课不行。您指出了与 class 的链接header_nav
。但你没有。
a.header_nav {
font-family: arial;
display: block;
color:white;
text-align: center;
padding: 14 px 16 px;
text-decoration: none;
}
它应该是(类内的链接.header_nav
)
.header_nav a {
font-family: arial;
display: block;
color:white;
text-align: center;
padding: 14 px 16 px;
text-decoration: none;
}
更新:
我已经包含了片段。是你想要的吗?
body{
background-color: #f1f6fe;
}
.header_nav{
list-style-type: none;
margin: 0;
padding: 25px;
overflow: hidden;
background-color:#78aefa;
width: 250 px;
}
li.header_nav{
float: right;
padding-right: 20px;
}
.header_nav a {
font-family: arial;
display: block;
color:white;
text-align: center;
padding: 14 px 16 px;
text-decoration: none;
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Xander Feliers - Portfolio</title>
<meta name="description" content="Portfolio - Xander Feliers">
<link rel="stylesheet" href="css/screen.css">
</head>
<body>
<div>
<nav>
<ul class="header_nav">
<li class="header_nav"><a href="contact.html">Contact</a></li>
<li class="header_nav"><a href="projects.html">Projects</a></li>
<li class="header_nav"><a href="about.html">About</a></li>
<li class="header_nav"><a href="index.html">Home</a></li>
</ul>
</nav>
</div>
</body>
</html>
更新 2
CSS 中的顺序非常重要。如果您想强制执行您的样式,您可以!important
在样式之后使用。(尽管我看到了被认为是不好的做法的文章。)
.header_nav a {
font-family: arial;
display: block;
color:white!important;
text-align: center;
padding: 14 px 16 px;
text-decoration: none!important;
}
推荐阅读
- authentication - 通过 SAML 使用字符串而不是 URL 作为 entityID
- kubernetes - 集群中的 A 类和 C 类 IP 地址
- angular - 在 ag-grid 中编辑单元格值后如何启动方法?
- apache-poi - 使用poi通过spring mvc导出word文件时如何从码头修复“java.io.IOException:已关闭”
- javascript - 将模板发送给多个人而不知道他们在 sendgrid 中的电子邮件
- git - git 无法使用 `git daemon` 通过 LAN 克隆
- html - NodeJS - 读取 HTML 头部标签
- vue.js - 如何创建nest vuejs项目
- azure - Input-Output:如何将输入查找表也用作更新数据的输出表?
- java - Cassandra 抛出 OutOfMemory ;怎么调?