Analysis of the HTML writing style and reasons of experienced people

Analysis of the HTML writing style and reasons of experienced people

1. Navigation: Unordered List vs. Other Label Elements
miaobao04
The reason to use the most commonly used "unordered list" to write navigation is obvious. It represents a list of links, which in itself is enough reason to choose the list tag. But we need to remove the default styling of the list to make it more meaningful.
Another benefit may be beyond your imagination: you create a list and add a link to it, and use CSS to control and define a series of elements in the list.

 <ul><li><a href="#">Collect and share</a></li></ul>

2. Path (breadcrumbs): p paragraph tag vs list list tag
miaobao

We can discuss this issue together, if you have other better ways please let us know. Personally, I prefer to write the path (breadcrumbs) as follows. (I don't use the >> symbol often, however).

 <p id="breadcrumbs"><a href="#">Home</a> » <a href="#">About Us</a> </p>

The website path (breadcrumbs) has a hierarchical relationship in a certain page. Logically, lists should be nested to show the hierarchical relationship. But what do you think if there is only one item in your list? I personally feel that the web page path (breadcrumbs) should be displayed in one line.

3. Button to Input
I can’t remember the last time I used input type="submit", but I stopped using it a long time ago for two reasons: Why does the button element have to have type="submit"? The button is its own element, which is easy to identify in code and easy to define with CSS (not all older browsers support this element tag attribute). And it also allows us to write other tag elements into it, thus expanding our possibilities for plasticity.

 <button type="submit">Submit Form</button>

4. Message: Ordered list (ol) vs. unordered list (ul)
miaobao02
Lists are really great! There are 3 different types (ordered, unordered, and definition lists), and they all have their own uses. You may be confused about when to use ordered lists (ol) and when to use unordered lists (ul), because it makes sense to use them both. The messages are a bit like the neatly arranged chronological examples in a textbook, with a natural upward order. Each comment message corresponds to a fixed time, so the comment structure should use an ordered list (ol).

 <ol>
	<li>
	<ul>
	<li><img src="path-to-gravatar.gif" alt="Author's name" /></li>
	<li><a href="url-to-authors-homepage.html">Author's name</a></li>

	<li>posted on date-goes-here</li>
	</ul>
	<div>Comment text goes here...</div>
	</li>
</ol>

5. label/input: div to other label elements
miaobao03
What label element is the best choice for embedding the parent structure outside the label/input?

 <label for="contactName">Your Name</label>
<input type="text" name="contactName" id="contactName" />

Using appropriate tag codes could have been discussed before, but now I have chosen to use div to embed label/input, and the label and its associated components are considered as a whole. The div element has a wide range of semantic properties and can be adapted to any situation.

 <div>
	<label for="contactName">Your Name</label>
	<input type="text" name="contactName" id="contactName" />
</div>

Original Chinese text: My 5 HTML writing preferences
My Top 5 HTML Coding Preferences

<<:  How to redirect PC address to mobile address in Vue

>>:  How to solve the problem of blurry small icons on mobile devices

Recommend

Implementation principle and configuration of MySql master-slave replication

Database read-write separation is an essential an...

A quick solution to accidentally delete MySQL data (MySQL Flashback Tool)

Overview Binlog2sql is an open source MySQL Binlo...

Example code for implementing a text marquee with CSS3

Background Here's what happened, Luzhu accide...

Vue improves page response speed through lazy loading

Table of contents Overview What is lazy loading? ...

Nginx+FastDFS to build an image server

Installation Environment Centos Environment Depen...

Problems and solutions encountered when installing mininet on Ubuntu 16.04.4LTS

Mininet Mininet is a lightweight software defined...

Detailed explanation of docker network bidirectional connection

View Docker Network docker network ls [root@maste...

Example explanation of MySQL foreign key constraints

MySQL's foreign key constraint is used to est...

How to handle spaces in CSS

1. Space rules Whitespace within HTML code is usu...

How to reasonably use the redundant fields of the database

privot is the intermediate table of many-to-many ...

Things about installing Homebrew on Mac

Recently, Xiao Ming just bought a new Mac and wan...

Sample code for achieving small triangle border effect with pure CSS3+DIV

The specific code is as follows: The html code is...