我正在尝试创建一个响应式网站。我在页面顶部有一个导航栏,在右侧带有链接,在左侧带有社交媒体图标。当我缩小浏览器时,它会将导航栏下的链接推入,就像它被推到另一个div中一样。
我相信社交图标正在引起问题。它们是多个div中的两个不同的div。如果我删除社交图标,则可以使用,但我想将社交图标保持在左上方。
<body>
<div id="outerWrapper"> </div>
<div id="navWrapper">
<div id="navInnerWrapper">
<div id="topSocials">
<a href="URL"><img alt="facebook icon" src="images/fb_social.png"></a>
<a href="URL"><img alt="linkedin icon" src="images/linkedin_social.png"></a>
</div>
<div id="navBar">
<ul>
<li><a href="#">About</a></li>
<li><a href="#">Our Work</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</div>
</div>
#outerWrapper {
width: 100%;
height: auto;
display: block;
position: relative;
color: #333333;
font-family: "Gill Sans", "Gill Sans MT", "Myriad Pro", "DejaVu
Sans Condensed", Helvetica, Arial, sans-serif;
font-size: 14px;
text-align: left;
line-height: 20px;
}
#navWrapper {
width: 100%;
height: 45px;
display: block;
padding-top: 10px;
padding-bottom: 10px;
position: relative;
clear: both;
border-bottom: 3px solid #000000;
background-color: #9FA2B2;
}
#navInnerWrapper {
width: auto;
height: auto;
display: block;
margin-left: auto;
margin-right: auto;
position: relative;
clear: both;
padding-right: 200px;
}
#topSocials {
width: 231px;
display: block;
position: relative;
float: left;
height: auto;
padding-top: 5px;
padding-left: 50px;
}
#navBar {
width: 600px;
display: block;
position: relative;
float: right;
height: auto;
color: #FFFFFF;
text-align: right;
text-transform: uppercase;
}
ul {
list-style-type: none;
}
ul li {
display: inline;
padding-left: 40px;
}
#navBar a:link {color: #16262E; text-decoration: none; }
#navBar a:visited {color: #16262E; text-decoration: none; }
#navBar a:hover {color: #FFFFFF; text-decoration: none; }
#navBar a:active {color: #16262E; text-decoration: none; }
这是我缩小浏览器时的样子。 https://imgur.com/a/BLSilIp
希望导航响应正确,右边的链接和左边的社交图标。
答案 0 :(得分:0)
您的代码非常错误。查看我在CSS中修复并添加了多少个属性。了解更多。
#navWrapper {
width: 100%;
/* height: 45px; */
/* display: block; */
/* padding-top: 10px; */
/* padding-bottom: 10px; */
/* position: relative; */
/* clear: both; */
border-bottom: 3px solid #000000;
background-color: #9FA2B2;
box-sizing: border-box;
}
#navInnerWrapper {
/* width: auto; */
/* height: auto; */
/* display: block; */
/* margin-left: auto; */
/* margin-right: auto; */
/* position: relative; */
/* clear: both; */
/* padding-right: 200px; */
/* padding: 20px 0; */
display: flex;
flex-flow: wrap;
justify-content: space-between;
align-items: center;
}
#topSocials {
/* width: 231px; */
/* display: block; */
/* position: relative; */
/* float: left; */
/* height: auto; */
/* padding-top: 5px; */
/* padding-left: 50px; */
display: flex;
flex-direction: row;
padding: 10px;
}
#topSocials a {
margin-right: 10px;
}
#navBar {
/* width: 600px; */
/* display: block; */
/* position: relative; */
/* float: right; */
/* height: auto; */
/* color: #FFFFFF; */
/* text-align: right; */
text-transform: uppercase;
padding: 10px;
}
ul {
list-style-type: none;
display: flex;
flex-flow: wrap;
padding: 0;
margin: 0;
}
ul li {
/* display: inline; */
/* padding-left: 40px; */
margin-left: 20px;
}
ul li:first-child {
margin-left: 0px;
}
#navBar a:link {
color: #16262E;
text-decoration: none;
}
#navBar a:visited {
color: #16262E;
text-decoration: none;
}
#navBar a:hover {
color: #FFFFFF;
text-decoration: none;
}
#navBar a:active {
color: #16262E;
text-decoration: none;
}
<div id="navWrapper">
<div id="navInnerWrapper">
<div id="topSocials">
<a href="URL"><img alt="facebook icon" src="images/fb_social.png"></a>
<a href="URL"><img alt="linkedin icon" src="images/linkedin_social.png"></a>
</div>
<div id="navBar">
<ul>
<li><a href="#">About</a></li>
<li><a href="#">Our Work</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</div>
</div>