我有一个用html和css编码的网站,除了导航栏不能适应小型电话的宽度之外,它的工作原理非常好!无论我如何努力,它总是溢出!
这是我的导航栏的代码
那是我的html代码:
<div class="nav-h">
<input type="checkbox" id="nav-check">
<div class="nav-header">
<div class="nav-title"><img src="images/ca.svg"><span><a class="c"
<a href="#">CAMER</a><a class="s" href="#">-AUTOPRIX</a></span>
</div>
</div>
<div class="nav-btn">
<label for="nav-check">
<span></span>
<span></span>
<span></span>
</label>
</div>
<div class="nav-links">
<ul>
<li><a class="feat" href="index.php" target="_self">ACCEUIL</a></li>
<li><a class="feat" href="../html/apropos.php" target="_self">A PROPOS</a></li>
<li><a class="feat" href="../html/contact.php" target="_self">CONTACT</a></li>
<li> <input class="s-search" type="text" name="search0" placeholder="Recherche"><button type="submit" class="searchButton"><i class="fa fa-search"></i></button></li>
</ul>
<div class="containers">
<input type="text" placeholder="Recherche...">
<div class="search"></div>
</div>
</div>
</div>
这是我的CSS代码:
.nav-h {
position: fixed;
top: 0;
left: 0;
width: 100%;
padding: 0;
z-index: 10000;
-webkit-box-shadow: 0 1px 5px rgba(0, 0, 0, 0.25);
-moz-box-shadow: 0 1px 5px rgba(0, 0, 0, 0.25);
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.25);
height: auto;
background-color:transparent;
padding: 20px 30px;
-webkit-transition: all ease-out .5s;
-moz-transition: all ease-out .5s;
-o-transition: all ease-out .5s;
transition: all ease-out .5s;
background-color: rgba(0, 0, 0, 0.4);
}
.nav-h > .nav-header {
display: inline;
}
.nav-h > .nav-header > .nav-title {
display: inline-block;
font-size: 22px;
color: #fff;
font-family: 'Black Han Sans';
font-weight: bolder;
padding: 10px 10px 10px 10px;
}
.nav-h > .nav-btn {
display: none;
}
.nav-h ul li {
display: inline-block;
}
.nav-h ul li a {
color: #FFF;
text-decoration: none;
display: block;
padding: 10px;
font-family: 'Basic';
transition: 0.3s;
font-family: 'Basic';
font-weight: bolder;
transition: 0.3s;
}
.nav-h > .nav-links {
display: inline;
float: right;
margin-right:310px;
}
.nav-h img{
width: 50px;
margin-left: -10px;
margin-right: 10px;
margin-top: -10px;
}
.nav-h > .nav-links > a {
display: inline-block;
padding: 13px 10px 13px 10px;
text-decoration: none;
color: #FFF;
float: right;
}
如何修改我的代码以使导航栏适应小屏幕?我记得除了导航栏外,所有其他代码在小屏幕上都可以很好地工作!
这是我的手机屏幕的CSS代码:
@media (max-width:700px) {
.nav-h > .nav-btn {
display: inline-block;
position: absolute;
right: 0px;
top: 0px;
}
.nav-h > .nav-btn > label {
display: inline-block;
width: 50px;
height: 50px;
padding: 13px;
}
.nav-h > .nav-btn > label:hover,.nav-h #nav-check:checked ~ .nav-btn > label {
background-color: rgba(0, 0, 0, 0.3);
}
.nav-h > .nav-btn > label > span {
display: block;
width: 25px;
height: 10px;
border-top: 2px solid #eee;
}
.nav-links ul li{
display: block;
font-size: 15px;
padding: 0, 20px;
}
.nav-h >.nav-links{
position: absolute;
display: inline;
width: 100%;
background-color: #333;
height: 0px;
transition: all 0.3s ease-in;
overflow-y: hidden;
top: 50px;
}
.nav-h > .nav-links > a {
display: block;
width: 100%;
}
.nav-h > #nav-check:not(:checked) ~ .nav-links {
height: 0px;
overflow-y: hidden;
overflow: hidden;
overflow-x: hidden;
}
.nav-h > #nav-check:checked ~ .nav-links {
height:200px;
overflow-y: hidden;
overflow: hidden;
overflow-x: hidden;
}
答案 0 :(得分:1)
您是否尝试过使用尺寸单位 vw ? Introduction into Viewport unit
或者也许您忘记添加视口元标记了? Viewport meta tag
<meta name="viewport" content="width=device-width, initial-scale=1">
答案 1 :(得分:0)
只需为移动margin-right
的{{1}}类删除nav-links
。代码看起来不完整。如果您需要进一步的帮助,请在下面写下您的评论。
(@media)
* {
box-sizing: border-box;
position: relative;
}
.nav-h {
position: fixed;
top: 0;
left: 0;
width: 100%;
padding: 0;
z-index: 10000;
-webkit-box-shadow: 0 1px 5px rgba(0, 0, 0, 0.25);
-moz-box-shadow: 0 1px 5px rgba(0, 0, 0, 0.25);
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.25);
height: auto;
background-color: transparent;
padding: 20px 30px;
-webkit-transition: all ease-out .5s;
-moz-transition: all ease-out .5s;
-o-transition: all ease-out .5s;
transition: all ease-out .5s;
background-color: rgba(0, 0, 0, 0.4);
}
.nav-h > .nav-header {
display: inline;
}
.nav-h > .nav-header > .nav-title {
display: inline-block;
font-size: 22px;
color: #fff;
font-family: 'Black Han Sans';
font-weight: bolder;
padding: 10px 10px 10px 10px;
}
.nav-h > .nav-btn {
display: none;
}
.nav-h ul li {
display: inline-block;
}
.nav-h ul li a {
color: #FFF;
text-decoration: none;
display: block;
padding: 10px;
font-family: 'Basic';
transition: 0.3s;
font-family: 'Basic';
font-weight: bolder;
transition: 0.3s;
}
.nav-h > .nav-links {
display: inline;
float: right;
margin-right: 310px;
}
.nav-h img {
width: 50px;
margin-left: -10px;
margin-right: 10px;
margin-top: -10px;
}
.nav-h > .nav-links > a {
display: inline-block;
padding: 13px 10px 13px 10px;
text-decoration: none;
color: #FFF;
float: right;
}
ul,
li {
padding: 0;
margin: 0;
}
@media (max-width:767px) {
.nav-h > .nav-links {
margin-right: 0;
}
}