Detailed explanation of simple html and css usage

Detailed explanation of simple html and css usage

I will use three days to complete the static page effect of JD.com's homepage, which includes HTML and CSS.

1. Before development, we must first configure the development environment: we need to install development software such as sublime webstorm vscode Hbuilder atom, just choose one. I am using webstorm.

2. Create relevant project folders in the main folder: to put project-related files together for easy management and future maintenance.

Among them: including some files related to the project

Home page or homepage index.html default.html

Css folder css files

Base.css global.css

The Images folder is used to store all the images on the website.

Js file

Audio or video files

3. After that, we need to perform style initialization. Generally, all websites will perform style initialization before development. For example, large websites such as Taobao and JD have their own style initialization css files. like:

XML/HTML CodeCopy content to clipboard
  1. html, body, ul, li, ol, dl, dd, dt, p, h1, h2, h3, h4, h5, h6, form, fieldset, legend, img {
  2. margin: 0;
  3. padding: 0;
  4. }
  5.   
  6. fieldset, img, input, button {
  7. border: none;
  8. padding: 0;
  9. margin: 0;
  10. outline-style: none;
  11. }
  12.   
  13. ul, ol {
  14. list-style: none;
  15. }
  16.   
  17. /*Remove the small black dots in the original style*/
  18. input {
  19. padding-top: 0;
  20. padding-bottom: 0;
  21. font-family: "SimSun", "宋体";
  22. }
  23.   
  24. select, input {
  25. vertical-align: middle;
  26. }
  27.   
  28. /*Input word is displayed in the center*/
  29. select, input, textarea {
  30. font-size: 12px;
  31. margin: 0;
  32. }
  33.   
  34. /**/
  35. textarea {
  36. resize: none;
  37. }
  38.   
  39. /*Prevent dragging*/
  40. img {
  41. border: 0;
  42. vertical-align: middle; /* Remove the default 3-pixel blank space at the bottom of the image*/
  43. }
  44.   
  45. table {
  46. border-collapse: collapse; /*Merge external links*/
  47. }
  48.   
  49. body {
  50. font: 12px/150% Arial, Verdana, "\5b8b\4f53"; /*UnitedCode is written in Songti*/
  51. color: #666; /*150% line spacing based on the current font size*/
  52. background: #fff;
  53. }
  54.   
  55. .clearfix:before, .clearfix:after {
  56. /* Clear floating, the best and most standard way to write it */
  57. content: "";
  58. display: table;
  59. }
  60.   
  61. .clearfix:after {
  62. clear: both;
  63. }
  64.   
  65. .clearfix {
  66. *zoom: 1; /*IE/7/6*/ /*Compatible with IE6*/
  67. }
  68.   
  69. a {
  70. color: #666;
  71. text-decoration: none;
  72. }
  73.   
  74. a:hover {
  75. color: #C81623;
  76. }
  77.   
  78. h1, h2, h3, h4, h5, h6 {
  79. text-decoration: none;
  80. font-weight: normal;
  81. font-size: 100%;
  82. }
  83.   
  84. s, i, em {
  85. font-style: normal;
  86. text-decoration: none;
  87. }
  88.   
  89. .col-red {
  90. color: #C81623 !important;/*JD.com main color*/
  91. }
  92.   
  93. /*Public class*/
  94. .w {
  95. /*Extract the content of the page */
  96. width: 1210px;
  97. margin: 0 auto;
  98. }
  99.   
  100. .fl {
  101. float: left;
  102. }
  103.   
  104. .fr {
  105. float: right;
  106. }
  107.   
  108. .al {
  109. text-align: left;
  110. }
  111.   
  112. .ac {
  113. text-align: center;
  114. }
  115.   
  116. .ar {
  117. text-align: right;
  118. }
  119.   
  120. .hide {
  121. display: none;
  122. }

This makes it easier for developers to initialize the styles of each tag and reuse common classes.

4. Analyze the website structure

There is also a standard or general practice when making a website

The layout order is generally from top to bottom and from left to right.

When writing a page, it is generally considered to use elements of the standard flow, and then use floating or positioning.

Among standard flow elements, width and height are the most stable, so padding is used first, and margin can be used last.

Any tag in our website structure can be regarded as a box model, and the width and height can be set. However, for some elements, the width and height will not work after they are set.

To make the width and height of inline elements work:

1. Convert inline elements to block-level elements or inline-block elements

2. Floating label

3. Positioning and label removal

When laying out inline block elements, there is a default spacing of several pixels between inline block elements. These few pixels of spacing can only be cleared using floats.

There are four types of positioning:

Fixed absolute relative static

