Home Web Front-end CSS Tutorial Web page navigation exercises (2)

Web page navigation exercises (2)

May 09, 2017 pm 02:14 PM

My other NavigationExercise was carried out with reference to the navigation of Guoker.com. When I checked the source code, I found that the css code of this website was really clear and classy. The organization is also great. Although I don’t understand it very well, I just like it when I look at it.

Web page navigation exercises (2)

Guoke.com Navigation

When I see this navigation for the first time, there are a few things that I need to think about carefully
1. In which element should the small house icon in front of the homepage be nested?
2. How to implement the small triangle at the bottom of the homepage?
3. More triangles at the back?
4. How to implement the drop-down menu that appears after clicking More?
I will only implement the left side first, so that I can connect many knowledge points.

  • Step one: Design the corresponding html structure, and mark the id and class

             <p id="gheader">
                 <p class="gh-wrap">
                     <p class="fl">
                         <ul class="gh-nav reset">
                             <li>
                                 <a href="">
                                     <span class="gnicon-home"></span>
                                     首页
                                     <b class="gnarrow-up"></b>                                    
                                 </a>
                             </li>
                             <li><a href="">科学人</a></li>
                             <li><a href="">小组</a></li>
                             <li><a href="">问答</a></li>
                             <li><a href="">Mooc学院</a></li>
                             <li><a href="">知性</a></li>
                             <li id=&#39;moreNav&#39;>
                                 <a href="" class="">
                                     更多
                                     <i class="gnarrow-down"></i>
                                 </a>
                                 <p class="gh-list">
                                     <ul class="reset">
                                         <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>
                                 </p>
                             </li>
                         </ul>
                     </p>
                 </p>
             </p>
    Copy after login

    1. This html structure is also a two-layer p package content #gheader .gh-wrapThe outer layer is to indicate the head, and the inner layer can be used for style and position adjustment of the entire head part
    2. Different from the previous navigation exercise, this There is another layer surrounding ul because the head of the original web page has navigation+search on the left and message reminders on the right. One left float and one right float. This makes the structure clearer.
    3,

    • The front icon of link a.

      Web page navigation exercises (2)

      ##Web page navigation exercises (2)

      When I set the icon and text to be centered on the homepage, the reason is that IE6 and 7 The rendering of vertical-line: mid

      dle; is inconsistent.

      Web page navigation exercises (2)

      Modern browsers

      There is no additional code. Let me describe it. The height of the content framed by the red border is set. row height, and both are equal. Then the text content is naturally centered.

      Setting vertical-line:middle; for
      picture means placing the picture in the middle of the line, so the picture finds the bottom (short picture) or top ( Picture height).

      Web page navigation exercises (2)

      IE6 and 7

      have the same settings as modern browsers, but produce different viewing effects. I can’t explain why, but I can see the pattern. IE6 and 7 choose to put both pictures and text at the top, and align them in the center.

      So I thought of a compatible solution, choose to set the height of the front icon and the peripheral element of the text
      a to the same height as the picture, and set the height equal to the line height, then the text can be Centered, and the image setting vertical-line: middle; can be aligned with the top or bottom of the text within a. Can also be aligned horizontally (ie6, 7).

      .gh-wrap .gh-nav li a{
          display: inline-block;
          height: 18px;
          line-height: 18px;
          padding: 11px;
          text-decoration: none;
          color: #d5d5d5;
      }
      .gh-nav li a:hover{
          background: #393939;
          color: #fff;
      }
      .gnicon-home{
          background: url(gk/5-icon.png) transparent no-repeat;
          display: inline-block;
          vertical-align: middle;
      }
      .gh-nav  a .gnicon-home{
          background-position: 0 0;
          height: 18px;
          width: 16px;
          margin-right:5px ;
      
      }
      Copy after login

      1. If you are careful, you can find that I have reset the style of

      a because I need to set the height for a. I am worried that the width will fill the parent element as I worried about in the previous note, so I converted inline elements to inline block-level elements. The conversion method is also mentioned in this note. In fact, I have also made notes about the performance of vertical-line modern browsers here. 2. When the front-end engineer of Guoke.com set the front icon style, he made settings separately. A common setting, set the source of the background image, converted the presentation form, and set the centering. So when except for the home page, Front icons can also use this public style.
      Then set a separate style, set the position of the image, size, and special settings such as margins.

    • Set the equilateral and inverted triangles

      Web page navigation exercises (2)
      ##Web page navigation exercises (2)

       .gnarrow-down,.gnarrow-up{
           line-height: 0;
           height: 0;
           width: 0;
           border: 4px solid transparent;
           color: #4c4c4c;
       }
       .gnarrow-up{
           position: absolute;
           border-bottom-color: #85C155;
           bottom: 0;
           left: 50%;
           margin-left: -4px;
       }
       .gnarrow-down{
           display: inline-block;
           vertical-align: middle;
           border-top-color:#d5d5d5 ;
           border-width: 3px;
           margin-left: 3px;
       }
       .gh-nav li a:hover{
           background: #393939;
           color: #fff;
       }
       .gh-nav li a:hover i,.gh-nav li a:hover b{
           color: #393939;
       }
      Copy after login

      1、设置这个三角,其实是很有技巧性的,觉得真的是对css了解的非常熟悉,才能想到这样的技巧。内容置空,宽度高度为0,设置其边框,然后通过分别设置上下左右的边框的颜色,可以获得各个方向的三角。
      2、注意:color这个属性具有继承性,他表示前景色,不仅设置文本的颜色,还设置了边框的颜色。在Web page navigation exercises (2)会发现识别不出透明色,然后通过分别设置前景色来改变border的颜色。
      3、绿色箭头采用绝对定位。下拉箭头采用行内块级元素进行定位。

    • 设置子菜单

      Web page navigation exercises (2)

      Web page navigation exercises (2)

       #moreNav .gh-list{
           position: absolute;
           right: 0;
           top: 40px;
           width: 80px;
           border: 1px solid #e0e0e0;
           box-shadow: 1px 1px 1px #f3f3f3;
           background: #fff;
           padding: 7px 0 8px;
       }
       #moreNav .gh-list li {
           /*之前设置过浮动*/
           width: 100%;
           height: 25px;
       }
       #moreNav .gh-list li a{
           /*之前设置过表现形式为行内块级元素,并设置过padding*/
           width: 100%;
           height: 25px;
           text-align: center;
           line-height: 25px;
           padding: 0;
       }
       #moreNav .gh-list li a:hover{
           background: #e0e0e0;
       }
      Copy after login

      1、子菜单需要进行绝对定位。
      2、需要理解特制度的概念,我会专门写这个的,因为我们在编写css样式规则时,却发现这个规则先后顺序不一样,展示的效果不一样,css规则写的嵌套层次不一样,展示的结果可能也不一样,就像这里我们之前都设置过li>a的样式,所以会对子菜单的样式有影响。
      3、继承的样式即使靠的再进,也没有专门写过的样式优先级高。例如,line-height具备继承性,所以我就不打算为a写行高,但是a的行高却被之前设置的覆盖了,却没有继承父元素的样子。

    • 第二步 设置包围元素样式

         #gheader{
             width: 100%;
             height: 43px;
             background: #4C4C4C;
             position: fixed;
             top: 0;
             left: 0;
             z-index: 999;
         }
         #gheader .gh-wrap{
             height: 40px;
             min-width: 1030px;
             padding: 0 30px;
             border-bottom: 3px solid #85c155;
         }
      Copy after login

      1、这是一个头部固定的网页,但是position:fixed一旦这么设置,必然导致其宽度收缩内容,这样就无法设置头部背景啦,于是设置宽度值为100%。
      2、这里面的包围元素并没有要居中,而是以默认的格式。所以没有必要设置宽度,设置最小宽度就可以。当浏览器屏幕缩小时,也会有先收缩再维持的视觉效果。
      3、发现a里面有很对<b> <span> <i>这类标签,注意,我都放在了<a>里,因为这些行内元素,我们通过将其修饰,然后放置一些下拉箭头,首页图标,鼠标点击标记。

    • 第三步:对导航元素进行基本布局

      Web page navigation exercises (2)

      Web page navigation exercises (2)

             .fl{
             float: left;
         }
         #moreNav p{
             display: none;
         }
         .gh-wrap .gh-nav li{
             float: left;
             position: relative;
             height: 40px;
         }
         .gh-wrap .gh-nav li a{
             display: block;
             line-height: 40px;
             padding: 0 10px;
             text-decoration: none;
             color: #d5d5d5;
         }
      Copy after login

      1、我先隐藏了二级菜单
      2、设置li为相对定位,目的是有助于二级菜单的定位
      3、a的设置较之前一致

    • 修饰导航

    这就是基本的导航的设置。虽然看着很简单,但是只有自己编写了才会发现之间的一些小小的细节。

    【相关推荐】

    1. 免费css在线视频教程

    2. css在线手册

    3. php.cn独孤九贱(2)-css视频教程

    The above is the detailed content of Web page navigation exercises (2). 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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

