这是我的网站:oxfordmakespace.com
我的问题是我无法让导航栏一直向左移动,我搜索了可能正在执行的填充或边距,但找不到它们。
使用.nav属性修改导航栏
这是我的CSS
body {
background-color: #999;
background-size: 100% ;
background-repeat: repeat;
/* background-image: url(/Images/swanon.jpg); */
font-size: 87.5%;
font-family:Arial, serif-sans;
}
.body {
/*text-align: left;*/
clear: both;
margin-left:auto;
margin-right: auto;
margin-top: 0%;
width: 80%;
}
div {
background: #1000;
}
.mainheader img {
margin: 0% auto;
width: 100%;
height: 8%;
padding: 10px 0 0 0 ;
}
.maincontent {
line-height: 15px;
border-radius: 2px;
-moz-border-radius: 2px;
-o-border-radius: 2px;
-webkit-border-radius: 2px;
}
.Content {
background: #855; /*red -----------*/
float: left;
width: 60%;
}
.topcontent {
background: #777; /* grey -------------------*/
float: left;
width: 90%;
border-radius: 2px;
-moz-border-radius: 2px;
-o-border-radius: 2px;
-webkit-border-radius: 2px;
padding: 1% 5%;
margin-top: 2px;
margin-bottom: 2px;
}
.bottomcontent {
background: #777; /* grey -------------------*/
float: left;
width: 90%;
border-radius: 2px;
-moz-border-radius: 2px;
-o-border-radius: 2px;
-webkit-border-radius: 2px;
padding: 1% 5%;
margin-top: 2px;
margin-bottom: 2px;
}
.post-info {
Font-style: italic;
color: #222;
fon-size: 85%;
}
.top-sidebar {
border-radius: 2px;
-moz-border-radius: 2px;
-o-border-radius: 2px;
-webkit-border-radius: 2px;
padding: 1% 5%;
margin-top: 2px;
margin-bottom: 2px;
margin-left: 0.5%;
width: 29.5%;
float: left;
background-color: #255; /* cyan -------------------*/
}
.middle-sidebar {
border-radius: 2px;
-moz-border-radius: 2px;
-o-border-radius: 2px;
-webkit-border-radius: 2px;
padding: 1% 5%;
margin-top: 2px;
margin-bottom: 2px;
margin-left: 0.5%;
width: 29.5%;
float: left;
background-color: #254; /* cyan green -------------------*/
}
.bottom-sidebar {
border-radius: 2px;
-moz-border-radius: 2px;
-o-border-radius: 2px;
-webkit-border-radius: 2px;
padding: 1% 5%;
margin-top: 2px;
margin-bottom: 2px;
margin-left: 0.5%;
width: 29.5%;
float: left;
background-color: #253; /* green -------------------*/
}
.mainfooter {
margin-top: 0%;
width: 100%;
float: left;
background-color: #666;
border-radius: 2px;
-moz-border-radius: 2px;
-o-border-radius: 2px;
-webkit-border-radius: 2px;
}
.mainfooter p {
text-align: center;
width: 92%;
padding-left: 0.8% ;
padding-right: 0.2%;
padding-bottom: 0;
padding-top: 0;
}
a {
text-decoration: none;
}
.maincontent a {
padding: 0 5px;
text-decoration: none;
}
.maincontent a:link, a:visited {
color: orange;
}
.maincontent a:hover, a:active {
padding: 0 5px;
color: white;
background-color: black;
margin: 0px;
}
/* navbar desktop */
.nav {
background-color: #612;
height: 30px;
border-radius: 5px;
-moz-border-radius: 5px;
-o-border-radius: 5px;
-webkit-border-radius: 5px;
}
.nav ul {
list-style: none;
margin: 0 auto;
}
.nav li {
float: left;
display: inline;
}
.nav a, .nav a:link, .nav a:visited {
float: left;
padding: 5px 5px 5px 5px;
color: white;
display: inline-block;
height: 20px;
}
.nav a:active, a:visited {
color: Black;
}
.nav .current a {
background: #499;
color: black; /*this changes the desktop view current link*/
border-radius: 5px;
}
.nav a:hover, .nav a:active, .nav .active a:link, .nav .active a:visited {
background: #253;
}
/*<!----------------------------------------------------------------->*/
.nav2 ul {
padding-right: 5%;
list-style: none;
margin: 0 auto;
}
.nav2 li {
float: right;
display: inline;
padding: 0;
/*margin: 0 5px 10px 0;
list-style: none;
display: inline-block;*/
}
.nav2 a, .nav a:link, .nav a:visited {
float: right;
padding: 5px 5px 5px 5px;
color: white;
display: inline-block;
height: 20px;
}
.nav2 a:active, a:visited {
color: Black;
}
.nav2 .current a {
background: #499;
color: black; /*this changes the desktop view current link*/
border-radius: 5px;
}
.nav2 a:hover, .nav a:active, .nav .active a:link, .nav .active a:visited {
background: #253;
}
@media only screen and (min-width: 150px) and (max-width: 600px), (orientation : portrait)
{
.body {
width: 95%;
font-size: 100%;
}
.mainheader img {
width: 100%;
height: 100%;
}
.mainheader nav {
background-color: #FFF;
height: 120px;
}
.mainheader nav ul {
padding-left: 0%;
}
.mainheader nav ul li {
width: 100%;
margin: 0 auto;
text-align: center;
}
.mainheader nav a, .mainheader nav a:link, .mainheader nav a:visited {
float: none;
color: Black;
height: 20px;
display: block;
}
.mainheader nav a:hover, .mainheader nav a:active, .mainheader nav .active a:link, .mainheader nav .active a:visited {
background: #199; /*<!---------------------------nav button color-->*/
}
.mainheader nav ul li a {
}
.maincontent {
line-height: 15px;
}
.Content {
background: #215; /*blue-----------*/
float: left;
width: 100%;
margin-top: 2%;
}
.post-info {
display: none;
}
.topcontent, .bottomcontent {
background: #777; /* grey -------------------*/
float: left;
width: 90%;
padding: 1% 5%;
margin-top: 2%;
margin-bottom: 2%;
}
.top-sidebar, .middle-sidebar, .bottom-sidebar {
padding: 1% 5%;
margin-top: 0.5%;
margin-bottom: 0.5%;
margin-left: 0%;
width: 90%;
float: left;
}
/*NAVBAR--------------------------*/
.nav {
position: relative;
min-height: 40px;
background-color: #999;
margin: 0px 0;
}
a {
color: Black;
height: 20px;
display: block;
}
.nav ul {
width: 50%;
padding: 2% 2% 2% 2%; /*this controls the displayed word padding*/
position: absolute;
top: 0; /*physical position of box holding links*/
left: 46.2%; /*physical position of box holding links*/
border: solid 0px #aaa;
background: #fff url(Images/topright.png) no-repeat ; /*background color for links*/
background-size: 15% 75%; /*changes for image*/
background-position: 90% 50%;
border-radius: 15px;
-moz-border-radius: 15px;
-o-border-radius: 15px;
-webkit-border-radius: 15px;
}
.nav li {
width: 100%;
text-align: left;
float: left;
display: none; /* hide all <li> items */
margin: 0;
}
.nav .current {
padding: 0 0 10px 0 ;
Background: none;
pointer-events: none; /*allows you to click on the menu usinga touch screen and not make the page load*/
display: block; /* show only current <li> item */
}
.nav .current a {
background: none;
color: Black; /* changes current links color when not active*/
}
/*-----------------------------------------------------*/
.nav a {
display: block;
padding: 3% 5% 3% 10%;
text-align: Left;
color: black; /*changes every text item in mobile menu*/
font-size: 150%;
font-style: Arial,serif-sans;
}
.nav a:link {
color: black;
}
.nav a:hover { /*changes the moused over or selected link in nav bar*/
border-radius: 5px;
color: black;
background: lightgreen;
}
/*-------------------------------------------------------*/
/* on nav hover */
.nav ul:hover {
background-image: none;/*hides the background image when the navbar exands to stop it stretching*/
}
.nav ul:hover li {
display: block;
margin: 0 0 5px; /*space between each menu item*/
}
/*-------------------------------------------------------*/
} /*media query end--------------------------*/
答案 0 :(得分:3)
padding
.nav > ul
问题
.nav ul {
list-style: none;
margin: 0 auto;
padding: 0; //reset default padding
}
您的ul
元素也已折叠。您需要使用clearfix或overflow: hidden;
清除浮动元素。这有点意外,但你真的应该纠正这些问题。应添加以下内容:
.nav{
background-color: #612;
height: 30px;
border-radius: 5px;
-moz-border-radius: 5px;
-o-border-radius: 5px;
-webkit-border-radius: 5px;
overflow: hidden; //add to correct floats
}
.nav ul { //for both nav menus
list-style: none;
margin: 0 auto;
padding: 0; //reset default padding
overflow: hidden; //add to correct floats
float: left; // which will float both left, we will override the second since it has an identifier
}
.nav2{
float: right;
}
.nav2 ul{
padding-right: 5%;
list-style: none;
margin: 0 auto;
float: none; //add to clear the float from the other ul
}
答案 1 :(得分:0)
ul自动倾向于同时具有边距和填充 添加
padding: 0;
到你的列表,它应该一直到左边