1. 程式人生 > 實用技巧 >LeetCode 131. 分割回文串 DFS DP

LeetCode 131. 分割回文串 DFS DP

技術標籤:前端知識點csscss3htmlanimation

HTML5與CSS

一、CSS權重

CSS權重指的是樣式的優先順序,有兩條或多條樣式作用於一個元素,權重高的那條樣式對元素起作用,權重相同的,後寫的樣式會覆蓋前面寫的樣式。

1.1 權重的等級

可以把樣式的應用方式分為幾個等級,按照等級來計算權重

1、!important,加在樣式屬性值後,權重值為 10000
2、內聯樣式,如:style=””,權重值為1000
3、ID選擇器,如:#content,權重值為100
4、類,偽類和屬性選擇器,如: content、:hover 權重值為10
5、標籤選擇器和偽元素選擇器,如:div、p、:before 權重值為1

6、通用選擇器(*)、子選擇器(>)、相鄰選擇器(+)、同胞選擇器(~)、權重值為0

1.2 權重的計算例項

1、例項一:

<style type="text/css">
    div{
        color:red !important;
    }        
</style>
......
<div style="color:blue">這是一個div元素</div>
<!-- 
兩條樣式同時作用一個div,上面的樣式權重值為10000+1,下面的行間樣式的權重值為1000,
所以文字的最終顏色為red 
-->

2、例項二:

<style type="text/css">
    #content div.main_content h2{
        color:red;    
    }
    #content .main_content h2{
        color:blue;
    }
</style>
......
<div id="content">
    <div class="main_content">
        <h2>這是一個h2標題</h2>
    </div>
</div>
<!-- 
第一條樣式的權重計算: 100+1+10+1,結果為112;
第二條樣式的權重計算: 100+10+1,結果為111;
h2標題的最終顏色為red
-->

二、CSS3新增選擇器

1、E:nth-child(n):匹配元素型別為E且是父元素的第n個子元素

<style type="text/css">            
    .list div:nth-child(2){
        background-color:red;
    }
</style>
......
<div class="list">
    <h2>1</h2>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
</div>

<!-- 第2個子元素div匹配 -->

2、E:first-child:匹配元素型別為E且是父元素的第一個子元素
3、E:last-child:匹配元素型別為E且是父元素的最後一個子元素
4、E > F E元素下面第一層子集
5、E ~ F E元素後面的兄弟元素
6、E + F 緊挨著的後面的兄弟元素

屬性選擇器:
1、E[attr] 含有attr屬性的元素

<style type="text/css">
    div[data-attr='ok']{
        color:red;
    }
</style>
......
<div data-attr="ok">這是一個div元素</div>

2、E[attr=‘ok’] 含有attr屬性的元素且它的值為“ok”
3、E[attr^=‘ok’] 含有attr屬性的元素且它的值的開頭含有“ok”
4、E[attr$=‘ok’] 含有attr屬性的元素且它的值的結尾含有“ok”
5、E[attr*=‘ok’] 含有attr屬性的元素且它的值中含有“ok”

三、CSS3圓角、rgba

3.1 CSS3圓角

設定某一個角的圓角,比如設定左上角的圓角:
border-top-left-radius:30px 60px;

同時分別設定四個角: border-radius:30px 60px 120px 150px;

設定四個圓角相同:
border-radius:50%;

3.2 rgba(新的顏色值表示法)

1、盒子透明度表示法:

    .box
    {
        opacity:0.1;
        /* 相容IE */
        filter:alpha(opacity=10); 
    }

2、rgba(0,0,0,0.1) 前三個數值表示顏色,第四個數值表示顏色的透明度

四、CSS3 transition動畫

1、transition-property 設定過渡的屬性,比如:width height background-color
2、transition-duration 設定過渡的時間,比如:1s 500ms
3、transition-timing-function 設定過渡的運動方式,常用有 linear(勻速)|ease(緩衝運動)
4、transition-delay 設定動畫的延遲
5、transition: property duration timing-function delay 同時設定四個屬性

五、CSS3 transform變換

1、translate(x,y) 設定盒子位移
2、scale(x,y) 設定盒子縮放
3、rotate(deg) 設定盒子旋轉
4、skew(x-angle,y-angle) 設定盒子斜切
5、perspective 設定透視距離
6、transform-style flat | preserve-3d 設定盒子是否按3d空間顯示
7、translateX、translateY、translateZ 設定三維移動
8、rotateX、rotateY、rotateZ 設定三維旋轉
9、scaleX、scaleY、scaleZ 設定三維縮放
10、tranform-origin 設定變形的中心點
11、backface-visibility 設定盒子背面是否可見

