font-size font-family color
複製代碼
p:last-child 選取其父元素中的最後一個元素,這個元素必須是p,否則會爲空css
P:first-child 選取其父元素中的第一個元素,這個元素必須是p,否則會爲空 p:only-child 選擇其父級元素中只有一個元素,且這個元素爲phtml
<style> .a{ width:100px; margin:0 auto; background:red; } </style>
<div class="a">123</div>
複製代碼
<!--第一種 在外面加一層div 設置寬度 使用margin:0 auto-->
<div class="content">
<div class="outer">
<div class="left"></div>
</div>
</div>
<style type="text/css"> .content { height: 500px; width: 500px; border: 1px solid red; /*垂直居中*/ display: table-cell; vertical-align: middle; } .outer{ width: 100px; margin:0 auto; } .left { height: 100px; width: 100px; border: 1px dashed blue; float: left; } </style>
<!--第二種-->
<style type="text/css"> .content { height: 500px; width: 500px; border: 1px solid red; /*垂直居中*/ display: table-cell; vertical-align: middle; } .left { height: 100px; width: 100px; border: 1px dashed blue; /*水平居中,但設置浮動後失效 margin: 0 auto;*/ float: left; /*水平居中 相對於父級寬度計算*/ margin-left: 50%; position: relative; left: -50px; } </style>
<div class="content">
<div class="left"></div>
</div>
複製代碼
<style type="text/css"> .content { height: 500px; width: 500px; border: 1px solid red; position: relative; } .absolute { background: black; width: 100px; height: 100px; position: absolute; <!--第一種方式 要知道元素的寬高--> <!-- left:50%;--> <!--top: 50%; --> <!--margin-left: -50px;--> <!--margin-top:-50px; --> <!--第二種方式--> <!--transform: translate(-50%, -50%); --> <!--第三種 當上下左右都爲0時, margin: auto使用這個就自動居中了--> <!--position: absolute; left: 0; top: 0; right: 0; bottom: 0;--> <!--margin: auto; --> } </style>
<div class="content">
<div class="absolute"></div>
</div>
第四種方式使用flex佈局
.content {
display: flex;
justify-content:center;
align-items:center;
}
複製代碼
<div style="border:solid 1px red;">
<!-- 背景 blue 由字體的大小決定 底線和頂線-->
<!-- line-height的高度大於字體的高度 其他的高度會均勻分佈在兩側 垂直居中 -->
<span style="background:blue;color:#fff;font-size:40px;line-height:60px;">
居中xfmsp
</span>
</div>
複製代碼
<style> .c3{ width:0px; /* height: 200px; */ border-bottom:30px solid red; /* border-right:30px solid blue; */ border-left:30px solid transparent; border-right:30px solid transparent; } </style>
<div class="c3">
</div>
複製代碼
white-space:nowrap;
複製代碼
<style> .checkbox{ } .checkbox input{ display: none; } .checkbox input + label{ background:url(./checkbox1.png) left center no-repeat; background-size:20px 20px; padding-left:20px; } .checkbox input:checked + label{ background-image:url(./checkbox2.png); } </style>
<div class="checkbox">
<input type="checkbox" id="handsome"/>
<label for="handsome">我很帥</label>
</div>
複製代碼
<style> div { background: red; width: 100px; height: 100px; } .p2 { /* 偏移相對於文檔流元素自己 不會由於偏移改變原來的計算 */ position: relative; left: 10px; top: -10px; background: blue; z-index: 2; } .p3 { /* 脫離文檔流 他的位置相對於最近的父級absolute或者relative 若是沒有的話 最終會找到body*/ position: absolute; left: 80px; top: 30px; background: green; /* z-index: 1; */ /* 定位爲absolute relative fixed的定元素能夠設置 z-index */ /* 子集不會被遮罩 */ } .p4 { /* 脫離文檔流 可是位置相對於可視區域*/ position: fixed; left: 0; bottom: 10px; } </style>
<div class="p1">
position:static
文檔流
</div>
<div class="p2">
position:relative
</div>
<div class="p3">
position:absolute
<div class="p3-3" style="position:absolute;width:50px;height:50px;background:yellow"></div>
</div>
<div class="p4">
position:fixed;
</div>
<div class="p5">
p5
</div>
複製代碼
absolute
:生成絕對定位的元素,定位原點是離本身這一級元素最近的一級position
設置爲absolute
或者relative
的父元素的左上角爲原點的,若是沒有則爲body
。fixed
(老IE不支持):生成絕對定位的元素,相對於瀏覽器窗口進行定位。relative
:生成相對定位的元素,定位原點是元素自己所在位置。static
:默認值。沒有定位,元素出如今正常的流中(忽略 top, bottom, left, right z-index
聲明)。inherit
:規定從父元素繼承 position
屬性的值。由於瀏覽器的兼容的問題,不一樣瀏覽器有些標籤的默認值是不一樣的,若是沒有CSS初始化每每會出現瀏覽器之間的頁面顯示差別。web
inline
元素間的空白字符(空格換行tab
)渲染成一個空格,也就是咱們上面的代碼<li>
換行後會產生換行字符,而它會變成一個空格,固然空格就佔用一個字符的寬度。<!--方案一-->
<style> * {margin: 0;padding: 0;}/* 去除全部元素默認的內外邊距的值 */ html, body {height: 100%;}/* 默認HTML,body的高度爲0,爲其設置高度以使後面的div能夠用百分比設置高度 */ .header {height: 50%;width: 50%;background-color: rgb(255,2545,167);margin: 0 auto;} .main {height: 50%;width: 100%;} .main .left {float: left;width: 50%;height: 100%;background-color: rgb(204,255,102);} .main .right {float: left;width: 50%;height: 100%;background-color: rgb(189,255,255);} </style>
<div class="header"></div>
<div class="main">
<div class="left"></div>
<div class="right"></div>
</div>
<!--方案二-->
<style> * {margin: 0;padding: 0;}/* 去除全部元素默認的內外邊距的值 */ html, body {height: 100%;}/* 默認HTML,body的高度爲0,爲其設置高度以使後面的div能夠用百分比設置高度 */ .pinzi-flex {position: fixed;left: 0;top: 0;height: 100%;width: 100%;} .header {height: 50%;} .header .div-up {width: 50%;height: 100%;background-color: rgb(255,2545,167);margin: 0 auto;} .main {height: 50%;position: relative;} .main .div-left {position: absolute;left: 0; width: 50%;height: 100%;background-color: rgb(204,255,102);} .main .div-right {position: absolute;right: 0; width: 50%;height: 100%;background-color: rgb(189,255,255);} </style>
<div class="pinzi-flex">
<div class="header">
<div class="div-up"></div>
</div>
<div class="main">
<div class="div-left"></div>
<div class="div-right"></div>
</div>
</div>
<!--本身的方案 使用flex-->
<style> * {margin: 0;padding: 0;} html, body {height: 100%;} .box { width: 100%; height: 100%; } .box_up { width: 100%; height: 50%; display: flex; justify-content: center; } .box1 { width: 50%; background:red; } .box_down { width: 100%; height: 50%; display: flex; } .box2 { width: 50%; background:blue; } .box3 { width: 50%; background:green; } </style>
<div class="box">
<div class="box_up">
<div class="box1"></div>
</div>
<div class="box_down">
<div class="box2"></div>
<div class="box3"></div>
</div>
</div>
複製代碼
display: inline
。-webkit-text-size-adjust: none;
。div margin-left margin-right
不會重合,但相鄰的margin-top margin-bottom
會重合。1.外層
padding
2.透明邊框border:1px solid transparent;
3.絕對定位postion:absolute
4.外層DIV overflow:hidden;
5.內層DIV 加float:left;display:inline;
6.外層DIV有時會用到zoom:1;
算法
cursor
屬性不支持hand
,可是支持pointer
,IE兩個都支持;因此爲了兼容都用pointer
。ul、ol
等列表的縮進時,樣式應寫成:list-style:none;margin:0px;padding:0px;
其中margin
屬性對IE
有效,padding
屬性對FireFox
有效。vertical-align
屬性便可,好比 img{verticle-align:center;}
。display:hidden
是同樣的。table
相關的元素,例如table行
,table group
,table列
,table column group
,它的表現卻跟display: none
同樣,也就是說,它們佔用的空間也會釋放。head
裏添加viewport --- 視口
。em rem vw wh
等單位。media query 珊欄佈局等
@media (max-width: 375px){
html{
font-size:24px;
}
}
@media (max-width: 320px){
html{
font-size:20px;
}
}
@media (max-width: 640px){
.intro{
margin:.3rem auto;
display: block;
}
}
複製代碼
input:-webkit-autofill {
background-color: #FAFFBD;
background-image: none;
color: #000;
}
複製代碼
input:-webkit-autofill {
-webkit-box-shadow: 0 0 0px 1000px white inset;
border: 1px solid #CCC!important;
}
複製代碼
<!-- 對整個表單設置 -->
<form autocomplete="off" method=".." action="..">
<!-- 或對單一元素設置 -->
<input type="text" name="textboxname" autocomplete="off">
複製代碼
float
脫離了文檔流,可是不脫離文本流chrome
overflow:hidden(auto)
, 在父級元素後面加上 ::after{clear:both,dispaly:block}
overflow:hidden;
transition:all 1000ms ease;
oblique
表示傾斜的文字-webkit-overflow-scrolling: touch;
,是由於這行代碼啓用了硬件加速特性,因此滑動很流暢。<style type="text/css"> html, body { height: 100%; padding: 0; margin: 0; } /* margin: 100 100 100 100 上右下左 margin 100 90 100 上100 左右 90 下 100 margin 100 80 上下 100 左右 80 */ /*方案一*/ .outer { height: 100%; padding: 100px 0 0; box-sizing: border-box ; } .A { height: 100px; margin: -100px 0 0; background: #BBE8F2; } .B { height: 100%; background: #D9C666; } /*方案二*/ /* .outer { height: 100%; padding: 100px 0 0; box-sizing: border-box ; position: relative; } .A { height: 100px; background: #BBE8F2; position: absolute; top: 0 ; left: 0 ; width: 100%; } .B { height: 100%; background: #D9C666; } */ /* 方案三 */ /* .outer { height: 100%; position: relative; } .A { height: 100px; background: #BBE8F2; } .B { background: #D9C666; width: 100%; position: absolute; top: 100px ; left: 0 ; bottom: 0; } */ </style>
<div class="outer">
<div class="A"></div>
<div class="B"></div>
</div>
複製代碼
多數顯示器默認頻率是60Hz,即1秒刷新60次,因此理論上最小間隔爲(1/60)*1000ms = 16.7ms
瀏覽器
height
是基於容器的高度margin-top 、margin-bottom
是根據容器的寬度line-height
是根據容器的font-size
從右至左解析CSS選擇器iphone
perspective:500px;
transform-style: preserve-3d;
transform: translate rotate .......
box-shadow: 0 0 0 5px green;
box-sizing:border-box
這種狀況 容器的寬度包含邊框trasition:監控的屬性 動畫的時間 動畫的function
<style> .container{ width: 100px; height: 100px; background: red; animation: run 1s linear; /* 動畫的方向 */ /* animation-direction: reverse; */ /* 動畫能夠停在結束或者開始的狀態 backward */ /* animation-fill-mode: forwards; */ /* 無限循環 或者指定數字即爲循環的次數 */ /* animation-iteration-count: infinite; */ /* 播放狀態 paused 爲中止動畫 */ /* animation-play-state: paused; */ } @keyframes run{ /* from{width: 100px;} */ 0%{width: 100px;} 50%{width: 800px;} 100%{width: 100px;} /* to{width: 100px;} */ } </style>
<div class="container">
</div>
複製代碼
animation-timing-function: steps(1);
<style> .container{ width: 100px; height: 100px; border: 1px solid red; background: url(./animal.png) no-repeat; animation: run 1s infinite; animation-timing-function: steps(1); } @keyframes run{ 0%{background-position: 0 0;} 12.5%{background-position: -100px 0;} 25%{background-position: -200px 0;} 37.5%{background-position: -300px 0;} 50%{background-position: 0 -100px;} 62.5%{background-position: -100px -100px;} 75%{ background-position: -200px -100px;} 87.5%{background-position: -300px -100px;} 100%{background-position: 0 0;} } </style>
<div class="container">
</div>
複製代碼