Home Web Front-end H5 Tutorial Xiaoqiang's road to HTML5 mobile development (4) - CSS2 and CSS3

Xiaoqiang's road to HTML5 mobile development (4) - CSS2 and CSS3

Jan 22, 2017 am 10:34 AM

In the previous article, we mentioned that learning HTML5 requires knowledge of CSS. When designing the page, you need to know the layout and structure of the Html5 page. To achieve a very gorgeous and beautiful interface, you need to use CSS. Let's first review the basic usage of CSS2, and then look at the relationship and difference with CSS3.

1. What is css?

Cascading stylesheet (cascading stylesheet) provides expression form for web pages. According to W3C specifications, when designing a web page, the data and structure of the web page should be written in the html file, the appearance of the web page should be written in the css file, and the behavior of the web page should be written in the .js file. The purpose of this is to separate the data, appearance, and behavior of the web page to facilitate code maintenance.

2. CSS selector:

(1) Tag selector (simple selector)

(2) Class selector

.s1{  
    属性名:属性  
}
Copy after login

There is also a class selector with a name, as follows:

 div.s1{  
    font-size;120px;  
}
Copy after login

(3) id selector

#d1{  
    font-size:italic;  
    font-weight:900;  
}
Copy after login

(4) Selector grouping

h1,h2,h3{   //用逗号隔开  
<span style="white-space:pre">  </span>color:bllue;  
    }
Copy after login

(5) Selection Derived

#d2 p{  
span style="white-space:pre">   </span>color:red;  
font-size:300;  
    }
Copy after login

Comments in CSS

/*   */
Copy after login

Priority of style:


External style, write the style in .css
Internal style in the file, write the style in the .html file
Inline style, write the style inside style=" "
When a conflict occurs: external style

Two key attributes in CSS:

(1) display attribute


has three values:
block by block Display the mark as a mark
inline Display the mark as an inline mark

none Do not display

<html>  
    <!--display属性-->  
    <head>  
        <style>  
            #d1{  
                width:200px;  
                height:100px;  
                background-color:red;  
                color:white;  
                font-size:40px;  
                display:inline; <!--改为行内标记-->  
            }  
            #d2{  
                width:200px;  
                height:100px;  
                background-color:blue;  
                color:white;  
                font-size:40px;  
                display:inline; <!--改为行内标记-->  
            }  
        </style>  
    </head>  
    <body>  
        <div id="d1">hello1</div>  
    <!--标记d2会另起一行显示-->  
        <div id="d2">hello2</div>  
    </body>  
</html>
Copy after login

(2) The position attribute
has three values:
static:Default value. The browser will place the tags in the default way (left-right, top-bottom).
Absolute: Offset relative to the parent mark (the mark where it is located).
relative: First place it in the default way, and then offset it.


Commonly used attributes are as follows:

 (1)文本相关的属性  
font-size:30px; //字体大小  
font-style:normal(正常)/italic(斜体)  
font-weight:800; //100-900 (粗细)  
font-family:"宋体"; //字体  
text-align:left/center/right;  //文本水平对齐方式  
line-height:30px;  //行高  一般和容器的高值相同放在中间  
cursor:pointer/wait;   //光标的形状  
    (2)背景相关的属性  
background-color:red;  //背景颜色  
background-color:#88eeff;  //RGB格式颜色设置  
background-color:rgb(100,100,100);  //可以用这种格式输入十进制数的颜色值  
background-image:url(images/t1.jpg);  //背景图片  
background-repeat:no-repeat/repeat-x/repeat-y;   //平铺方式  
background-position:30px 20px; //(水平和垂直)背景位置  
background-attachment:scroll(默认)/fixed;  //依附方式    
也可以同时设置背景的多个特性:  
background:背景颜色 背景图片 平铺方式 依附方式  水平位置 垂直位置;  
    (3)边框  
border-left:1px solid red;  
border-right:2px dotted black;  
border-bottom:  
border-top:  
border:1px solid red;  
    (4)定位  