Generally, when we analyze the website structure, we can use Firefox to take a screenshot of this webpage and save it:

Then we can use fireworks to extract the width, height, color, etc. of the specific content on the website.

Common shortcut keys for Fw:

I Eyedropper Tool to pick up color

K Slice tool Measure the width of an element

Z Magnifier Tool

V Move

A Pointer Tool

Commonly used composite attributes:

Background

mso-char-indent-count:3.4900;">The reason for floating is that the parent box has no height. The original height is supported by the child elements in the standard flow. However, after the child element floats, it is out of the standard flow, causing the height of the parent element to be 0;

1. Set a height for the parent box

2. Clear: both

3. Overflow: hidden triggers the BFC mode and can also be used to clear floating

4. Pseudo-element or double pseudo-element removal method

XML/HTML CodeCopy content to clipboard
  1. .clearfix:before, .clearfix:after {
  2. /* Clear floating, the best and most standard way to write it */
  3. content: "";
  4. display: table;
  5. }
  6.   
  7. .clearfix:after {
  8. clear: both;
  9. }
  10.   
  11. .clearfix {
  12. *zoom: 1; /*IE/7/6*/ /*Compatible with IE6*/
  13. }
  14.   

(Pseudo-elements are often used to clear floats)

Hierarchy of positioning elements:

If you only give an element absolute positioning without writing a trbl value, it will be displayed in place

Positioned elements (relative and absolute or fixed) have a property or concept of hierarchy. If multiple adjacent elements are positioned at the same position, the latter elements will suppress the former elements by default. If they are both positioned elements, their levels are all 0 by default, but the latter elements will suppress the former elements. If you want the current element to be displayed above the elements behind it, you need to change the hierarchy using z-index.

The value range of z-index is 0-9999999. It is best to use a positive number and try not to use a negative number.

Also note that position:relative will still occupy the position in the standard flow, which will prevent other content from being displayed at its level.

opacity

Opacity: There are compatibility issues, and it not only makes the background color transparent, but also makes the content inside transparent

background: rgba(0,0,0,.3);

Make only the background color transparent, and the content opaque

Hierarchy of adjacent elements

The border flashes when the mouse enters the Taobao webpage

XML/HTML CodeCopy content to clipboard
  1. < style >   
  2. * {
  3. margin: 0;
  4. padding: 0;
  5. }
  6. div {
  7. width: 200px;
  8. height: 500px;
  9. border: 10px solid blue;
  10. float: left;
  11. /*margin-right: 10px;*/
  12. margin-left: -10px;
  13. position: relative; /* Positioned elements will have a hierarchy by default, and the default hierarchy is 0*/
  14. }
  15. div:hover {
  16. border-color: red;
  17. position: relative;
  18. z-index: 1;
  19. }
  20.      </ style >   
  21. </ head >   
  22. < body >   
  23. < div > </ div >   
  24. < div > </ div >   
  25. < div > </ div >   
  26. < div > </ div >   
  27. < div > </ div >   
  28. </ body >   
  29.   

In this way, you can use the hover pseudo-element to control the color and other properties of the border by taking advantage of the hierarchy of adjacent elements to achieve the same effect as Taobao.

The above detailed explanation of the usage of simple html and css is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

Original URL: http://www.cnblogs.com/moyong/archive/2016/07/27/5709491.html

<<:  CSS sample code with search navigation bar

>>:  Generate OpenSSL certificates in Linux environment

Recommend

CSS example code for setting scroll bar style

The CSS implementation code for setting the scrol...

4 solutions to CSS browser compatibility issues

Front-end is a tough job, not only because techno...

Vue basic instructions example graphic explanation

Table of contents 1. v-on directive 1. Basic usag...

In-depth explanation of the global status of WeChat applet

Preface In WeChat applet, you can use globalData ...

Detailed explanation of CSS counter related attributes learning

The CSS counter attribute is supported by almost ...

How to install theano and keras on ubuntu system

Note: The system is Ubuntu 14.04LTS, a 32-bit ope...

Example of customizing the style of the form file selection box

Copy code The code is as follows: <!DOCTYPE ht...

Detailed Analysis of Event Bubbling Mechanism in JavaScript

What is bubbling? There are three stages in DOM e...

Sharing tips on using vue element and nuxt

1. Element time selection submission format conve...

Solve the problem of using less in Vue

1. Install less dependency: npm install less less...

A brief discussion on how to use slots in Vue

How to define and use: Use the slot tag definitio...

MySQL 8.0.13 installation and configuration graphic tutorial

Msyql database installation, for your reference, ...

How to use VUE to call Ali Iconfont library online

Preface Many years ago, I was a newbie on the ser...