


CSS structural pseudo-class selector—nth-of-type implements custom navigation menu case analysis (code example)
Goal of this article:
1. Master the usage of nth-of-type, a structural pseudo-class selector in CSS.
Question:
1. Implement the following customization To define a navigation menu and use pure DIV CSS, you must use the structural pseudo-class selector—nth-of-type
Additional notes:
1, The navigation width is 800px, the height is 90px, and the display is centered
2. The width and height of the snowflake background image are 50px, and the size of the wine bottle image is also the same
Now let’s do the specific operation
1. Prepare materials: Combined with the target effect, we can make a picture of a wine bottle. The background is transparent. In this way, the background color changes, and the transparent part inside it can also change accordingly. There are also two snowflakes on the left and right, which are also the required materials.
2. Create index.html, write the architecture, how to analyze the architecture
Idea analysis:
1. The target navigation is divided into 6 sub-items, so we can use the commonly used li to implement it. The li is arranged horizontally, so it definitely needs to be floated, so we can clear the float of the last li, and it will still work if it reaches ul Effectively wraps all the floating li
2, 1, 3, 5 navigation background is blue, 2, 4, 6 navigation background is yellow, so the colors of li are regular. Change, so at this time we can use nth-of-type
3. Each navigation has two parts, the upper part is a picture, and the lower part is text
Okay, first According to the analysis, write a good idea and ignore the implementation of css for the time being
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
3. Write the style, create a css folder, create a new index.css in it, how to write the style inside, the following is the analysis idea
Idea analysis:
.container *Public style
1. After writing so many cases, this step is basically indispensable, and it is also to reduce code redundancy. , so here we can define the public style
So add the following code to index.css:
1 2 3 4 |
|
.container outer container
1. According to the instructions, The width is 600, the height is 90, the left and right padding intervals are 100, the background color is earthy, with rounded corners, and it must be centered. There are multiple background images. The first background image is horizontally on the left, the second background image is horizontally on the right, and both vertically It is centered, and the background image size is 50px
So add the following code to index.css:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
li Column
1. There is no default black point, so list-style :none, horizontal arrangement, so float:left, width is the same, so width=600/6=100px, font is centered text-align: center;
So add the following code to index.css:
1 2 3 4 5 6 |
|
imgimage
1. According to the requirements, the width and height are both 50 and must be centered, so the width and height of the image inside are exactly equal to the size of the image container, so the width is 100% and the height is 100%. 100%
So add the following code to index.css:
1 2 3 4 5 6 7 8 9 10 |
|
clear clear floating column
1. Because the purpose of this column is to clear floating column
So add the following code to index.css:
1 2 3 4 5 6 |
|
title text
1. There is a padding distance between the top and bottom, so add the following code to index.css:
1 2 3 |
|
li Separate settings:
1, 1, 3, 5 navigation background is blue, 2, 4, 6 navigation background is yellow, so the background of odd-numbered columns is blue, and the background of even-numbered columns is yellow, exactly nth -of-type can bring expressions, so add the following code to index.css:
1 2 3 4 5 6 7 |
|
So far, the index.css code is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
Then introduce index.css into index. The final running effect of
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
in html is as follows:
Summary:
1. Learned the structural pseudo-class selector—nth- Of-type usage, the difficulty here also lies in expressions, so you need to spend more patience to summarize the rules when writing code
The above is the detailed content of CSS structural pseudo-class selector—nth-of-type implements custom navigation menu case analysis (code example). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

Answer: You can use the date picker component of Bootstrap to view dates in the page. Steps: Introduce the Bootstrap framework. Create a date selector input box in HTML. Bootstrap will automatically add styles to the selector. Use JavaScript to get the selected date.

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

To verify dates in Bootstrap, follow these steps: Introduce the required scripts and styles; initialize the date selector component; set the data-bv-date attribute to enable verification; configure verification rules (such as date formats, error messages, etc.); integrate the Bootstrap verification framework and automatically verify date input when form is submitted.

Bootstrap provides a simple guide to setting up navigation bars: Introducing the Bootstrap library to create navigation bar containers Add brand identity Create navigation links Add other elements (optional) Adjust styles (optional)