How to send web pages to desktop as shortcut in Edge browser? How to send web pages to desktop as shortcut in Edge browser? Mar 14, 2024 pm 05:22 PM

How to send web pages to the desktop as a shortcut in Edge browser? Many of our users want to display frequently used web pages on the desktop as shortcuts for the convenience of directly opening access pages, but they don’t know how to do it. In response to this problem, the editor of this issue will share the solution with the majority of users. , let’s take a look at the content shared in today’s software tutorial. The shortcut method of sending web pages to the desktop in Edge browser: 1. Open the software and click the "..." button on the page. 2. Select "Install this site as an application" in "Application" from the drop-down menu option. 3. Finally, click it in the pop-up window

How to set up web page automatic refresh How to set up web page automatic refresh Oct 26, 2023 am 10:52 AM

To set the automatic refresh of a web page, you can use the HTML "meta" tag, the JavaScript "setTimeout" function, the "setInterval" function or the HTTP "Refresh" header. Detailed introduction: 1. Use the "meta" tag of HTML. In the "<head>" tag of the HTML document, you can use the "meta" tag to set the automatic refresh of the web page; 2. The "setTimeout" function of JavaScript, etc.

What should I do if the images on the webpage cannot be loaded? 6 solutions What should I do if the images on the webpage cannot be loaded? 6 solutions Mar 15, 2024 am 10:30 AM

