2017-02-23 110 views
0

我的导航栏不以内联方式显示。 当更改代码:.nav li a {...}.nav li{...}它是一致的,但所有css函数都从HTML中的class = nav中消失。 我试图添加ul.nav{display: inline-block;},但它什么也没做。导航栏不显示内嵌

我希望我解释得很好,我试图弄明白,因为昨天...

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

 
.container { 
 
    max-width: 940px; 
 
    margin: 0 auto; 
 
    padding: 5px; 
 
} 
 

 
.header { 
 
    background-color: #333; 
 
} 
 

 
.nav { 
 
    list-style-type: none; 
 
    margin: 0; 
 
    padding: 20px 0; 
 
    letter-spacing: 1.6px; 
 
} 
 

 
.nav li a { 
 
    display: inline; 
 
    text-decoration: none; 
 
    transition: 0.4s; 
 
    color: #fff; 
 
    font-family: 'Raleway', sans-serif; 
 
    font-weight: 600; 
 
    font-size: 12px; 
 
    margin-right: 25px; 
 
    text-transform: uppercase; 
 
} 
 

 
.nav li a:hover { 
 
    background-color: #ffffff; 
 
    color: #333; 
 
    font-weight: 900; 
 
    padding: 24px 10px; 
 
    font-size: 12px; 
 
    cursor: pointer; 
 

 

 
}
<!DOCTYPE html> 
 
<html> 
 
    <head> 
 
    <link href="https://fonts.googleapis.com/css?family=Raleway:400, 600" rel="stylesheet"> 
 
    <link href="stylesheet.css" type="text/css" rel="stylesheet"> 
 
    <script type='text/javascript' src='script.js'></script> 
 
    <script src="jquery-3.1.1.min.js"></script> 
 
    <title>Smart-Home</title> 
 
    </head> 
 
<body> 
 

 
    <div class="header"> 
 
    <div class="container"> 
 
     <ul class="nav"> 
 
     <li><a href ="indexKontakt.html"> O firmie </a></li> 
 
     <li><a href ="indexKontakt.html"> Produkty </a></li> 
 
     <li><a href ="indexKontakt.html"> Nasi partnerzy </a></li> 
 
     <li><a href ="indexKontakt.html"> Kontakt </a></li> 
 
     </ul> 
 
    </div> 
 
    </div>

回答

5

如果我理解正确的话,你可以将其添加到CSS:

.nav li{ 
    display: inline; //or inline-block 
} 

这里 - 工作版本https://jsfiddle.net/2rovth3a/

+0

或'显示:inline-block的;'过了,我想你需要更正understoor为*了解*;) –

+0

@Hidayt拉赫曼定点谢谢:) – Shtut

+0

谢谢你洙多!有用! 我只是想知道为什么当我将'display:inline-block;'添加到'.nav li a {}'或'.nav {}'时,它不起作用: – stackmack

1

我想你应该添加display: inline-block;li

Why is my bootstrap navbar not displaing inline?

+0

@Shtut –

+0

同样的答案,这是不重复的,因为OP没有提到bootstrap任何地方 –

+0

:D ...好吧先生...可能是这个答案张贴,而我正在阅读这个问题...将删除这个if你喜欢;) –

0

enter image description here喜的朋友可能重复;

You just make 

.nav li{display:inline-block;} 

and remove .nav li a {display: inline;} 

see attachment file....[![enter image description here][1]][1]