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

黄舟
黄舟Original
2017-01-22 10:34:091416browse

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{  
    属性名:属性  
}

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

 div.s1{  
    font-size;120px;  
}

(3) id selector

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

(4) Selector grouping

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

(5) Selection Derived

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

Comments in CSS

/*   */

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>

(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} 鼠标离开时

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>

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>

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>

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:
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