简体   繁体   English

使用html和css在导航栏下面放置侧边栏和文章

[英]Positioning sidebar and article below navbar with html and css

with this html code: 与此HTML代码:

    <header>
        <ul>
            <li> <a href="#">...</a> </li>
            <li> <a href="#">...</a> </li>
            <li> <a href="#">...</a> </li>
            <li> <a href="#">...</a> </li>
            <li> <a href="#">...</a> </li>
        </ul>
    </header>

    <main>
        <nav>
            <ul>
                <li> <a href="#">...</a> </li>
                <li> <a href="#">...</a> </li>
                <li> <a href="#">...</a> </li>
                <li> <a href="#">...</a> </li>
                <li> <a href="#">...</a> </li>
            </ul>
        </nav>

        <article>
            <section>
                <ul>
                    <li> <a href="#">...</a> </li>
                    <li> <a href="#">...</a> </li>
                    <li> <a href="#">...</a> </li>
                    <li> <a href="#">...</a> </li>
                    <li> <a href="#">...</a> </li>
                </ul>
            </section>

            <section>
                <ul>
                    <li> <a href="#">...</a> </li>
                    <li> <a href="#">...</a> </li>
                    <li> <a href="#">...</a> </li>
                    <li> <a href="#">...</a> </li>
                    <li> <a href="#">...</a> </li>
                </ul>
            </section>

            <section>
                <ul>
                    <li> <a href="#">...</a> </li>
                    <li> <a href="#">...</a> </li>
                    <li> <a href="#">...</a> </li>
                    <li> <a href="#">...</a> </li>
                    <li> <a href="#">...</a> </li>
                </ul>
            </section>

            <section>
                <ul>
                    <li> <a href="#">...</a> </li>
                    <li> <a href="#">...</a> </li>
                    <li> <a href="#">...</a> </li>
                    <li> <a href="#">...</a> </li>
                    <li> <a href="#">...</a> </li>
                </ul>
            </section>

            <section>
                <ul>
                    <li> <a href="#">...</a> </li>
                    <li> <a href="#">...</a> </li>
                    <li> <a href="#">...</a> </li>
                    <li> <a href="#">...</a> </li>
                    <li> <a href="#">...</a> </li>
                </ul>
            </section>
        </article>
    </main>

    <footer>
        <ul>
            <li> <a href="#">...</a> </li>
            <li> <a href="#">...</a> </li>
            <li> <a href="#">...</a> </li>
            <li> <a href="#">...</a> </li>
            <li> <a href="#">...</a> </li>
        </ul>
    </footer>

I am trying write a css for acomplish this things: 我正在尝试为完成此事情写一个CSS:

  • one fixed navbar on top (already ok) 顶部有一个固定的导航栏(已经可以了)
  • main area with a sidebar and an "article" area (need fix position and alignment of its parts) 具有侧边栏和“文章”区域的主要区域(需要固定位置并对齐各个部分)
  • the article area needs to be placed to the roght of the sidebar, but right now it's been displayed on the bottom of it. 文章区域需要放在侧边栏的最上方,但现在它已显示在其底部。
  • footer has some strange banner been displayed below (only when mouse cursor is not hovering it) like it's showing here: 页脚下面显示了一些奇怪的横幅(仅当鼠标光标没有悬停时),就像这里显示的那样:

https://jsfiddle.net/klebermo/5axmocwp/1/ https://jsfiddle.net/klebermo/5axmocwp/1/

Anyone can give some hints of how to fix that? 任何人都可以提供一些解决方法的提示?

May be this is what you want? 可能这就是您想要的吗? I only change this in css: 我只在CSS中更改此设置:

main {
  margin-top: 32px;

  /* below lines was added */
  display: flex;
  flex-direction: row-reverse;
  justify-content: flex-end;
}

footer {
  left: 0;
  bottom: 0;
  width: 100%;
  background-color: #333;
  color: white;
  text-align: center;

  /* below line was added */
  height: 50px;
}

Here is example . 这是例子 I use flexbox in this solution - great tutorial about this is HERE - however you can also use even better tool for layouts: GRID . 我在此解决方案中使用flexbox-关于此的很棒的教程在这里 -但是您也可以使用更好的布局工具: GRID

Suggestion : use class attribute in html and then use that class name in css - direct html tag names in css is not good practice - if possible avoid it 建议 :在html中使用class属性,然后在css中使用该类名-在css中直接使用html标签名不是一个好习惯-如果可能的话,避免使用它

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

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