width:100px;  
height:200px;  
margin  //外边距  
margin-left:20px;  
margin-right:30px;  
margin-top:40px;  
margin-buttom:50px;  
可以简化为:margin:top right bottom left;  
      margin:40 30 50 20;  
padding  //内边距  
padding-left:  
padding-right:  
padding-top:  
padding-buttom:  
可以简化为:padding:top right bottom left;  
内边距会将父标记撑开  
     (5)浮动  
取消标记独占一行的特性  
float:left/right;  //向左,向右浮动  
clear:both;  //清除浮动的影响  
     (6)其他  
list-style-type:none;除掉列表选项的小圆点。  
text-decoreation:underline;    //给文本加下划线  
     (7)连接的伪样式  
a:link{color:red} 没有访问时  
a:visited{color:blue} 鼠标放上时  
a:action{color:green} 鼠标点击时  
a:hover{color:yellow} 鼠标离开时
Copy after login

The above is a basic summary of the css we have learned before. Let’s take a look at the characteristics of css3. Open it first css3 reference manual (download address: http://download.csdn.net/detail/lxq_xsyu/6784027)

First look at border-color setting border

Related attributes: border-top- color,border-right-color,border-bottom-color,border-left-color

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
<meta http-equiv="Content-Language" content="utf-8" />  
<meta name="robots" content="all" />  
<meta name="author" content="Tencent-ISRD" />  
<meta name="Copyright" content="Tencent" />  
<title>Border-color</title>  
<style>  
    div{  
        border: 8px solid #000;  
        -moz-border-bottom-colors: #555 #666 #777 #888 #999 #aaa #bbb #ccc;  
        -moz-border-top-colors: #555 #666 #777 #888 #999 #aaa #bbb #ccc;  
        -moz-border-left-colors: #555 #666 #777 #888 #999 #aaa #bbb #ccc;  
        -moz-border-right-colors: #555 #666 #777 #888 #999 #aaa #bbb #ccc;  
        padding: 5px 5px 5px 15px;  
    }  
</style>  
</head>  
<body>  
<div>在Firefox浏览器里能看到边框颜色渐变效果</div>  
</body>  
</html>
Copy after login

This setting border is only supported on the Firefox browser, and the running effect

Xiaoqiangs road to HTML5 mobile development (4) - CSS2 and CSS3

You can see from the css3.0 reference book that css3 adds a lot of style attributes. We can refer to this manual to create a more gorgeous interface effect than css2. If we cooperate with js, we can also realize page animation production.

Let’s take a look at creating a rounded corner effect for interface elements

In order to achieve this effect in css2, we need to create two pictures. The code is as follows:

<html>  
    <head>  
        <style type="text/css">  
            a{  
                display:block;  
                height:40px;  
                float:left;  
                font-size:1.2em;  
                padding-right:0.8em;  
                background:url(images/headerRight.png) no-repeat scroll top right;  
            }  
              
            a span{  
                background:url(images/headerLeft.png) no-repeat;  
                display:block;  
                line-height:40px;  
                padding-left:0.8em;  
            }  
        </style>  
    </head>  
    <body>  
        <a href="#"><span>Box Title</span></a>  
    </body>  
</html>
Copy after login

Although the above method solves the problem, it adds a redundant tag. Let’s see how to solve it using css3:

<html>  
    <head>  
        <style type="text/css">  
            a{  
                float:left;  
                height:40px;  
                line-height:40px;  
                padding-left:0.8em;  
                padding-right:0.8em;  
                border-top-left-radius:8px;  
                border-top-right-radius:8px;  
                background-image:url(image/headerTiny.png);  
                backgrount-repeat:repeat-x;  
            }  
        </style>  
    </head>  
    <body>  
        <a href="#"><span>Box Title</span></a>  
    </body>  
</html>
Copy after login

Above It's Xiaoqiang's HTML5 mobile development road (4) - the content of CSS2 and CSS3. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!



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)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

See all articles