gpt4 book ai didi

html - 如何使我的导航栏响应移动设备(包括 Codepen)?

转载 作者:行者123 更新时间:2023-11-28 03:30:04 24 4
gpt4 key购买 nike

我目前正在使我的网页响应。我在导航栏上苦苦挣扎,不知道从哪里开始让它适合移动设备。这是我的导航栏的样子:

HTML:

<head>

<link href="https://fonts.googleapis.com/css?family=Gilda+Display|Montez|Sacramento" rel="stylesheet">

</head>


<nav>
<div class="navcontainer">
<ul>
<li class="right"><a href="productPage.php">Shop</a></li>
<li class="right"><a href="">Login</a></li>
<li><a href="index.php"><img class="logo" src="http://rubyfearless.com/wp-content/uploads/2012/08/style-insider-logo221.jpeg"></a></li>
<li class="right"><a href="contact.php">Contact us</a></li>
<li class="right"><a href="blog/cms.php">Blog</a></li>
</ul>
</div>
</nav>

<div class="clearfix"></div>

CSS:

html, body {
margin: auto;
padding: 0px;
}

.container{
margin: 0 auto;
width: 85%;
}

.clearfix{
clear:both;
}


/*******************************/

/*********************HEADER*******************/



nav {
text-align: center;
width: 100%;
background-color: white;
border:2px solid black;
}

nav ul {
padding: 0;
margin:0;
}

nav li {
color: black;
display: inline-block;
font-size: 30px;
font-weight: 300;
font-family: 'Sacramento', cursive;
vertical-align: middle;
margin: 16px 20px;
}



li a{
text-decoration: none;
color: black;
}

.logo{
height:100px;
}

这是我的导航栏的codepen代码:

https://codepen.io/teenicarus/pen/vZWJxX

这是我希望它在移动设备上的样子:

enter image description here

我该从哪里开始创建类似的结果?

感谢所有回复。

最佳答案

您需要使用@media 查询来根据屏幕尺寸覆盖 css...工作示例如下

html, body {
margin: auto;
padding: 0px;
}

.container{
margin: 0 auto;
width: 85%;
}

.clearfix{
clear:both;
}


/*******************************/

/*********************HEADER*******************/



nav {
text-align: center;
width: 100%;
background-color: white;
border:2px solid black;
}

nav ul {
padding: 0;
margin:0;
}

nav li {
color: black;
display: inline-block;
font-size: 30px;
font-weight: 300;
font-family: 'Sacramento', cursive;
vertical-align: middle;
margin: 16px 20px;
}



li a{
text-decoration: none;
color: black;
}

.logo{
height:100px;
}
.small-screen{display:none;}
@media screen and (max-width: 768px) {
nav li {display:block}
.small-screen{display:block;}
.large-screen{display:none;}
}
<head>

<link href="https://fonts.googleapis.com/css?family=Gilda+Display|Montez|Sacramento" rel="stylesheet">

</head>


<nav>
<div class="navcontainer">
<ul>
<li class="small-screen"><a href="index.php"><img class="logo" src="http://rubyfearless.com/wp-content/uploads/2012/08/style-insider-logo221.jpeg"></a></li>
<li class="right"><a href="productPage.php">Shop</a></li>
<li class="right"><a href="">Login</a></li>
<li class="large-screen"><a href="index.php"><img class="logo" src="http://rubyfearless.com/wp-content/uploads/2012/08/style-insider-logo221.jpeg"></a></li>
<li class="right"><a href="contact.php">Contact us</a></li>
<li class="right"><a href="blog/cms.php">Blog</a></li>
</ul>
</div>
</nav>

<div class="clearfix"></div>

关于html - 如何使我的导航栏响应移动设备(包括 Codepen)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44778402/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com