【发布时间】:2020-05-12 03:40:22
【问题描述】:
您好,我一直在做一个新网站,但有一个问题我似乎无法弄清楚。
这是网站网址:https://inspiring-mayer-4c86b6.netlify.com/
我遵循了有关如何使导航栏保持粘性的指南,这样当您滚动时,导航栏会停留在顶部。
它在 PC 和 1920x1080 像素的屏幕上运行良好。我认为使其具有响应性很重要,并且我尝试了几种使其具有响应性的方法,但是当我从 iPhone XS Max 打开网站时,导航栏上的按钮会出现在屏幕之外。
另外,在联系部分,我有一个按钮,其中包含指向联系表的链接。我已经使用 margin-left 将它移到了右边,这在更大的屏幕上是可以的,但是在手机上,这个按钮一直在右边的黑色背景中,在部分边框之外。
/----这是我的 index.html 代码。---/
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>EFPC | Welcome</title>
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="theme-color" content="#ffffff">
<meta name="viewport" content="width=divice-width, initial-scale=1.0">
<!--Style-->
<link rel="stylesheet" type="text/css" href="style.css">
<!--Style-->
<style>
body {
background-color:#0b0c10;
margin: 0;
padding: 0;
font-family:helvetica;
}
img {
}
marquee {
}
button {
background-color:#0b0c10;
color:white;
border:none;
box-shadow: 1px 1px 1px 2px #63c91d;
border-radius: 20px;
text-align: center;
text-decoration: none;
display: inline-block;
transition: all 0.5s;
cursor: pointer;
}
button span {
cursor: pointer;
display: inline-block;
position: relative;
transition: 0.5s;
}
button span:after {
content: '\00bb';
position: absolute;
opacity: 0;
top: 0;
right: -20px;
transition: 0.5s;
}
button:hover span {
padding-right: 25px;
}
button:hover span:after {
opacity: 1;
right: 0;
}
.navbar {
position: fixed;
display:flex;
justify-content: center;
align-items: center;
flex-direction: row;
flex-wrap: wrap;
background-color:#0b0c10;
Width:100%**;
height: 70px;
z-index: 1;
border-bottom: 2px solid white;
border-radius: 20px;
}
.nav {
display:flex;
justify-content: right;
list-style:none;
padding-right: 250px;
}
.logo {
flex:1 1 auto;
margin-left: 10%;
text-transform: uppercase;
text-shadow: 1px 1px 1px 1px ;
letter-spacing: 1px;
font-weight: bold;
font-size:35px;
text-shadow: -1px -1px 5px rgba(99, 201, 29, 1),
1px -1px 5px rgba(99, 201, 29, 1),
-1px 1px 5px rgba(99, 201, 29, 1),
1px 1px 5px rgba(99, 201, 29, 1);
}
html {
scroll-behavior: smooth;
}
a {
color: #000;
text-decoration: none;
text-transform: uppercase;
margin: 0;
}
a:hover{
color: #000;
}
.banner-area {
position: relative;
height: 100px;
}
.about-area, .products-area, .service-area, .contact-area {
position:relative;
display:flex;
justify-content: space-around;
align-items: center;
flex-wrap:wrap;
flex-direction: row;
width: 100%;
height: 700px;
}
.text-part {
width: 65%;
height: 80%;
}
h1 {
font-size: 50px;
font-family: helvetica;
}
p{
font-size: 24px;
line-height: 50px;
}
input {
background-color:#d4d7de;
border:none;
box-shadow: 1px 1px 1px 2px #596173 ;
text-align: center;
text-decoration: none;
display: inline-block;
transition: all 0.5s;
cursor: pointer;
height: 50px;
width: 85px;
}
button span {
cursor: pointer;
display: inline-block;
position: relative;
transition: 0.5s;
}
button span:after {
content: '\00bb';
position: absolute;
opacity: 0;
top: 0;
right: -20px;
transition: 0.5s;
}
button:hover span {
padding-right: 25px;
}
button:hover span:after {
opacity: 1;
right: 0;
}
* {box-sizing:border-box}
/* Slideshow container */
.slideshow-container {
max-width: 1000px;
position: relative;
margin: auto;
}
/* Next & previous buttons */
.prev, .next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
margin-top: -22px;
padding: 16px;
color: white;
font-weight: bold;
font-size: 18px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
}
/* Position the "next button" to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
/* On hover, add a black background color with a little bit see-through */
.prev:hover, .next:hover {
background-color: rgba(0,0,0,0.8);
}
/* Caption text */
.text {
color: #f2f2f2;
font-size: 15px;
padding: 8px 12px;
position: absolute;
bottom: 8px;
width: 100%;
text-align: center;
}
/* Number text (1/3 etc) */
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}
/* The dots/bullets/indicators */
.dot {
cursor: pointer;
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}
.active, .dot:hover {
background-color: #717171;
}
/* Fading animation */
.fade {
-webkit-animation-name: fade;
-webkit-animation-duration: 1.5s;
animation-name: fade;
animation-duration: 1.5s;
}
@-webkit-keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
@keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
@import "~slick-carousel/slick/slick.css";
@import "~slick-carousel/slick/slick-theme.css";
</style>
</head>
<body>
<div class="navbar">
<a class="logo" style="color:white;">EFPC</a>
<ul class="nav">
<a href="index.html" class="button"><button class="button" style="height:50px; text-transform: uppercase; width: 85px; "><span><li><strong>Home</strong></li></span></button></a>
<a href="#about"><button class="button" style="height:50px; text-transform: uppercase; width: 85px; "><span><li><strong>About</strong></li></span></button></a>
<a href="#products"><button class="button" style="height:50px; text-transform: uppercase; width: 120px; "><span><li><strong>products</strong></li></span></button></a>
<a href="#services"><button class="button" style="height:50px; text-transform: uppercase; width: 120px; margin-right: 0px; "><span><li><strong>services</strong></li></span></button></a>
<a href="contact.html" style="width: 100px;"><button class="button" style="height:50px; text-transform: uppercase; width: 100px; margin-right: 50px;"><li><span><strong>contact</strong></li></span></button></a>
<a href="#home" style="margin-left: 100px;" class="button"><button class="button" style="height:50px; text-transform: uppercase; width: 85px; "><span><li><strong>Login</strong></li></span></button></a>
<a href="#home" class="button"><button class="button" style="height:50px; text-transform: uppercase; width: 85px; m"><span><li><strong>Sign up</strong></li></span></button></a>
</ul>
</div>
<div class="banner-area" id="home"></div>
<div class="text-part">
<section class="leftpane" style="border:solid; border-radius: 10px; border-color: white; width:75%; height: 100%; float: left;">
<h1 style="color:white; text-align: center; font-size:40px; text-shadow:
-1px -1px 5px rgba(99, 201, 29, 1),
1px -1px 5px rgba(99, 201, 29, 1),
-1px 1px 5px rgba(99, 201, 29, 1),
1px 1px 5px rgba(99, 201, 29, 1); " >NEWS</h1>
<!-- Slideshow container -->
<script src="https://apps.elfsight.com/p/platform.js" defer></script>
<div class="elfsight-app-ef5db8e0-d439-47e7-a3df-53e0daaa7e65"></div>
</section>
</div>
<section class="rightpane" style="color:white; float:right; border:solid; border-radius: 10px; width:51%; height: 100%; display:inline-block;"> <h1>Welcome to EFPC!</h1><p> The website is under development , stay tuned for new updates everyday! Best regards,
<em><br> ~ The EFPC team ~</em></p></section>
<div class="about-area" id="about"></div>
<div class="text-part">
<h1>About Us</h1>
<p>Welcome to our website, here you can read some information about us.</p>
</div>
</body>
</html>
/---这是我的 style.css 代码---/
header {
}
body {
background-color: white;
margin: 0;
padding: 0;
font-family:helvetica;
}
img {
}
marquee {
}
button {
background-color:#d4d7de;
border:none;
box-shadow: 1px 1px 1px 2px #596173 ;
text-align: center;
text-decoration: none;
display: inline-block;
transition: all 0.5s;
cursor: pointer;
}
button span {
cursor: pointer;
display: inline-block;
position: relative;
transition: 0.5s;
}
button span:after {
content: '\00bb';
position: absolute;
opacity: 0;
top: 0;
right: -20px;
transition: 0.5s;
}
button:hover span {
padding-right: 25px;
}
button:hover span:after {
opacity: 1;
right: 0;
}
.navbar {
position: fixed;
display:flex;
justify-content: center;
align-items: center;
flex-direction: row;
flex-wrap: wrap;
background-color:#d4d7de;
Width:100%;
height: 70px;
z-index: 1;
}
.nav {
display:flex;
justify-content: right;
list-style:none;
padding-right: 250px;
}
.logo {
flex:1 1 auto;
margin-left: 10%;
text-transform: uppercase;
letter-spacing: 1px;
font-weight: bold;
font-size:35px;
color:
}
html {
scroll-behavior: smooth;
}
a {
color: #000;
text-decoration: none;
text-transform: uppercase;
margin: 0;
}
a:hover{
color: #000;
}
.banner-area {
position: relative;
height: 100px;
}
.about-area, .products-area, .service-area, .contact-area {
position:relative;
display:flex;
justify-content: space-around;
align-items: center;
flex-wrap:wrap;
flex-direction: row;
width: 100%;
height: 700px;
}
.text-part {
width: 65%;
height: 80%;
}
h1 {
font-size: 50px;
font-family: helvetica;
}
p{
font-size: 24px;
line-height: 50px;
}
input {
background-color:#d4d7de;
border:none;
box-shadow: 1px 1px 1px 2px #596173 ;
text-align: center;
text-decoration: none;
display: inline-block;
transition: all 0.5s;
cursor: pointer;
height: 50px;
width: 85px;
}
button span {
cursor: pointer;
display: inline-block;
position: relative;
transition: 0.5s;
}
button span:after {
content: '\00bb';
position: absolute;
opacity: 0;
top: 0;
right: -20px;
transition: 0.5s;
}
button:hover span {
padding-right: 25px;
}
button:hover span:after {
opacity: 1;
right: 0;
}
/* Media Section */
@import "~slick-carousel/slick/slick.css";
@import "~slick-carousel/slick/slick-theme.css";
@media screen and (max-width: 600px) {
/* Stylings for all devices with screens with a width of 600px or less.*/
}
@media screen and (max-width: 992px) {
/* all screens with a max width of 992px or less */
}
@media screen and (min-width: 992px) {
/* all screens with a width of 992px or higher */
}
`@import url('mainstyles.css');`
任何帮助将不胜感激,谢谢!
【问题讨论】:
-
没有什么可以让导航栏响应。你刚刚把它粘起来了。
-
我意识到,我已经尝试了几种不同的方法来使用 @media 查询设置导航栏的样式,但它们似乎都不起作用,所以我删除了它们。 head部分的“”呢?
-
这不会使网站响应它只是缩小页面以适应屏幕。要使导航栏响应,您必须将内联样式从
<a>和<li>标签移动到 css 并为不同的分辨率定义不同的宽度。文档中也存在 HTML 错误,例如在<a>中嵌套<li>元素 -
那么我应该将 标签嵌套在
- 中吗?
-
是的
<li>应该是<ul>的直接子代
标签: javascript html css navbar responsive