【问题标题】:Vertical navigation bar takes the full width of the page垂直导航栏占据页面的整个宽度
【发布时间】:2014-03-18 09:13:14
【问题描述】:

我是 html 和 css 新手,我开始制作自己的网站,但遇到了一个问题,我的导航栏占据了页面的整个宽度,我想将页面的内容添加到我的垂直旁边居中导航栏。

html:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="css/style.css">
<title>Insert title here</title>
</head>
<body>
        <div class="logoBar">   
            <div class="helper">        
                <div class="logo"></div>
            </div>
        </div>

        <div id="vmenu"> 
            <ul> 
              <li><a href="">Acceuil</a></li> 
              <li><a href="">Identification</a></li> 
              <li><a href="">Mon Parcours</a></li> 
              <li><a href="">Ma Formation</a></li> 
              <li><a href="">Mes Projets</a></li> 
              <li><a href="">Dossier de Veille</a></li> 
              <li><a href="">Contact Me</a></li> 
            </ul>   
        </div> 

        <div class="content">
        </div>

</body>
</html>

css:

body{
    background:url(../img/bg.png) no-repeat center center fixed;
    -moz-background-size: cover;
    -webkit-background-size: cover;
    -o-background-size: cover;
    background-size: cover; 
    margin:0 ;
    padding:0;
    height: 100%;
    width: 100%;
}

.logoBar{ 
    background:url(../img/LogoBar.png) ;
    height:150px;   
    position:relative;

}

.helper{
    height:120px;
    width:100%;
    display: table;
}

.logo{  
    background:url(../img/Untitled-1.png) no-repeat center;
     width:262px;
     height:80px;
     margin:0 auto;
     display: table-cell;
     vertical-align: middle;
}




div#vmenu { 
   margin: 0; 
   padding: .25em 0em .25em 0em; 
   border: solid 1px #30c9e0; 
   background: #7895A2; 
   width: 13.5em; 

} 

div#vmenu ul { 
   margin: 0; 
   padding: 0; 
   list-style: none;


} 

div#vmenu ul li { 
   margin: 0; 
   padding: 0; 
   list-style: none; 

} 

div#vmenu ul a:link { 
   margin: 0; 
   padding: .2em 0em .2em .4em; 
   text-decoration: none; 
   font-size:17pt;   
   background-color: #7895A2; 
   color: #0059a0; 
   display: block; 

} 

div#vmenu ul a:active { 
   margin: 0; 
   padding: .25em .5em .25em .5em; 
   text-decoration: none; 
   font-weight: bold; 
   font-size:17pt;
   background: #4d8cba; 
   color: #ffffff; 
   display: block; 
} 

div#vmenu ul a:visited { 
   margin: 0; 

   text-decoration: none; 
   font-weight: bold; 
   font-size:17pt; 
   background: #4d8cba; 
   color: #ffffff; 
   display: block; 
} 

div#vmenu ul li a:hover { 
   margin: 0; 
   padding: .2em 0em .2em .4em; 
   text-decoration: none; 
   font-weight: bold; 
   font-size:17pt;
   background-color: #30c9e0; 
   color: #ffffff; 
   display: block; 
} 


.content{
  width: 700px ;
  height:50px;
  margin-left: auto ;
  margin-right: auto ;
  border: 1px solid black;
  background-color:black;
  text-align:center;

}

【问题讨论】:

    标签: html css navigation uinavigationbar


    【解决方案1】:

    不确定你是否想要这个。

    在你的 CSS 中更新这个

    div#vmenu { 
       margin: 0; 
       padding: .25em 0em .25em 0em; 
       border: solid 1px #30c9e0; 
       background: #7895A2; 
       width: auto; 
       float:left;
    
    } 
    

    我希望这是你想要的。

    【讨论】:

      【解决方案2】:

      div 元素是 display: block;,这意味着它具有 100% 的宽度。 只需为导航设置宽度即可。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-11-29
        • 1970-01-01
        • 1970-01-01
        • 2020-06-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多