5.1 舉例:(翻面效果)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>翻面</title>
    <style type="text/css">
        .box{
            width:300px;
            height:272px;
            margin:50px auto 0;
            transform-style:preserve-3d;
            position:relative;            
        }
        .box .pic{
            width:300px;
            height:272px;
            position:absolute;
            background-color:cyan;
            left:0;
            top:0;
            transform:perspective(800px) rotateY(0deg);
            backface-visibility:hidden;
            transition:all 500ms ease;
        }
        .box .back_info{
            width:300px;
            height:272px;
            text-align:center;
            line-height:272px;
            background-color:gold;
            position:absolute;
            left:0;
            top:0;
            transform:rotateY(180deg);
            backface-visibility:hidden;
            transition:all 500ms ease;            
        }
        .box:hover .pic{
            transform:perspective(800px) rotateY(180deg);
        }
        .box:hover .back_info{
            transform:perspective(800px) rotateY(0deg);
        }
    </style>
</head>
<body>
    <div class="box">        
        <div class="pic"><img src="images/location_bg.jpg"></div>
        <div class="back_info">背面文字說明</div>
    </div>
</body>
</html>

六、CSS3 animation動畫

1、@keyframes 定義關鍵幀動畫
2、animation-name 動畫名稱
3、animation-duration 動畫時間
4、animation-timing-function 動畫曲線 linear(勻速)|ease(緩衝)|steps(步數)
5、animation-delay 動畫延遲
6、animation-iteration-count 動畫播放次數 n|infinite
7、animation-direction 動畫結束後是否反向還原 normal|alternate
8、animation-play-state 動畫狀態 paused(停止)|running(運動)
9、animation-fill-mode 動畫前後的狀態 none(預設)|forwards(結束時停留在最後一幀)|backwards(開始時停留在定義的開始幀)|both(前後都應用)
10、animation:name duration timing-function delay iteration-count direction;同時設定多個屬性

理解練習:
1、風車動畫
2、loading動畫
在這裡插入圖片描述

3、人物走路動畫

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>走路動畫</title>
    <style type="text/css">        
        .box{
            width:120px;
            height:180px;
            border:1px solid #ccc;            
            margin:50px auto 0;
            position:relative;
            overflow:hidden;            
        }

        .box img{
            display:block;
            width:960px;
            height:182px;
            position: absolute;
            left:0;
            top:0;
            animation:walking 1.0s steps(8) infinite;            
        }
        @keyframes walking{
            from{
                left:0px;
            }

            to{
                left:-960px;
            }
        }
    </style>
</head>
<body>
    <div class="box"><img src="images/walking.png"></div>
</body>
</html>

動畫中使用的圖片如下:

在這裡插入圖片描述

七、CSS3 瀏覽器字首

7.1 瀏覽器樣式字首

為了讓CSS3樣式相容,需要將某些樣式加上瀏覽器字首:

-ms- 相容IE瀏覽器
-moz- 相容firefox
-o- 相容opera
-webkit- 相容chrome 和 safari

比如:

div
{    
    -ms-transform: rotate(30deg);        
    -webkit-transform: rotate(30deg);    
    -o-transform: rotate(30deg);        
    -moz-transform: rotate(30deg);    
    transform: rotate(30deg);
}

7.2 自動新增瀏覽器字首

目前的狀況是,有些CSS3屬性需要加字首,有些不需要加,有些只需要加一部分,這些加字首的工作可以交給外掛來完成,比如安裝: autoprefixer

可以在Sublime text中通過package control 安裝 autoprefixer

1)Autoprefixer在Sublime text中的設定:

1、preferences/key Bindings-User

{ "keys": ["ctrl+alt+x"], "command": "autoprefixer" }

2、Preferences>package setting>AutoPrefixer>Setting-User

{
    "browsers": ["last 7 versions"],
    "cascade": true,
    "remove": true
}

last 7 versions:最新的瀏覽器的7個版本
cascade:縮排美化屬性值
remove:是否去掉不必要的字首

八、HTML5新增標籤

新增語義標籤

1、<header>頁面頭部、頁首
2、<nav> 頁面導航
3、<article> 一篇文章
4、<section> 文章中的章節
5、<aside>側邊欄
6、<footer>頁面底部、頁尾

音訊視訊
1、<audio>
2、<video>

PC端相容h5的新標籤的方法,在頁面中引入以下js檔案:

<script type="text/javascript" src="//cdn.bootcss.com/html5shiv/r29/html5.js"></script>

九、HTML5 新增表單控制元件

新增型別:網址 郵箱 日期 時間 星期 數量 範圍 電話 顏色 搜尋

<label>網址:</label><input type="url" name="" required><br><br> 
<label>郵箱:</label><input type="email" name="" required><br><br> 
<label>日期:</label><input type="date" name=""><br><br> 
<label>時間:</label><input type="time" name=""><br><br> 
<label>星期:</label><input type="week" name=""><br><br> 
<label>數量:</label><input type="number" name=""> <br><br>
<label>範圍:</label><input type="range" name=""><br><br> 
<label>電話:</label><input type="tel" name=""><br><br> 
<label>顏色:</label><input type="color" name=""><br><br> 
<label>搜尋:</label><input type="search" name=""><br><br>

新增常用表單控制元件屬性:
1、placeholder 設定文字框預設提示文字
2、autofocus 自動獲得焦點
3、autocomplete 聯想關鍵詞