浮动标题不会出现在悬停的图像上
问题描述:
所以我设置我的标题淡入滚动,但出现悬停。它适用于所有图像,但投资组合部分中的猫图片。我调整了Z-索引并尝试了一切。头文件不会出现在h4或其他文件的下方。问题文件是portfolio.html。标题出现在其他图片上。这让我疯狂。 https://github.com/alil0rphan/Basic-Portfolio浮动标题不会出现在悬停的图像上
/* Eastablish body parameters */
body {
\t background-image: url("../images/circlesbg.png");
\t background-color: #D7CFC3;
\t color: #777777;
\t margin: 0px auto;
\t font-family: 'Arial', 'Helvetica Neue', Helvetica, sans-serif;
}
/* Create Heading block */
h1 {
\t background-color: #4AAAA5;
\t display: inline-block;
\t padding: 25px 20px 0px 20px;
\t height: 55px;
\t margin: 0px auto;
\t font-family: "Georgia", Times, "Times New Roman", serif;
\t color: #FFFFFF;
\t font-size: 36px;
}
h1,
h2,
h3 {
\t font-weight: bold;
}
section {
\t background-color: #ffffff;
}
/*Establishes header on top */
header {
\t background-color: #FFFFFF;
\t border-bottom: solid 2px #cccccc;
\t margin: 0px auto;
\t width: 100%;
\t height: 80px;
\t top: 0px;
\t position: fixed;
\t z-index: 99;
}
/* establishes tranparency on scroll */
body.scrolled #main-menu {
\t opacity: 0.2;
\t transition: opacity .2s;
\t z-index: 98;
}
body.scrolled #main-menu:hover {
\t opacity: 1.0;
\t transition: opacity .2s;
\t z-index: 97;
}
/* Makes sure heading and contents line up */
.banner {
\t width: 960px;
\t margin: 0px auto;
\t height: 60px;
\t position: relative;
}
/* Navigational link parameters established */
.link-box {
\t padding: 30px 0px 0px 20px;
\t height: 55px;
\t right: 0px;
\t display: inline;
\t position: absolute;
}
/* Establishes main content parameters (container and connect blocks) */
.content {
\t width: 960px;
\t margin: 0px auto;
}
/* Establish main unique block on each page */
.container {
\t width: 590px;
\t border: solid 2px #dddddd;
\t float: left;
\t margin: 115px 0px 200px 0px;
\t padding: 30px;
}
/* Link attributes including hover */
a {
\t color: #777777;
\t text-decoration: none;
\t font-family: 'Arial', 'Helvetica Neue', Helvetica, sans-serif;
\t word-spacing: 10px;
}
a:hover {
\t color: #4AAAA5;
}
/* Establishing heading fonts for container and connect box*/
h2 {
\t color: #4AAAA5;
\t font-family: "Georgia", Times, "Times New Roman", serif;
\t border-bottom: solid 3px #dddddd;
\t padding-bottom: 20px;
\t margin-bottom: 10px;
\t font-size: 32px;
}
h3 {
\t color: #4AAAA5;
\t font-family: "Georgia", Times, "Times New Roman", serif;
\t border-bottom: solid 1px #dddddd;
\t padding-bottom: 20px;
\t margin-bottom: 10px;
\t font-size: 24px;
}
/* adjusts line height and paragraphs for the about me section */
p {
\t line-height: 2.5;
\t font-family: 'Arial', 'Helvetica Neue', Helvetica, sans-serif;
\t margin-top: 0px;
\t color: #777777;
}
/* My picture on the index file */
#face {
\t float: left;
\t display: inline;
\t margin-top: 10px;
\t margin-right: 15px;
\t width: 250px;
}
/* Connections box parameters with icons */
.connect {
\t width: 210px;
\t border: solid 2px #dddddd;
\t float: right;
\t margin-top: 115px;
\t padding: 30px;
}
/* Establish icon aesthetics and behaviors with hover features */
.icons {
\t display: inline-block;
\t margin: 0px 5px 30px 0px;
\t width: 60px;
\t height: 60px;
}
.icons:hover {
\t box-shadow: 4px 4px 2px #4AAAA5;
}
/* cat pictures and parameters established with hover features*/
.cats {
\t display: inline-block;
\t margin: 10px 40px 40px 0px;
\t width: 230px;
}
.cats:hover {
\t box-shadow: 4px 4px 2px #4AAAA5;
}
.image {
position: relative;
display: inline-block;
}
/* establishes parameters for banners over the cat images */
h4 {
position: absolute;
width: 230px;
background-color: #4AAAA5;
color: #FFFFFF;
font-family: "Georgia", Times, "Times New Roman", serif;
text-align: center;
padding: 10px 0px 10px 0px;
margin: auto;
left: 0px;
bottom: 50px;
}
/* Establishes sticky footer */
footer {
\t background-color: #666666;
\t opacity: 0.85;
\t text-align: center;
\t border-top: solid 6px #4AAAA5;
\t position: fixed;
\t width: 100%;
\t bottom: 0px;
\t padding-top: 30px;
\t padding-bottom: 30px;
\t color: #BFBEBC;
\t font-size: 10px;
\t font-family: 'Arial', 'Helvetica Neue', Helvetica, sans-serif;
}
.clearfix::after {
\t content: "";
\t display: block;
\t clear: both;
}
/* Establishes input attributes for the contact/ message form. */
input[type=text], select, textarea {
width: 100%;
padding: 12px;
border: 2px solid #DDDDDD;
border-radius: 4px;
box-sizing: border-box;
margin-bottom: 16px;
resize: vertical
}
input[type=submit] {
background-color: #4AAAA5;
color: #FFFFFF;
padding: 12px 20px;
border: none;
cursor: pointer;
}
/* Makes the Submit button change color when mouse hovers over */
input[type=submit]:hover {
background-color: #666666;
}
::-webkit-input-placeholder { /* WebKit browsers */
color: #666666;
opacity: 0.5 !important;
}
label {
\t color: #8F7E7F;
}
<!DOCTYPE html>
<html lang="en-us">
<head>
\t <meta charset="UTF-8">
\t <title>Portfolio</title>
\t <link rel="stylesheet" type="text/css" href="assets/css/reset.css">
\t <link rel="stylesheet" type="text/css" href="assets/css/style.css">
</head>
<div id="main-menu">
\t <header>
\t \t <div class="banner">
\t \t \t <h1>John Bendfeldt</h1>
<!-- Navigational links. -->
\t \t \t <div class="link-box">
\t \t \t \t <a href="index.html">About | </a>
\t \t \t \t <a href="portfolio.html">Porfolio | </a>
\t \t \t \t <a href="contact.html">Contact</a>
\t \t \t </div>
\t \t </div>
\t </header>
</div>
<body>
\t <div class="content">
<!-- Big content box in middle \t -->
\t \t \t <section class="container">
\t \t \t <h2>Portfolio</h2>
\t \t \t <br>
<!-- Images for the main content block -->
\t \t \t <div class="image">
\t \t \t \t <img src="assets/images/cat1.jpg" class="cats" alt="kitten">
\t \t \t \t <h4>Building Websites</h4>
\t \t \t </div>
\t \t \t <div class="image">
\t \t \t \t <img src="assets/images/cat2.jpg" class="cats" alt="kitten">
\t \t \t \t <h4>RPG</h4>
\t \t \t </div>
\t \t \t <div class="image">
\t \t \t \t <img src="assets/images/cat3.jpg" class="cats" alt="kitten">
\t \t \t \t <h4>Trivia Game</h4>
\t \t \t </div>
\t \t \t <div class="image">
\t \t \t \t <img src="assets/images/cat4.jpg" class="cats" alt="kitten">
\t \t \t \t <h4>Rock Paper Scissors</h4>
\t \t \t </div>
\t \t \t <div class="image">
\t \t \t <img src="assets/images/cat5.jpg" class="cats" alt="kitten">
\t \t \t <h4>American Freedom</h4>
\t \t \t </div>
\t \t </section>
<!-- connect with me box -->
\t \t <section class="connect">
\t \t \t <h3>Connect with Me</h3>
\t \t \t <br>
\t \t \t <a href="https://github.com/alil0rphan" target="_blank"><img src="assets/images/Github-icon.png" class="icons" alt="Github-icon" title="GitHub"></a>
\t \t \t <a href="https://www.linkedin.com/in/john-bendfeldt-b32736130/" target="_blank"><img src="assets/images/linkedin-icon.png" class="icons" alt="linkedin-icon" title="LinkedIn"></a>
\t \t \t <a href="http://stackoverflow.com/users/7700030/john-bendfeldt" target="_blank"><img src="assets/images/stackoverflow-icon.png" class="icons" alt="stackoverflow-icon" title="Stackoverflow"></a>
\t \t </section>
\t </div>
</body>
<footer>
\t © Copywrite 2017 John Bendfeldt
</footer>
<!-- makes the header transparent on scroll -->
<script type="text/javascript">
\t window.addEventListener('scroll', function() {
\t document.body.classList[
window.scrollY > 20 ? 'add': 'remove'
]('scrolled');
});
</script>
</html>
`
答
尝试添加在body.scrolled #main-menu
选择position: absolute;
。它看起来像这样:
body.scrolled #main-menu {
opacity: 0.2;
transition: opacity .2s;
z-index: 98;
position: absolute;
}
谢谢。它不会让我接受答案。你知道这是为什么吗? –
别担心,您可以稍后接受答案:)。具有小于1的值的不透明属性将导致导航栏位于不透明度为1的标签下方。对于绝对位置,导航栏将在具有较低z-索引的标签上被提升。 –