简体   繁体   English

显示:内联不适用于div

[英]display: inline doesn't work properly with div

I'm a HTML/CSS beginner and currently I'm building a simple website. 我是HTML / CSS初学者,目前正在构建一个简单的网站。 What I wanna do is I'd like to make 3 divs. 我想做的是让3个div。 One for the whole site, one for the content and one for the navigation list - row. 一个用于整个网站,一个用于内容,一个用于导航列表-行。

It should look like this: 它看起来应该像这样:

_ _ _ _ _ _ (navigation list - row) _ _ _ _ _ _(导航列表-行)

asdfwefwefwe asdfwefwefwe

cofwerferwefw (content) cofwerferwefw(内容)

To recognize the divs I background-colored them. 为了识别div,我对它们进行了背景着色。 Whenever I use display-inline it looks like this. 每当我使用display-inline时,它看起来都是这样。 whole site div(red colored), main content(orange colored) 整个网站div(红色),主要内容(橙色)

http://puu.sh/iFyeC/a48443bc07.png http://puu.sh/iFyeC/a48443bc07.png

When I use display: inline-block whole site div(red colored), main content(orange colored), navigation list - row(blue colored) 当我使用显示广告时:内嵌整个网站div(红色),主要内容(橙色),导航列表-行(蓝色)

http://puu.sh/iFyil/40e73716e7.png http://puu.sh/iFyil/40e73716e7.png

Now it works but I want a navigation - row bar and not a ranked list but I don't know how to do it. 现在它可以工作了,但是我想要一个导航-行栏,而不是排名列表,但是我不知道该怎么做。

Here is my css for the navigation list - row: 这是我的导航列表的CSS-行:

.navigationlist{
    height:20%;
    width:100%;
    display:inline-block;
    background-color:blue;
}

Thank you very much for reading and for hopefully good answers. 非常感谢您的阅读和希望得到很好的答复。

Firstly, Use Home,Story,Hereos All in list tag!! 首先,在列表标签​​中使用“家庭,故事,Hereos全部”!

<ul>
<li>Home</li>
<li>Story</li>
<li>Hereos</li<
......
<ul>

And then Style Then element 然后样式然后元素

li
{
display:inline;
padding:10px;
}

Your Out will be 你的出将
http://myslambook.pe.hu/demo.png http://myslambook.pe.hu/demo.png

 li { display: inline-block; border-radius: 5px; font-size: 0.4em; margin: 1% auto; padding: 1%; text-align: center; border: 2px solid #000; background-color: rgba(255, 255, 255, 0.7); } 
 <ul> <li>Hello</li> <li>Stack Overflow</li> <li>World</li> </ul> 

Apart from using the li and ul I will suggest you make use of the bootstrap navbar class whenever you have to create navigation bars. 除了使用li和ul外,我还建议您在必须创建导航栏时都使用bootstrap navbar类。 You can read on its advantages online ( http://getbootstrap.com/components/#navbar ) plus it will also allow you to highlight one of the li by default. 您可以在线阅读其优势( http://getbootstrap.com/components/#navbar ),此外,默认情况下它也允许您突出显示li之一。 In your case it would be something like. 在您的情况下,它将是类似的。

<nav class="navbar navbar-default">
    <div class="container-fluid">
        <div>
            <ul class="nav navbar-nav">
                <li><a href="#">Hello</a></li>
                <li><a href="#">Stack Overflow</a></li> 
                <li><a href="#">World</a></li> 
            </ul>
        </div>
    </div>
</nav>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM