我一直在努力使这个响应性CSS/HTML菜单工作,当它处于全屏/普通桌面视图时,它以我想要的颜色显示,但当我在“响应”视图(例如电话分辨率)中查看它时,菜单颜色显示的方式不正确.
根据全屏版本,颜色应该如下所示
菜单文本- #278189背景- #fff背景- #3A3A3A
我一遍又一遍地浏览代码,但不明白为什么这不起作用?由于其他一些奇怪的原因,“家”“关于”和“接触”有一个黑色悬停的背景。
另一个小问题(不太麻烦,但很高兴知道)是,当全屏上有一个"home“按钮,将链接到索引页,但在较小的版本中也有一个”菜单“按钮.?
提亚
丹
<html>
<head>
<meta charset="utf-8">
<title>Primeheat | Chichester Plumbing & Heating Installation,
Maintenance & Emergency Breakdown</title>
<meta name="viewport" content="width=device-width">
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<nav>
<div id="logo">Your Logo here</div>
<label for="drop" class="toggle">Menu</label>
<input type="checkbox" id="drop" />
<ul class="menu">
<li><a href="#">Home</a></li>
<li>
<!-- First Tier Drop Down -->
<label for="drop-1" class="toggle">Plumbing</label>
<a href="#">Plumbing</a>
<input type="checkbox" id="drop-1"/>
<ul>
<li><a href="#">Installation</a></li>
<li><a href="#">Service</a></li>
<li><a href="#">Breakdown</a></li>
</ul>
</li>
<li>
<!-- First Tier Drop Down -->
<label for="drop-2" class="toggle">Heating</label>
<a href="#">Heating</a>
<input type="checkbox" id="drop-2"/>
<ul>
<li><a href="#">Installation</a></li>
<li><a href="#">Service</a></li>
<li><a href="#">Service</a></li>
<li>
</ul>
</li>
<li><a href="#">Contact</a></li>
<li><a href="#">About</a></li>
</ul>
</nav>
<div id="navbar2" div id class="navbar2">
<h1 class="h1">Welcome to Primeheat Plumbing & Heating</h1>
</div>
</body>
</html>
body {
background: #212121;
font-size:22px;
line-height: 32px;
color: #278189;
margin: 0;
padding: 0;
word-wrap:break-word !important;
font-family: 'Open Sans', sans-serif;
}
h1 {
font-size: 60px;
text-align: center;
color: #278189;
}
h3 {
font-size: 30px;
line-height: 34px;
text-align: center;
color: ##278189;;
}
h3 a {
color: ##278189;;
}
a {
color: ##278189;;
}
h1 {
margin-top: 100px;
text-align:center;
font-size:60px;
line-height: 70px;
font-family: 'Bree Serif', 'serif';
}
#container {
margin: 0 auto;
max-width: 890px;
}
p {
text-align: center;
}
.toggle,
[id^=drop] {
display: none;
}
/* Giving a background-color to the nav container. */
nav {
margin:0;
padding: 0;
background-color: #FFFFFF;
}
#logo {
display: block;
padding: 0 30px;
float: left;
font-size:20px;
line-height: 60px;
}
/* Since we'll have the "ul li" "float:left"
* we need to add a clear after the container. */
nav:after {
content:"";
display:table;
clear:both;
}
/* Removing padding, margin and "list-style" from the "ul",
* and adding "position:reltive" */
nav ul {
float: right;
padding:0;
margin:0;
list-style: none;
position: relative;
}
/* Positioning the navigation items inline */
nav ul li {
margin: 0px;
display:inline-block;
float: left;
background-color: #fff;
}
/* Styling the links */
nav a {
display:block;
padding:14px 20px;
color:#278189;
font-size:17px;
text-decoration:none;
}
nav ul li ul li:hover { background: #3A3A3A; }
/* Background color change on Hover */
nav a:hover {
background-color: #3A3A3A;
}
/* Hide Dropdowns by Default
* and giving it a position of absolute */
nav ul ul {
display: none;
position: absolute;
/* has to be the same number as the "line-height" of "nav a" */
top: 60px;
}
/* Display Dropdowns on Hover */
nav ul li:hover > ul {
display:inherit;
}
/* Fisrt Tier Dropdown */
nav ul ul li {
width:170px;
float:none;
display:list-item;
position: relative;
}
/* Second, Third and more Tiers
* We move the 2nd and 3rd etc tier dropdowns to the left
* by the amount of the width of the first tier.
*/
nav ul ul ul li {
position: relative;
top:-60px;
/* has to be the same number as the "width" of "nav ul ul li" */
left:170px;
}
/* Change ' +' in order to change the Dropdown symbol */
li > a:after { content: ' +'; }
li > a:only-child:after { content: ''; }
/* Media Queries
-------------------------------------------- */
@media all and (max-width : 768px) {
#logo {
display: block;
padding: 0;
width: 100%;
text-align: center;
float: none;
}
nav {
margin: 0;
}
/* Hide the navigation menu by default */
/* Also hide the */
.toggle + a,
.menu {
display: none;
}
/* Stylinf the toggle lable */
.toggle {
display: block;
background-color: #FFF;
padding:14px 20px;
color:##278189;
font-size:17px;
text-decoration:none;
border:none;
}
.toggle:hover {
background-color: #278189;
}
/* Display Dropdown when clicked on Parent Lable */
[id^=drop]:checked + ul {
display: block;
}
/* Change menu item's width to 100% */
nav ul li {
display: block;
width: 100%;
}
nav ul ul .toggle,
nav ul ul a {
padding: 0 40px;
}
nav ul ul ul a {
padding: 0 80px;
}
nav a:hover,
nav ul ul ul a {
background-color: #000000;
}
nav ul li ul li .toggle,
nav ul ul a,
nav ul ul ul a{
padding:14px 20px;
color:#464646;
font-size:17px;
}
nav ul li ul li .toggle,
nav ul ul a {
background-color: #3a3a3a;
}
/* Hide Dropdowns by Default */
nav ul ul {
float: none;
position:static;
color: #278189;
/* has to be the same number as the "line-height" of "nav a" */
}
/* Hide menus on hover */
nav ul ul li:hover > ul,
nav ul li:hover > ul {
display: none;
}
/* Fisrt Tier Dropdown */
nav ul ul li {
display: block;
width: 100%;
}
nav ul ul ul li {
position: static;
/* has to be the same number as the "width" of "nav ul ul li" */
}
}
@media all and (max-width : 330px) {
nav ul li {
display:block;
width: 94%;
}
}发布于 2018-06-16 16:46:12
在讨论所述的问题之前,我想指出代码中的一些明显错误。第一个错误,你输入了一些颜色十六进制代码错误。你可以输入额外的标签和分号。不仅仅是这个h3标记,还有其他标记。正确检查您的代码。
h3 {
font-size: 30px;
line-height: 34px;
text-align: center;
color: ##278189;; /* should be #278189; */
}第二个错误,为什么你要两次使用相同的标签(h1)?我可以理解,如果其中之一位于媒体查询中,或者嵌套在其他标记或类/ids下,则可以将其样式设置两次,但事实并非如此。
h1 {
font-size: 60px;
text-align: center;
color: #278189;
}
h1 {
margin-top: 100px;
text-align:center;
font-size:60px;
line-height: 70px;
font-family: 'Bree Serif', 'serif';
}好的,要解决你的问题:
您刚才提到,菜单颜色在移动分辨率中显示不正确。
在媒体查询@media all and (max-width : 768px)下,您可以看到如下所示。只需将其更改为您想要的颜色,即#3A3A3A。
.toggle:hover {
background-color: #278189; /* it's using the menu text color. change this to the color you want, which is #3A3A3A */
}如果您希望导航项具有相同的悬停背景色,也可以在相同的媒体查询下更改此颜色。
nav a:hover,
nav ul ul ul a {
background-color: #000000; /* #000000 is black color. Change this */
}如果子菜单文本也要有#278189,请更改这一点。
nav ul li ul li .toggle,
nav ul ul a,
nav ul ul ul a{
padding:14px 20px;
color: #464646; /* change this too... */
font-size:17px;
} 另一个小问题(不太麻烦,但很高兴知道)是,当全屏上有一个"home“按钮,将链接到索引页,但在较小的版本中也有一个”菜单“按钮.?
您提到的“菜单”按钮用于折叠移动分辨率上的下拉菜单。单击它,将显示下拉菜单。它来自于这行html代码:
<label for="drop" class="toggle">Menu</label>如果要删除整行,则不能再获得移动分辨率上的下拉菜单,因为下拉css代码都是由toggle类处理的。
基本上,你提到的问题并不大。如果您不确定颜色从哪里来,为什么会显示错误的颜色,等等,您可以使用浏览器中的检查元素来查找它(如果你对检查元素知之甚少,请在这里阅读更多信息 )。此外,一定要确保代码没有语法错误(阅读有关css语法的更多信息。),就像我前面提到的颜色十六进制代码一样。
https://stackoverflow.com/questions/50887692
复制相似问题