【发布时间】:2019-06-21 03:47:12
【问题描述】:
所以我创建了我的响应式导航栏,当它在移动设备中时,它并不是我想象的那样。我得到了活动页面的“标题”,我想要它做的是如果我点击下一页,左上角的标题会改变。这是我得到这个想法的地方。 https://www.w3schools.com/howto/howto_js_topnav_responsive.asp.
这就是我的页面现在的样子。
当我转到另一个页面时,“活动”标题页不再是绿色的。并且标题仍然命名为home。这是 w3schools 在您切换到另一个 (dot)html 页面时没有告诉您的另一个问题。
此外,我希望主页选项卡位于汉堡图标栏下方,使其外观干净。比如这个。
这是我的代码,看看你能做些什么来解决我的问题。
index.html
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
.topnav {
overflow: hidden;
background-color: #333;
}
.topnav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav a:hover {
background-color: #ddd;
color: black;
}
.active {
background-color: #4CAF50;
color: white;
}
.topnav .icon {
display: none;
}
@media screen and (max-width: 600px) {
.topnav a:not(:first-child) {
display: none;
}
.topnav a.icon {
float: right;
display: block;
}
}
@media screen and (max-width: 600px) {
.topnav.responsive {
position: relative;
}
.topnav.responsive a.icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a {
float: none;
display: block;
text-align: center;
}
}
.summary {
min-height: 75vh;
max-width: 2000px;
display: flex;
align-items: center;
justify-content: center;
}
.profilePicture {
padding: 2rem;
}
.profileSummary {
max-width: 400px;
}
@media screen and (max-width: 800px) {
.summary {
flex-direction: column;
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Homepage</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="main.css">
<script src="script.js"></script>
</head>
<body>
<div class="topnav" id="myTopnav">
<a href="index.html" class="active">Home</a>
<a href="about.html">About Me</a>
<a href="portfolio.html">Portfolio</a>
<a href="contact.html">Contact</a>
<a href="javascript:void(0);" class="icon" onclick="myFunction()">
<i class="fa fa-bars"></i>
</a>
</div>
<div class="summary">
<div class="profilePicture">
<img src="https://ih1.redbubble.net/image.464384650.8618/flat,550x550,075,f.jpg" style="width: 170px; height: 170px; border-radius:50%;">
</div>
<div class="profileSummary">
Attentive alas because yikes due shameful ouch much kookaburra cantankerously up unbridled far vulnerably climbed aristocratically hired brusque fox said the therefore terrier scallop innocent on goodness mongoose woolly showed insistently and.
</div>
</div>
</body>
</html>
about.html
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
.topnav {
overflow: hidden;
background-color: #333;
}
.topnav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav a:hover {
background-color: #ddd;
color: black;
}
.active {
background-color: #4CAF50;
color: white;
}
.topnav .icon {
display: none;
}
@media screen and (max-width: 600px) {
.topnav a:not(:first-child) {
display: none;
}
.topnav a.icon {
float: right;
display: block;
}
}
@media screen and (max-width: 600px) {
.topnav.responsive {
position: relative;
}
.topnav.responsive a.icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a {
float: none;
display: block;
text-align: center;
}
}
.summary {
min-height: 75vh;
max-width: 2000px;
display: flex;
align-items: center;
justify-content: center;
}
.profilePicture {
padding: 2rem;
}
.profileSummary {
max-width: 400px;
}
@media screen and (max-width: 800px) {
.summary {
flex-direction: column;
}
}
/* Nav Styling Ends Here */
.skillResponsive {
max-width: 1000px;
margin: 0 auto;
padding: 0 15px;
}
.container {
background-color: #ddd;
}
.skills {
text-align: right;
padding: 10px;
color: white;
}
.html {
width: 60%;
background-color: #00e64d;
}
.css {
width: 60%;
background-color: #4da6ff;
}
.sql {
width: 10%;
background-color: #cc66ff;
}
.pc {
width: 75%;
background-color: #ff5050;
}
.trouble {
width: 75%;
background-color: #ff8533;
margin-bottom: 45px;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Homepage</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="main.css">
<script src="script.js"></script>
</head>
<body>
<!-- The navigation menu -->
<div class="topnav" id="myTopnav">
<a href="index.html">Home</a>
<a href="about.html" class="active">About Me</a>
<a href="portfolio.html">Portfolio</a>
<a href="contact.html">Contact</a>
<a href="javascript:void(0);" class="icon" onclick="myFunction()">
<i class="fa fa-bars"></i>
</a>
</div>
<h1 style="text-align: center;">
About me
</h1>
<div class="desc">
<p style="background-color: lightblue; border: 2px solid lightgreen; border-radius: 10px; text-align: center; font-size: 22px;">
I am currently attending Pikes Peak Community College towards my Associate of Applied Science Degree in Computer Information Systems.
</p>
</div>
<h2 align="center">My Programming Skills</h2>
<div class="skillResponsive">
<!--Div for Skill Bar-->
<p>HTML</p>
<div class="container">
<div class="skills html">60%</div>
</div>
<p>CSS</p>
<div class="container">
<div class="skills css">60%</div>
</div>
<p>SQL (Currently taking "Intro to SQL" at college this semester for a Database certificate)</p>
<div class="container">
<div class="skills sql">10%</div>
</div>
<h2 align="center">Computer Skills</h2>
<p>Build Computer</p>
<div class="container">
<div class="skills pc">75%</div>
</div>
<p>
The other 25% would have to be cable management, watercooling, and trying to figure which hardware is recommended to be place first to make cable management a priority to give it a good airflow. See the Portfolio page for a picture of my first gaming
PC.
</p>
<p>Software Troubleshooting</p>
<div class="container">
<div class="skills trouble">90%</div>
</div>
</div>
<h2 style="text-align: center; background-color: lightblue; border: 2px solid lightgreen; border-radius: 10px; margin-left: 100px; margin-right: 100px;">
My College Degree Progress
</h2>
</body>
</html>
我可以发布更多 (dot)html 文件,但我想你明白了。
【问题讨论】:
标签: html css drop-down-menu responsive-design flexbox