Some netizens found that when they opened the browser web page, the pictures on the web page could not be loaded for a long time. What happened? I checked that the network is normal, so where is the problem? The editor below will introduce to you six solutions to the problem that web page images cannot be loaded. Web page images cannot be loaded: 1. Internet speed problem The web page cannot display images. It may be because the computer's Internet speed is relatively slow and there are more softwares opened on the computer. And the images we access are relatively large, which may be due to loading timeout. As a result, the picture cannot be displayed. You can turn off the software that consumes more network speed. You can go to the task manager to check. 2. Too many visitors. If the webpage cannot display pictures, it may be because the webpages we visited were visited at the same time.

How to practice typing with Kingsoft Typing Guide - How to practice typing with Kingsoft Typing Guide How to practice typing with Kingsoft Typing Guide - How to practice typing with Kingsoft Typing Guide Mar 18, 2024 pm 04:25 PM

Nowadays, many friends like to use Kingsoft Typing Assistant, but the typing speed seriously affects work efficiency, so I teach you to practice typing speed. So how to use Kingsoft Typing Assistant to practice typing? Today, the editor will give you a tutorial on how to practice typing numbers with Kingsoft Typing Assistant. The following is described, I hope it will be helpful to everyone. First, open the Kingsoft typing software, then click the (Getting Started) button with your mouse, then click the (Number Keys) button in a new window, then click the (Start from Scratch) button below to practice, or click the (Test Mode) button. , just enter numbers for practice. In addition, Kingsoft Typing Assistant has other functions that can help you practice typing better. 1. Select practice mode: On the software interface, you can see that there are different practice modes, such as &quot;New

Possible reasons why the network connection is normal but the browser cannot access the web page Possible reasons why the network connection is normal but the browser cannot access the web page Feb 19, 2024 pm 03:45 PM

The browser cannot open the web page but the network is normal. There are many possible reasons. When this problem occurs, we need to investigate step by step to determine the specific cause and solve the problem. First, determine whether the webpage cannot be opened is limited to a specific browser or whether all browsers cannot open the webpage. If only one browser cannot open the web page, you can try to use other browsers, such as Google Chrome, Firefox, etc., for testing. If other browsers are able to open the page correctly, the problem is most likely with that specific browser, possibly

What to do if the webpage cannot be opened What to do if the webpage cannot be opened Feb 21, 2024 am 10:24 AM

How to solve the problem of web pages not opening With the rapid development of the Internet, people increasingly rely on the Internet to obtain information, communicate and entertain. However, sometimes we encounter the problem that the web page cannot be opened, which brings us a lot of trouble. This article will introduce you to some common methods to help solve the problem of web pages not opening. First, we need to determine why the web page cannot be opened. Possible reasons include network problems, server problems, browser settings problems, etc. Here are some solutions: Check network connection: First, we need

How to open php on the web page How to open php on the web page Mar 22, 2024 pm 03:20 PM

Executing PHP code in a web page requires ensuring that the web server supports PHP and is properly configured. PHP can be opened in three ways: * **Server environment:** Place the PHP file in the server root directory and access it through the browser. * **Integrated Development Environment: **Place PHP files in the specified web root directory and access them through the browser. * **Remote Server:** Access PHP files hosted on a remote server via the URL address provided by the server.

How to use JavaScript to show and hide the fixed navigation bar at the bottom of the web page? How to use JavaScript to show and hide the fixed navigation bar at the bottom of the web page? Oct 19, 2023 am 09:04 AM

How to use JavaScript to show and hide the fixed navigation bar at the bottom of the web page? In web design, a fixed navigation bar is a common design element that can provide users with quick navigation functions to access the website. When the user scrolls the page, the navigation bar can be fixed at the bottom of the page to provide continuous navigation services. This article will introduce how to use JavaScript to achieve this effect and provide specific code examples. To realize the display and hiding effect of the fixed navigation bar at the bottom of the web page, it can be divided into the following steps: Step

See all articles