Home Web Front-end CSS Tutorial CSS syntax summary

CSS syntax summary

Nov 22, 2016 am 09:41 AM
css

In the process of learning CSS, it is crucial to understand and master the syntax of CSS. Here is a summary of the relevant syntax.

1. How to write CSS:

css code

选择器{
    属性名:属性值 
}
Copy after login

2. Where to write it:

There are three ways, namely: inline style, internal style, and external style.

Inline style

is written directly in the HTML tag, written in the style attribute

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <div style="background:red;width:15px;height:15px;"></div>
</body>
</html>
Copy after login

Internal style

is written in the head tag, placed inside the style tag

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
        .exp{
            height: 150px;
            width: 200px;
            background-color: #123456;
            box-shadow: 0 0 8px #132478;
        }
    </style>
</head>
<body>
    <div></div>
</body>
</html>
Copy after login

External style

Use the link tag in the head Introduce and place in the CSS file

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
    <div></div>
</body>
</html>
Copy after login

css code

.exp{
    height: 30px;
    width: 20px;
    background-color: #123456;
    box-shadow: 0 0 1px #132478;
}
Copy after login

3. Notes:

css code

.exp{
    background: #123444;    /*背景色,注释用此符号*/
    height: 90px;
    width: 80px;    //CSS中的注释不能用此符号,和HTML有所不同
}
Copy after login

Note:

In terms of writing, the browser’s private attributes are placed in the front and the standard attributes are placed in the back. Private attributes need to be prefixed: add -webkit-, add -moz-, add -ms-, add -o-.

4. Attribute value syntax:

CSS syntax summary

5. Combination symbols:

1、空格 数量与顺序必须保持一致

 <&#39;font-size&#39;> <&#39;font-family&#39;>
 合法值:
 12px arial
 不合法值:
 12px   或者 arial 12px
Copy after login

2、&& 数量必须一致,顺序随意

 <length>&&<color>
 合法值:
 green 2px  或者  2em blue
 不合法值:
 blue  或者  5em
Copy after login

3、|| 必须出现一个,顺序无关

 underline||overline||linethrough||blink
 合法值:
 underline  或者  overline underline
Copy after login

4、| 只能出现一个

 <color>|transparent
 合法值:
 #123456  或者  transparent
 不合法值:
 #aabb33 transparent
Copy after login

5、[] 分组作用,作为整体

 bold [thin||<length>]     合法值:
 bold thin  或者  bold 3px
Copy after login

七、数量符号:

1、无

 <length>    只能出现一次
 合法值:
 1px  或者  10em
 不合法值:
 1px 3em 5px
Copy after login

2、+ 可以出现一次或多次

 <color-stop>[,<color-stop>]+
 合法值:
 #fff,red,yellow  或者  blue,red 50%,black
 不合法值:
 #123456
Copy after login

3、? 可出现,也可不出现

 inset?&&<color>
 合法值:
 inset #123445  或  #abcd33
Copy after login

4、{} 基本元素可以出现几次(最少出现几次,最多出现几次)

 <length>{2,4}    最少出现两次,最多出现四次
 合法值:
 1px 3em  或者  1px 3px 5em
 不合法值:
 3px
Copy after login

5、* 可以出现0次,1次或者多次

 <time>[,<time>]*
 合法值:
 1s     出现0次
 1s,5ms    出现1次
Copy after login

6、# 出现1次或多次,中间用”,"隔开

 <time>#    相当于    <time>[,<time>]*
 合法值:
 2s,4s,8s
 不合法值:
 2s 4s
Copy after login

八、@规则语法:

1、@标识符 xxx;

2、@标识符 xxx{}

常用的:

@media 响应式布局
@keyframe 描述动画的中间步骤
@font-face 引入外部字体


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)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks 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)

How to make progress bar with h5 How to make progress bar with h5 Apr 06, 2025 pm 12:09 PM

Create a progress bar using HTML5 or CSS: Create a progress bar container. Set the progress bar width. Create internal elements of the progress bar. Sets the internal element width of the progress bar. Use JavaScript, CSS, or progress bar library to display progress.

How to set h5 table border How to set h5 table border Apr 06, 2025 pm 12:18 PM

In HTML, set H5 table borders through CSS: Introduce a CSS style sheet, style the border using border attributes (including border-width, border-style, and border-color sub-properties), and apply the style to the table elements. In addition, specific border styles can be set, such as border-top, border-right, border-bottom, and border-left.

How to run the h5 project How to run the h5 project Apr 06, 2025 pm 12:21 PM

Running the H5 project requires the following steps: installing necessary tools such as web server, Node.js, development tools, etc. Build a development environment, create project folders, initialize projects, and write code. Start the development server and run the command using the command line. Preview the project in your browser and enter the development server URL. Publish projects, optimize code, deploy projects, and set up web server configuration.

How to make h5 click icon How to make h5 click icon Apr 06, 2025 pm 12:15 PM

The steps to create an H5 click icon include: preparing a square source image in the image editing software. Add interactivity in the H5 editor and set the click event. Create a hotspot that covers the entire icon. Set the action of click events, such as jumping to the page or triggering animation. Export H5 documents as HTML, CSS, and JavaScript files. Deploy the exported files to a website or other platform.

How to make pop-up windows with h5 How to make pop-up windows with h5 Apr 06, 2025 pm 12:12 PM

H5 pop-up window creation steps: 1. Determine the triggering method (click, time, exit, scroll); 2. Design content (title, text, action button); 3. Set style (size, color, font, background); 4. Implement code (HTML, CSS, JavaScript); 5. Test and deployment.

How to solve the h5 compatibility problem How to solve the h5 compatibility problem Apr 06, 2025 pm 12:36 PM

Solutions to H5 compatibility issues include: using responsive design that allows web pages to adjust layouts according to screen size. Use cross-browser testing tools to test compatibility before release. Use Polyfill to provide support for new APIs for older browsers. Follow web standards and use effective code and best practices. Use CSS preprocessors to simplify CSS code and improve readability. Optimize images, reduce web page size and speed up loading. Enable HTTPS to ensure the security of the website.

How to make the h5 drop-down menu How to make the h5 drop-down menu Apr 06, 2025 pm 12:24 PM

The Create H5 drop-down menu includes the following steps: Create a drop-down list, apply a CSS style, add toggle effects, and handle user selections. The specific steps are as follows: Use HTML to create a drop-down list. Use CSS to adjust the appearance of the drop-down menu. Use JavaScript or CSS to achieve the switching effect. Listen to change events to handle user selections.

How to do the h5 progress bar How to do the h5 progress bar Apr 06, 2025 am 11:54 AM

There are two ways to make an H5 progress bar: using HTML progress bar elements and using JavaScript to create a progress bar. The HTML progress bar element method involves creating a progress bar element and setting its maximum and current value, while the JavaScript method includes creating a progress bar container and a function that updates the progress bar.

See all articles