目錄
- css 禁用a標簽
- angular2 [ngStyle] [ngClass]的用法
- node 版本更新
- css 超出隱藏
- css width和height 的計算
- css3自適應布局單位vw,vh
- angular 組織默認事件和冒泡
- angular innerHtml
- string startsWith() 方法
- css 透明度設置
內(nèi)容
1. css 禁用a標簽
<style>
a.disabled {
pointer-events: none;
filter: alpha(opacity=50); /*IE濾鏡衩辟,透明度50%*/
-moz-opacity: 0.5; /*Firefox私有,透明度50%*/
opacity: 0.5; /*其他坟比,透明度50%*/
}
</style>
2. angular2 [ngStyle] [ngClass]的用法
1. ngStyle
<div [ngStyle]="{'background-color':'green'}"></<div>
判斷添加
<div [ngStyle]="{'background-color':username === 'zxc' ? 'green' : 'red' }"></<div>
2.ngClass
第一個參數(shù)為類名稱恋拍,第二個參數(shù)為boolean值蠢挡,如果為true就添加第一個參數(shù)的類,
基本用法: ngClass]="{'text-success':true}"
判斷
[ngClass]="{'text-success':username == 'zxc'}"
[ngClass]="{'text-success':index == 0}"
3. node 版本更新問題
win系統(tǒng)下 node只能下載新版本覆蓋舊版本更新
4. css 超出隱藏
單行
overflow:hidden; //超出的文本隱藏
text-overflow:ellipsis; //溢出用省略號顯示
white-space:nowrap; //溢出不換行
多行
overflow: hidden;
text-overflow: ellipsis;
display:-webkit-box; //作為彈性伸縮盒子模型顯示。
-webkit-box-orient:vertical; //設置伸縮盒子的子元素排列方式--從上到下垂直排列
-webkit-line-clamp:2; //顯示的行
5. css width和height 的計算
width:calc(100% - 20px);
width:-webkit-calc(100% - 20px);//chrome
width:-moz-calc(100% - 20px);//firefox
height:calc(80% + 20px);
height:-webkit-calc(80% + 20px);//chrome
height:-moz-calc(80% + 20px);//firefox
特別注意:+或者-兩邊都要用空格隔開MァV们!
6. css3自適應布局單位vw,vh
在PC端咙咽,視口指的是在PC端老玛,指的是瀏覽器的可視區(qū)域;
而在移動端钧敞,它涉及3個視口:Layout Viewport(布局視口)蜡豹,Visual Viewport(視覺視口),Ideal Viewport(理想視口)犁享。
視口單位中的“視口”余素,PC端指的是瀏覽器的可視區(qū)域;移動端指的就是Viewport中的Layout Viewport炊昆。
根據(jù)CSS3規(guī)范,視口單位主要包括以下4個:
1.vw:1vw等于視口寬度的1%威根。
2.vh:1vh等于視口高度的1%凤巨。
3.vmin:選取vw和vh中最小的那個。
4.vmax:選取vw和vh中最大的那個洛搀。
vh and vw:相對于視口的高度和寬度敢茁,而不是父元素的(CSS百分比是相對于包含它的最近的父元素的高度和寬度)。1vh 等于1/100的視口高度留美,1vw 等于1/100的視口寬度彰檬。
比如:瀏覽器高度950px,寬度為1920px, 1 vh = 950px/100 = 9.5 px谎砾,1vw = 1920px/100 =19.2 px逢倍。
vmax相對于視口的寬度或高度中較大的那個。其中最大的那個被均分為100單位的vmax景图。
vmin相對于視口的寬度或高度中較小的那個较雕。其中最小的那個被均分為100單位的vmin。
7. angular 組織默認事件和冒泡
ng-click="ratioTab(3,$event);
阻止冒泡 $event.stopPropagation()
阻止默認行為 $event.preventDefault()
8. angular innerHtml
在頁面展示后臺傳來的html片段時挚币,可以用innerHtml屬性
不過片段中的樣式css會被忽略亮蒋。
可以使用自定義管道實現(xiàn)對展示內(nèi)容的自定義樣式。
import { Pipe, PipeTransform } from "@angular/core";
import { DomSanitizer } from '@angular/platform-browser';
@Pipe({ name: 'safeHtml' })
export class SafeHtmlPipe implements PipeTransform {
constructor(private sanitized: DomSanitizer) { }
transform(value) {
return this.sanitized.bypassSecurityTrustHtml(value);
}
}
htmlStr = `
<h1>innerHtml內(nèi)容</h1>
<h2 style="color: #1b75bb;">樣式自定義</h2>
`
<div [innerHtml]="htmlStr | safeHtml"></div>
9.string startsWith() 方法
查看字符串是否為 "xx" 開頭:
var str = "Hello world, welcome to the Runoob.";
var n = str.startsWith("Hello"); //true
10. css 透明度設置
設置透明度opacity妆毕,其子元素也會繼承
避免使用background:#000慎玖;opacity:0.5,建議使用background:rgba(0,0,0,0.5)