CSS样式元素
1? 字體屬性
font-size: 5px; /* 字體大小 */ font-size: 20px/50%/larger /* 字體的大小 */ font-family:'Lucida Bright' /* 字體的類型,如宋體,仿宋 */ font-weight: lighter/bold/border /* 字體的粗細 */ font-style: oblique /* 字體的類型 */ letter-spacing: 50px; /* 標簽內的所有字體所占用的寬度 */? ? font-weight用來設置字體的字重(粗細)。粗細值列表如下:
? 示例
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><meta http-equiv="Refresh" content="2"><title>調整頁</title> <style>.a{font-size: 20px;font-family: 宋體;font-weight: bold;} </style> </head> <body><p class="a">hello-world-a</p><p class="b">hello-world-b</p> </body> </html>示例 View Code?
2? 文本顏色
color:pink; /*字體顏色*/ color: #ff0; /* css的16進制顏色對照 原名為color: #ffff00; */ color: rgb(255,0,0); /* 3原色的調色 */ color: rgba(255,0,0,0.1); /* 這是透明度 */示例
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><meta http-equiv="Refresh" content="2"><title>調整頁</title> <style>p{/*color: #ffff00;*/color: #ff0; /* css的16進制顏色對照 原名為color: #ffff00;*/}a{color: rgb(255,0,0);}h1{color: rgba(255,0,0,0.1);} </style> </head> <body><p>hello-world</p><a>hello1</a><h1>hello2</h1> </body> </html>示例 View Code3? 文字屬性
text-align: center; /* 字體居中 */ text-decoration: underline; /* 文字裝飾,文字下加下劃線 */ text-decoration: none; /* 常用的為去掉a標簽默認的自劃線: */ text-indent: 32px; /* 首行縮進,將段落的第一行縮進 32像素:*/ word-break: break-all; /* 文本內容的排列,先排上還是先排下 */? 示例
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><meta http-equiv="Refresh" content="2"><title>調整頁</title><style>div {word-break: break-all;background-color: aqua;width: 200px;height: 40px;text-align: center;line-height: 20px;}</style> </head> <body> <div>hello-world-aaegaggegaggeagaggg</div> </body> </html>示例 View Code?
4? 背景屬性
background-color: red; /*背景顏色*/ padding: 20px; 背景色從元素中的文本向外少有延伸,只需增加一些內邊距 background-image: url('1.jpg'); /*背景圖片*/ background-attachment:fixed; 可以聲明圖像相對于可視區是固定的(fixed),因此不會受到滾動的影響: background-attachment 屬性的默認值是 scroll p.flower {background-image: url('1.jpg'); 為一個段落應用了一個背景,而不會對文檔的其他部分應用背景 a.radio {background-image: url('1.jpg'); 為行內元素設置背景圖像,為一個鏈接設置了背景圖像 /* 背景重復 repeat(默認):背景圖片平鋪排滿整個網頁 repeat-x:背景圖片只在水平方向上平鋪 repeat-y:背景圖片只在垂直方向上平鋪 no-repeat:背景圖片不平鋪 */ background-repeat: no-repeat; /*鋪滿整個屏幕 (repeat:平鋪滿)*/ background-position: right top; background-position: center center; /* 背景圖片位置 */ background-position: 200px 200px; 簡寫:background:#ffffff url('1.png') no-repeat right top;? background-position ?的位置關鍵字值
? 示例
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><meta http-equiv="Refresh" content="2"><title>調整頁</title> <style>body{width: 200px;height: 400px;background-image: url(1.png);background-repeat: no-repeat;background-position: center center;} </style> </head> <body><p class="a">hello-world-a</p><p class="b">hello-world-b</p> </body> </html>示例 View Code?
5? ? 邊框屬性
(1) 統一設置邊框屬性
border-style: solid; 邊框樣式,實線邊框。 border-color: red; border-width: 20px; 簡寫:border: 30px red solid;? ? 邊框的樣式
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><meta http-equiv="Refresh" content="2"><title>調整頁</title> <style>div{background: rebeccapurple;height: 100px;width: 100px;border: dashed 6px red;} </style> </head> <body><div></div> </body> </html> View Code?
(2) 單獨為某一個邊框設置樣式
#i1 {border-top-style:dotted;border-top-color: red;border-right-style:solid;border-bottom-style:dotted;border-left-style:none; }(3) 圓角邊框
border-radius設置為長或高的一半即可得到一個圓形 用這個屬性能實現圓角邊框的效果。? ? 示例
<!DOCTYPE HTML> <html> <head><meta charset="UTF-8"><meta http-equiv="x-ua-compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1"><title>圓形的頭像示例</title><style>* {margin: 0;padding: 0;background-color: #eeeeee;}.header-img {width: 150px;height: 150px;border: 3px solid white;border-radius: 100%;overflow: hidden;}.header-img>img {max-width: 100%;}</style> </head> <body><div class="header-img"><img src="https://q1mi.github.io/Blog/asset/img/head_img.jpg" alt=""> </div></body> </html> View Code?
6? ? 列表屬性
ul,ol{list-style: decimal-leading-zero;list-style: none; list-style: circle;list-style: upper-alpha;list-style: disc; } <!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><meta http-equiv="Refresh" content="2"><title>調整頁</title> <style>ul{list-style: none;}p{background-color: yellow;display: inline;} </style> </head> <body><ul><li>111</li><li>222</li><li>333</li></ul><p>user</p> </body> </html> View Code?
7? ? ?display屬性:用于控制HTML元素的顯示效果
? ?示例
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><meta http-equiv="Refresh" content="2"><title>調整頁</title> <style>span{background-color: aqua;/*display: block;*/display: none;} </style> </head> <body><span>hello</span> </body> </html>示例 View Code??display:"none"與visibility:hidden的區別
visibility:hidden: 可以隱藏某個元素,但隱藏的元素仍需占用與未隱藏之前一樣的空間。也就是說,該元素雖然被隱藏了,但仍然會影響布局。 display:none: 可以隱藏某個元素,且隱藏的元素不會占用任何空間。也就是說,該元素不但被隱藏了,而且該元素原本占用的空間也會從頁面布局中消失。?
8? ? CSS盒子模型
margin: 用于控制元素與元素之間的距離;margin的最基本用途就是控制元素周圍空間的間隔,從視覺角度上達到相互隔開的目的。 padding: 用于控制內容與邊框之間的距離; Border(邊框): 圍繞在內邊距和內容外的邊框。 Content(內容): 盒子的內容,顯示文本和圖像。? ?如圖
(1)??margin外邊距
.margin-test {margin-top:5px;margin-right:10px;margin-bottom:15px;margin-left:20px; } 推薦簡寫。順序:上右下左 .margin-test {margin: 5px 10px 15px 20px; }常見居中: .mycenter {margin: 0 auto; }使用示例 View Code(2)?padding內填充
.padding-test {padding-top: 5px;padding-right: 10px;padding-bottom: 15px;padding-left: 20px; } 推薦簡寫。順序:上右下左 .padding-test {padding: 5px 10px 15px 20px; }補充padding的常用簡寫方式:提供一個,用于四邊;提供兩個,第一個用于上-下,第二個用于左-右;如果提供三個,第一個用于上,第二個用于左-右,第三個用于下;提供四個參數值,將按上-右-下-左的順序作用于四邊;使用示例 View Code?
9? ? float浮動
? ? ??在 CSS 中,任何元素都可以浮動
浮動元素會生成一個塊級框,而不論它本身是何種元素。 關于浮動的兩個特點:浮動的框可以向左或向右移動,直到它的外邊緣碰到包含框或另一個浮動框的邊框為止。由于浮動框不在文檔的普通流中,所以文檔的普通流中的塊框表現得就像浮動框不存在一樣。 三種取值left:向左浮動right:向右浮動none:默認值,不浮動(1) clear屬性
? ? ?clear屬性規定元素的哪一側不允許其他浮動元素
? ? ?注意:clear屬性只會對自身起作用,而不會影響其他元素。
? 示例
.news {background-color: gray;border: solid 1px black;}.news img {float: left;}.news p {float: right;}.clear {clear: both;}<div class="news"> <img src="news-pic.jpg" /> <p>some text</p> <div class="clear"></div> </div>示例 View Code(2) 父標簽塌陷問題
.clearfix:after {content: "";display: block;clear: both; } View Code(3)?overflow溢出屬性?
overflow(水平和垂直均設置) overflow-x(設置水平方向) overflow-y(設置垂直方向)? 圓頭像示例
<!DOCTYPE HTML> <html> <head><meta charset="UTF-8"><meta http-equiv="x-ua-compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1"><title>圓形的頭像示例</title><style>* {margin: 0;padding: 0;background-color: #eeeeee;}.header-img {width: 150px;height: 150px;border: 3px solid white;border-radius: 100%;overflow: hidden;}.header-img > img {max-width: 100%;}</style> </head> <body><div class="header-img"><img src="https://q1mi.github.io/Blog/asset/img/head_img.jpg" alt=""> </div></body> </html>圓形頭像示例 View Code?
10? ? position定位
static,默認值 無特殊定位,對象遵循正常文檔流。不能當作絕對定位的參照物,并且設置標簽對象的left、top等值是不起作用的的。 屬性:position:relative (相對定位)relative:對象遵循正常文檔流,但將依據top,right,bottom,left等屬性在正常文檔流中偏移位置。而其層疊通過z-index屬性定義。注意:position:relative的一個主要用法:方便絕對定位元素找到參照物屬性:position:absolute(絕對定位)定義:設置為絕對定位的元素框從文檔流完全刪除,并相對于最近的已定位祖先元素定位,如果元素沒有已定位的祖先元素,那么它的位置相對于最初的包含塊(即body元素)。元素原先在正常文檔流中所占的空間會關閉,就好像該元素原來不存在一樣。元素定位后生成一個塊級框,而不論原來它在正常流中生成何種類型的框。重點:如果父級設置了position屬性,例如position:relative;,那么子元素就會以父級的左上角為原始點進行定位。這樣能很好的解決自適應網站的標簽偏離問題,即父級為自適應的,那我子元素就設置position:absolute;父元素設置position:relative;,然后Top、Right、Bottom、Left用百分比寬度表示。另外,對象脫離正常文檔流,使用top,right,bottom,left等屬性進行絕對定位。而其層疊通過z-index屬性定義。屬性:position:fixed在理論上,被設置為fixed的元素會被定位于瀏覽器窗口的一個指定坐標,不論窗口是否滾動,它都會固定在這個位置。fixed:對象脫離正常文檔流,使用top,right,bottom,left等屬性以窗口為參考點進行定位,當出現滾動條時,對象不會隨著滾動。而其層疊通過z-index屬性定義。 注意點: 一個元素若設置了 position:absolute | fixed; 則該元素就不能設置float。這是一個常識性的知識點,因為這是兩個不同的流,一個是浮動流,另一個是“定位流”。但是 relative 卻可以。因為它原本所占的空間仍然占據文檔流。? 返回頂部按鈕示例
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><meta http-equiv="x-ua-compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1"><title>返回頂部示例</title><style>* {margin: 0;}.d1 {height: 1000px;background-color: #eeee;}.scrollTop {background-color: darkgrey;padding: 10px;text-align: center;position: fixed;right: 10px;bottom: 20px;}</style> </head> <body> <div class="d1">111</div> <div class="scrollTop">返回頂部</div> </body> </html>返回頂部按鈕示例 View Code?
11? ??z-index
? ? ? ?設置對象的層疊順序,數值大的會覆蓋在數值小的標簽之上。z-index 僅能在定位元素上奏效
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><meta http-equiv="x-ua-compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1"><title>自定義模態框</title><style>.cover {background-color: rgba(0,0,0,0.65);position: fixed;top: 0;right: 0;bottom: 0;left: 0;z-index: 998;}.modal {background-color: white;position: fixed;width: 600px;height: 400px;left: 50%;top: 50%;margin: -200px 0 0 -300px;z-index: 1000;}</style> </head> <body><div class="cover"></div> <div class="modal"></div> </body> </html>示例 View Code?
12? ??opacity
? ? ? ??用來定義透明效果。取值范圍是0~1,0是完全透明,1是完全不透明。
13? ? 綜合實例
(1)? ?頂部導航
<!DOCTYPE HTML> <html> <head><meta charset="UTF-8"><meta http-equiv="x-ua-compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1"><title>li標簽的float示例</title><style>/*清除瀏覽器默認外邊距和內填充*/* {margin: 0;padding: 0;}a {text-decoration: none; /*去除a標簽默認的下劃線*/}.nav {background-color: black;height: 40px;width: 100%;position: fixed;top: 0;}ul {list-style-type: none; /*刪除列表默認的圓點樣式*/margin: 0; /*刪除列表默認的外邊距*/padding: 0; /*刪除列表默認的內填充*/}/*li元素向左浮動*/li {float: left;}li > a {display: block; /*讓鏈接顯示為塊級標簽*/padding: 0 15px; /*設置左右各15像素的填充*/color: #b0b0b0; /*設置字體顏色*/line-height: 40px; /*設置行高*/}/*鼠標移上去顏色變白*/li > a:hover {color: #fff;}/*清除浮動 解決父級塌陷問題*/.clearfix:after {content: "";display: block;clear: both;}</style> </head> <body> <!-- 頂部導航欄 開始 --> <div class="nav"><ul class="clearfix"><li><a href="">玉米商城</a></li><li><a href="">MIUI</a></li><li><a href="">ioT</a></li><li><a href="">云服務</a></li><li><a href="">水滴</a></li><li><a href="">金融</a></li><li><a href="">優品</a></li></ul> </div> <!-- 頂部導航欄 結束 --> </body> </html>頂部導航菜單 View Code(2)? 博客頁面
html
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>blog示例</title><link rel="stylesheet" href="blog.css"> </head> <body> <div class="left"><div class="head-img"><img src="1.jpg" alt=""></div><p class="blog-title">你的博客</p><p class="blog-info" >這個人很帥,留下了很多到東西</p><div class="blog-link"><ul><li><a href="">關于我</a> </li><li><a href="">微博</a> </li><li><a href="">公眾號</a> </li></ul></div><div class="blog-tag"><ul><li><a href="">JavaScript</a> </li><li><a href="">Python</a> </li><li><a href="">Golang</a> </li></ul></div> </div><div class="right"><div class="article-list"><div class="article"><div class="article-header clearfix" ><p class="article-title">張三</p><span class="article-date">2018-05-25</span></div><div class="article-info">在蒼茫的大海上,狂風卷集這烏云,在烏云和大海直接,海燕像黑色的閃電,高傲的飛翔</div><div class="article-tag"><span>#Python</span><span>#JavaScript</span></div></div><div class="article"><div class="article-header clearfix" ><p class="article-title">張三</p><span class="article-date">2018-05-25</span></div><div class="article-info">在蒼茫的大海上,狂風卷集這烏云,在烏云和大海直接,海燕像黑色的閃電,高傲的飛翔</div><div class="article-tag"><span>#Python</span><span>#JavaScript</span></div></div><div class="article"><div class="article-header clearfix" ><p class="article-title">張三</p><span class="article-date">2018-05-25</span></div><div class="article-info">在蒼茫的大海上,狂風卷集這烏云,在烏云和大海直接,海燕像黑色的閃電,高傲的飛翔</div><div class="article-tag"><span>#Python</span><span>#JavaScript</span></div></div><div class="article"><div class="article-header clearfix" ><p class="article-title">張三</p><span class="article-date">2018-05-25</span></div><div class="article-info">在蒼茫的大海上,狂風卷集這烏云,在烏云和大海直接,海燕像黑色的閃電,高傲的飛翔</div><div class="article-tag"><span>#Python</span><span>#JavaScript</span></div></div><div class="article"><div class="article-header clearfix" ><p class="article-title">張三</p><span class="article-date">2018-05-25</span></div><div class="article-info">在蒼茫的大海上,狂風卷集這烏云,在烏云和大海直接,海燕像黑色的閃電,高傲的飛翔</div><div class="article-tag"><span>#Python</span><span>#JavaScript</span></div></div><div class="article"><div class="article-header clearfix" ><p class="article-title">張三</p><span class="article-date">2018-05-25</span></div><div class="article-info">在蒼茫的大海上,狂風卷集這烏云,在烏云和大海直接,海燕像黑色的閃電,高傲的飛翔</div><div class="article-tag"><span>#Python</span><span>#JavaScript</span></div></div></div> </div></body> </html>blog.html View Codecss
/* 這是blog頁面的css樣式 *//*通用的樣式*/ body {margin: 0;font-size: 14px; }.clearfix:after{content: "";clear: both;display: block; }a {text-decoration: none; }ul {list-style-type: none;padding: 0; }/*左邊樣式*/ .left{width: 20%;background-color: rgb(77,77,77);height: 100%;position: fixed;top: 0;left: 0;color: darkgrey; }.head-img {height: 120px;width: 120px;border: 5px solid white;border-radius: 70px;overflow: hidden;margin: 20px auto;}.head-img>img {max-width:100%; }.blog-title {text-align: center; }.blog-info {font-size: 12px;text-align: center; }.blog-link li, .blog-tag li{text-align: center; }.blog-link a, .blog-tag a{color: darkgrey;font-size: 14px; }.blog-link a:hover, .blog-tag a:hover{color: white;font-size: 14px; }/*右邊樣式*/ .right{width: 80%;float: right;background-color: #eeeeee; }.article-list{padding-left: 15px;width: 80%; }.article {background-color: white;margin-top: 15px;box-shadow: 3px 3px 3px rgba(0,0,0,0.2); }.article-header {border-left: 5px solid red; }.article-title{float: left;font-size: 24px;font-weight: bold;margin: 0; }.article-date{float: right;/*margin: 24px 0;*/ }.article-info{border-bottom: 1px solid grey; }.article *{padding:0 15px 0; }.article-tag{padding: 15px 0; }blog.css View Code?
參考:?https://www.cnblogs.com/linu/p/9441206.html
轉載于:https://www.cnblogs.com/iamspecialone/p/11190874.html
總結
- 上一篇: Entity Framework如何得到
- 下一篇: html购物车内部处理样式,第4期学习班