Home Web Front-end CSS Tutorial web page navigation exercises

web page navigation exercises

Apr 04, 2017 am 11:20 AM
web page

When I was doing NavigationExercise, I looked at the source code of successful websites for practice. I hope that through these successful codes, I can learn the front-end behind the code. Engineers’ programming ideas.
While viewing the source code, I also learned a lot of details that I had ignored before, and I feel that I have benefited a lot.

When I open the css file of Lagou.com, the first part uses comments to mark the time of the document, the author, and certain elements within the style sheet that are easy to view. color, width and height.
The second part is some initialized element styles and initialized public classes.
The third part is the style of each part of the web page.

  • The first navigation exercise I did was the navigation of Lagou.com.

    web page navigation exercises

    web page navigation exercises

    Observation and thinking
    1. How many levels of nesting do I need to write for this navigation?
    2. Do you want to set the width or use 100%?
    3. How to center?
    4. How to realize the thin line between login and registration.
    These are the problems I discovered, and there will definitely be problems as I go along.

    • Set the surrounding element style

        #header{
            background: #fafafa;
            height: 60px;
            min-width: 1024px;
            border-top: 3px solid #00B38A;
        }
        #header .wrapper{
            width: 1024px;
            margin: 0 auto;
        }
      Copy after login

      1. The outermost periphery#header sets the height of the navigation and the background color of the navigation. Added border-top style.
      2. The internal .wrapper sets the width, and the external #header sets the minimum width. The attribute values ​​of both are the same. Of course, the width of the display must be greater than 1024px, so by adding margin: 0 auto; in .wrapper, the content with a width of 1024 can be centered.

    • Carry out basic layout of navigation elements

      web page navigation exercises

      web page navigation exercises

        .wrapper .logo{
            float: left;
            margin-top: 7px;
            width: 229px;
            height: 43px;
            background: url(image/logo.png) no-repeat;
        }
        .wrapper .navheader{
            float: left;
            margin-left: 30px;
        }
        .navheader li{
            float: left;
        }
        .wrapper .loginTop{
            float: right;
        }
        .loginTop li{
            float: left;
        }
      Copy after login

      1. Set logo At that time, the original size of Picture is 229×43, so this setting will not stretch the picture.
      2. The logo and navigation menu are floating to the left, and the login and registration buttons are floating to the right.

    • Modify the basic style of the navigation menu
      Note: When the mouse passes over a, there needs to be a 3px border-bottom, But this 3px cannot exceed #header. What needs to be done is to make the height of li 60px and the height of a to 57px, so that when the mouse passes by, it will be displayed The bottom edge will not protrude.

      web page navigation exercises

      web page navigation exercises

        .navheader li{
            height: 60px;
            padding: 0px 20px;                
        }
        .navheader li a{
            display: block;
            line-height: 57px;
            text-decoration: none;
            color: #999;
            font-size: 20px;
        }
        .navheader li a:hover{
            color: #333;
            border-bottom: 3px solid #00B38A;
        }
        .loginTop li{
            height: 30px;
            line-height: 30px;
            color: #FFF;
            background: #00B38A;
        }
        .loginTop li a{
            display: block;
            line-height: 30px;
            padding: 0px 10px;
            color: #fff;
            text-decoration:none ;
        }
        .loginTop li a:hover{
            color: #CCEAE3;
        }
      Copy after login

      1, a is an inline element and needs to be converted to block level element so that the height can be set. If the inline element is not set to block level and the line height is set directly, although the height can be changed and occupy the document flow, the space occupied by the line height will not belong to a.
      2. Those who are careful can find that I only set the row height for each a, and did not set the height, because in IE6 and 7 versions of the browser, I found that when the height was not set, I found a does not have the width that fills the parent element like a true block-level element. But after setting the height, I found that they suddenly had the characteristics of block-level elements. But we don't want him to do that, so I won't write the height. This effect is compatible. If you write it, it is very simple. Just add a float<a href="http://www.php.cn/wiki/974.html" target="_blank">:left</a>
      3 for a. ie6 does not support images in png format. . . . .

    • In fact, at first glance, it seems to have the appearance, but I found that when my mouse passed through the menu, the change of the menu was gradual, not sudden.

        .navheader a,.loginTop a{
            transition: all .2s ease-in-out ;
            -webkit-transition: all .2s ease-in-out ;
            -moz-transition: all .2s ease-in-out ;
            -o-transition: all .2s ease-in-out ;
        }
      Copy after login

      transitionThis attribute can be set, and when a certain style of an element changes, the gradient can be changed. He can achieve more exciting pictures and needs to learn the relevant knowledge of html5. Will continue to learn.

    • *{<a href="http://www.php.cn/wiki/938.html" target="_blank">outline</a>:none;} Set the outline of all elements to none by default.

    • ##body,p,a,span,ul,li{margin: 0;padding: 0;}Set the inner margins of all elementsOuter margin is 0.

    • ul.<a href="http://www.php.cn/wiki/1081.html" target="_blank">reset</a>{list-style:none;}去除掉列表的默认样式

    • 首先分出body与footer两个部分。这里面还涉及相应的height与min-height设置,但是这些又涉及一些兼容的问题,所以我就先不写了,回头再另写一篇。

    • 最外层嵌套使用id='header'标记,方便寻找里面子元素,里面就可以用class啦,.wrapper可以用作包围元素做公共类使用。class="navheader"class="loginTop"可以作为查找元素使用。

    • ul>li>a,一般的导航基本上都是这样的结构。

    • ul前的a可以以背景为图片,做链接。

    • 第一步:设计出html结构,并为元素设置相应的id与类

          <p>
              </p><p>
                  </p><p>
                      <a></a>
                      </p>
      Copy after login
                            
      • 首页
      •                     
      • 论坛
      •                     
      • 我的简历
      •                     
      • 发布职位
      •                 
                      
                            
      • 登录
      •                     
      • |
      •                     
      • 注册
      •                 
                                                 

          

    • 对网页进行全局的css设置。
      我先写下做导航时我用到的

    • 对导航进行css设置

    The above is the detailed content of web page navigation exercises. For more information, please follow other related articles on the PHP Chinese website!

    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    AI Hentai Generator

    AI Hentai Generator

    Generate AI Hentai for free.

    Hot Article

    R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
    4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O. Best Graphic Settings
    4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O. How to Fix Audio if You Can't Hear Anyone
    4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
    WWE 2K25: How To Unlock Everything In MyRise
    1 months ago By 尊渡假赌尊渡假赌尊渡假赌

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    Making Your First Custom Svelte Transition Making Your First Custom Svelte Transition Mar 15, 2025 am 11:08 AM

    The Svelte transition API provides a way to animate components when they enter or leave the document, including custom Svelte transitions.

    Working With GraphQL Caching Working With GraphQL Caching Mar 19, 2025 am 09:36 AM

    If you’ve recently started working with GraphQL, or reviewed its pros and cons, you’ve no doubt heard things like “GraphQL doesn’t support caching” or

    Show, Don't Tell Show, Don't Tell Mar 16, 2025 am 11:49 AM

    How much time do you spend designing the content presentation for your websites? When you write a new blog post or create a new page, are you thinking about

    Building an Ethereum app using Redwood.js and Fauna Building an Ethereum app using Redwood.js and Fauna Mar 28, 2025 am 09:18 AM

    With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum

    Creating Your Own Bragdoc With Eleventy Creating Your Own Bragdoc With Eleventy Mar 18, 2025 am 11:23 AM

    No matter what stage you’re at as a developer, the tasks we complete—whether big or small—make a huge impact in our personal and professional growth.

    A bit on ci/cd A bit on ci/cd Apr 02, 2025 pm 06:21 PM

    I&#039;d say "website" fits better than "mobile app" but I like this framing from Max Lynch:

    Vue 3 Vue 3 Apr 02, 2025 pm 06:32 PM

    It&#039;s out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

    Let's use (X, X, X, X) for talking about specificity Let's use (X, X, X, X) for talking about specificity Mar 24, 2025 am 10:37 AM

    I was just chatting with Eric Meyer the other day and I remembered an Eric Meyer story from my formative years. I wrote a blog post about CSS specificity, and

    See all articles