. 文字水平居中
將一段文字置于容器的水平中點,只要設置text-align屬性即可:
text-align:center;
2. 容器水平居中
先該容器設置一個明確寬度,然后將margin的水平值設為auto即可。
div#container { width:760px; margin:0 auto; }
3. 文字垂直居中
單行文字的垂直居中,只要將行高與容器高設為相等即可。
比如,容器中有一行數字。
<div id="container">1234567890</div>
然后CSS這樣寫:
div#container {height: 35px; line-height: 35px;}
如果有n行文字,那么將行高設為容器高度的n分之一即可。
4. 容器垂直居中
比如,有一大一小兩個容器,請問如何將小容器垂直居中?
<div id="big"> <div id="small"> </div></div>
首先,將大容器的定位為relative。
div#big{position:relative;height:480px; }
然后,將小容器定位為absolute,再將它的左上角沿y軸下移50%,最后將它margin-top上移本身高度的50%即可。
div#small { position: absolute; top: 50%; height: 240px; margin-top: -120px; }
5. 圖片寬度自適應
如何使得較大的圖片,能夠自動適應小容器的寬度?CSS可以這樣寫:
img {max-width: 100%}
6. 3D按鈕
要使按鈕具有3D效果,只要將它的左上部邊框設為淺色,右下部邊框設為深色即可。
div#button { background: #888; border: 1px solid; border-color: #999 #777 #777 #999; }
7. font屬性快捷寫法
font快捷寫法的格式為:
body { font: font-style font-variant font-weight font-size line-height font-family; }
所以,
body { font-family: Arial, Helvetica, sans-serif; font-size: 13px; font-weight: normal; font-variant: small-caps; font-style: italic; line-height: 150%; }
可以被寫成:
body { font: italic small-caps normal 13px/150% Arial, Helvetica, sans-serif; }
8. link狀態設置順序
link的四種狀態,需要按照下面的前后順序進行設置:
a:link a:visited a:hover a:active
9. CSS優先性
如果同一個容器被多條CSS語句定義,那么哪一個定義優先呢?
基本規則是:
行內樣式 > id樣式 > class樣式 > 標簽名樣式
比如,有一個元素:
<div id="ID" class="CLASS" style="color:black;"></div>
行內樣式是最優先的,然后其他設置的優先性,從低到高依次為:
div < .class < div.class < #id < div#id < #id.class < div#id.class
10. font-size基準
瀏覽器的缺省字體大小是16px,你可以先將基準字體大小設為10px:
body {font-size:62.5%;}
后面統一采用em作為字體單位,2.4em就表示24px。
h1 {font-size: 2.4 em}
11. Text-transform和Font Variant
Text-transform用于將所有字母變成小寫字母、大寫字母或首字母大寫:
p {text-transform: uppercase} p {text-transform: lowercase} p {text-transform: capitalize}
Font Variant用于將字體變成小型的大寫字母(即與小寫字母等高的大寫字母)。
p {font-variant: small-caps}
12. CSS重置
CSS重置用于取消瀏覽器的內置樣式,請參考YUI和Eric Meyer的樣式表。
13. 用圖片充當列表標志
默認情況下,瀏覽器使用一個黑圓圈作為列表標志,可以用圖片取代它:
ul {list-style: none} ul li { background-image: url("path-to-your-image"); background-repeat: none; background-position: 0 0.5em; }
14. 透明
將一個容器設為透明,可以使用下面的代碼:
.element { filter:alpha(opacity=50); -moz-opacity:0.5; -khtml-opacity: 0.5; opacity: 0.5; }
在這四行CSS語句中,第一行是IE專用的,第二行用于Firefox,第三行用于webkit核心的瀏覽器,第四行用于Opera。
15. CSS三角形
如何使用CSS生成一個三角形?
先編寫一個空元素
<div class="triangle"></div>
然后,將它四個邊框中的三個邊框設為透明,剩下一個設為可見,就可以生成三角形效果:
.triangle { border-color: transparent transparent green transparent; border-style: solid; border-width: 0px 300px 300px 300px; height: 0px; width: 0px; }
16. 禁止自動換行
如果你希望文字在一行中顯示完成,不要自動換行,CSS命令如下:
h1 { white-space:nowrap; }
17. 用圖片替換文字
有時我們需要在標題欄中使用圖片,但是又必須保證搜索引擎能夠讀到標題,CSS語句可以這樣寫:
h1 { text-indent:-9999px; background:url("h1-image.jpg") no-repeat; width:200px; height:50px; }
18. 獲得焦點的表單元素
當一個表單元素獲得焦點時,可以將其突出顯示:
input:focus { border: 2px solid green; }
19. !important規則
多條CSS語句互相沖突時,具有!important的語句將覆蓋其他語句。由于IE不支持!important,所以也可以利用它區分不同的瀏覽器。
h1 { color: red !important; color: blue; }
上面這段語句的結果是,其他瀏覽器都顯示紅色標題,只有IE顯示藍色標題。
20. CSS提示框
當鼠標移動到鏈接上方,會自動出現一個提示框。
<a class="tooltip" href="#">鏈接文字 <span>提示文字</span></a>
CSS這樣寫:
a.tooltip {position: relative} a.tooltip span {display:none; padding:5px; width:200px;} a:hover {background:#fff;} /*background-color is a must for IE6*/ a.tooltip:hover span{display:inline; position:absolute;}
21. 各類瀏覽器的專用語句
/* IE6 and below */ * html #uno { color: red } /* IE7 */ *:first-child+html #dos { color: red } /* IE7, FF, Saf, Opera */ html>body #tres { color: red } /* IE8, FF, Saf, Opera (Everything but IE 6,7) */ html>/**/body #cuatro { color: red } /* Opera 9.27 and below, safari 2 */ html:first-child #cinco { color: red } /* Safari 2-3 */ html[xmlns*=""] body:last-child #seis { color: red } /* safari 3+, chrome 1+, opera9+, ff 3.5+ */ body:nth-of-type(1) #siete { color: red } /* safari 3+, chrome 1+, opera9+, ff 3.5+ */ body:first-of-type #ocho { color: red } /* saf3+, chrome1+ */ @media screen and (-webkit-min-device-pixel-ratio:0) { #diez { color: red } } /* iPhone / mobile webkit */ @media screen and (max-device-width: 480px) { #veintiseis { color: red } } /* Safari 2 - 3.1 */ html[xmlns*=""]:root #trece { color: red } /* Safari 2 - 3.1, Opera 9.25 */ *|html[xmlns*=""] #catorce { color: red } /* Everything but IE6-8 */ :root *> #quince { color: red } /* IE7 */ *+html #dieciocho { color: red } /* Firefox only. 1+ */ #veinticuatro, x:-moz-any-link { color: red } /* Firefox 3.0+ */ #veinticinco, x:-moz-any-link, x:default { color: red } /***** Attribute Hacks ******/ /* IE6 */ #once { _color: blue } /* IE6, IE7 */ #doce { *color: blue; /* or #color: blue */ } /* Everything but IE6 */ #diecisiete { color/**/: blue } /* IE6, IE7, IE8 */ #diecinueve { color: blue; } /* IE7, IE8 */ #veinte { color/*\**/: blue; } /* IE6, IE7 -- acts as an !important */ #veintesiete { color: blue !ie; } /* string after ! can be anything */
22. 容器的水平和垂直居中
HTML代碼如下:
<figure class='logo'> <span></span> <img class='photo'/></figure>
CSS代碼如下:
.logo { display: block; text-align: center; display: block; text-align: center; vertical-align: middle; border: 4px solid #dddddd; padding: 4px; height: 74px; width: 74px; } .logo * { display: inline-block; height: 100%; vertical-align: middle; } .logo .photo { height: auto; width: auto; max-width: 100%; max-height: 100%; }
23. CSS陰影
外陰影:
.shadow { -moz-box-shadow: 5px 5px 5px #ccc; -webkit-box-shadow: 5px 5px 5px #ccc; box-shadow: 5px 5px 5px #ccc; }
內陰影:
.shadow { -moz-box-shadow:inset 0 0 10px #000000; -webkit-box-shadow:inset 0 0 10px #000000; box-shadow:inset 0 0 10px #000000; }
24. 取消IE文本框的滾動條
textarea { overflow: auto; }
25. 黑白圖像
這段代碼會讓你的彩色照片顯示為黑白照片,是不是很酷?
img.desaturate { filter: grayscale(100%); -webkit-filter: grayscale(100%); -moz-filter: grayscale(100%); -ms-filter: grayscale(100%); -o-filter: grayscale(100%);}
26. 使用 :not() 在菜單上應用/取消應用邊框
先給每一個菜單項添加邊框
/* add border */.nav li { border-right: 1px solid #666;}
然后再除去最后一個元素
// remove border /.nav li:last-child { border-right: none;}
可以直接使用 :not() 偽類來應用元素:
.nav li:not(:last-child) { border-right: 1px solid #666;}
這樣代碼就干凈,易讀,易于理解了。
當然,如果你的新元素有兄弟元素的話,也可以使用通用的兄弟選擇符(~):
.nav li:first-child ~ li { border-left: 1px solid #666;}
27. 頁面頂部陰影
下面這個簡單的 CSS3 代碼片段可以給網頁加上漂亮的頂部陰影效果:
body:before { content: ""; position: fixed;top: -10px; left: 0; width: 100%;height: 10px; -webkit-box-shadow: 0px 0px 10px rgba(0,0,0,.8); -moz-box-shadow: 0px 0px 10px rgba(0,0,0,.8); box-shadow: 0px 0px 10px rgba(0,0,0,.8); z-index: 100;}
28. 給 body 添加行高
你不需要分別添加 line-height 到每個p,h標記等。只要添加到 body 即可,這樣文本元素就可以很容易地從 body 繼承。
body { line-height: 1;}
29. 所有一切都垂直居中
要將所有元素垂直居中,太簡單了:注意:在IE11中要小心flexbox。
html, body { height: 100%; margin: 0;}body { -webkit-align-items: center; -ms-flex-align: center; align-items: center; display: -webkit-flex; display: flex;}
30. 逗號分隔的列表
讓HTML列表項看上去像一個真正的,用逗號分隔的列表,對最后一個列表項使用 :not() 偽類。
ul > li:not(:last-child)::after { content: ",";}
31. 使用負的 nth-child 選擇項目
在CSS中使用負的 nth-child 選擇項目1到項目n。
li { display: none;}/* select items 1 through 3 and display them */li:nth-child(-n+3) { display: block;}
32. 對圖標使用 SVG
我們沒有理由不對圖標使用SVG,SVG對所有的分辨率類型都具有良好的擴展性,并支持所有瀏覽器都回歸到IE9。這樣可以避開.png、.jpg或.gif文件了。
.logo { background: url("logo.svg");}
33. 優化顯示文本
有時,字體并不能在所有設備上都達到最佳的顯示,所以可以讓設備瀏覽器來幫助你:
html { -moz-osx-font-smoothing: grayscale; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;}
注:請負責任地使用 optimizeLegibility。此外,IE /Edge沒有 text-rendering 支持。
34. 對純 CSS 滑塊使用 max-height
使用 max-height 和溢出隱藏來實現只有CSS的滑塊:
.slider ul { max-height: 0; overlow: hidden;}.slider:hover ul { max-height: 1000px; transition: .3s ease;}
35. 繼承 box-sizing
讓 box-sizing 繼承 html:
html { box-sizing: border-box;}*, *:before, *:after { box-sizing: inherit;}
這樣在插件或杠桿其他行為的其他組件中就能更容易地改變 box-sizing 了。
36. 表格單元格等寬
表格工作起來很麻煩,所以務必盡量使用 table-layout: fixed 來保持單元格的等寬:
.calendar { table-layout: fixed;}
37. 用 Flexbox 擺脫外邊距的各種 hack
當需要用到列分隔符時,通過flexbox的 space-between 屬性,你就可以擺脫nth-,first-,和 last-child 的hack了:
.list { display: flex; justify-content: space-between;}.list .person { flex-basis: 23%;}
現在,列表分隔符就會在均勻間隔的位置出現。
38. 使用屬性選擇器用于空鏈接
當a元素沒有文本值,但 href 屬性有鏈接的時候顯示鏈接:
a[href^="http"]:empty::before { content: attr(href);}
相當方便。
39. 檢測鼠標雙擊
HTML:
<div class="test3"> <span><input type="text" value=" " readonly="true" /> <a >Double click me</a></span></div>
CSS:
.test3 span { position: relative;}.test3 span a { position: relative; z-index: 2;}.test3 span a:hover, .test3 span a:active { z-index: 4;}.test3 span input { background: transparent; border: 0; cursor: pointer; position: absolute; top: -1px; left: 0; width: 101%; /* Hacky */ height: 301%; /* Hacky */ z-index: 3;}.test3 span input:focus { background: transparent; border: 0; z-index: 1;}
40. CSS 寫出三角形
/* create an arrow that points up */div.arrow-up { width:0px; height:0px; border-left:5px solid transparent; /* left arrow slant */ border-right:5px solid transparent; /* right arrow slant */ border-bottom:5px solid #2f2f2f; /* bottom, add background color here */font-size:0px; line-height:0px;}/* create an arrow that points down */div.arrow-down { width:0px; height:0px; border-left:5px solid transparent; border-right:5px solid transparent; border-top:5px solid #2f2f2f;font-size:0px; line-height:0px;}/* create an arrow that points left */div.arrow-left { width:0px; height:0px; border-bottom:5px solid transparent; /* left arrow slant */ border-top:5px solid transparent; /* right arrow slant */ border-right:5px solid #2f2f2f; /* bottom, add background color here */ font-size:0px; line-height:0px;}/* create an arrow that points right */div.arrow-right { width:0px; height:0px; border-bottom:5px solid transparent; /* left arrow slant */ border-top:5px solid transparent; /* right arrow slant */ border-left:5px solid #2f2f2f;/* bottom, add background color here */ font-size:0px; line-height:0px;}
41. CSS3 calc() 的使用
calc() 用法類似于函數,能夠給元素設置動態的值:
/* basic calc */.simpleBlock { width: calc(100% - 100px);}/* calc in calc */.complexBlock { width: calc(100% - 50% / 3); padding: 5px calc(3% - 2px); margin-left: calc(10% + 10px);}
42. 文本漸變
文本漸變效果很流行,使用 CSS3 能夠很簡單就實現:
h2[data-text] { position: relative;}h2[data-text]::after { content: attr(data-text); z-index: 10; color: #e3e3e3; position: absolute; top: 0; left: 0; -webkit-mask-image: -webkit-gradient(linear, left top, left bottom, from(rgba(0,0,0,0)), color-stop(50%, rgba(0,0,0,1)), to(rgba(0,0,0,0)));}
43. 禁用鼠標事件
CSS3 新增的 pointer-events 讓你能夠禁用元素的鼠標事件,例如,一個連接如果設置了下面的樣式就無法點擊了。
.disabled { pointer-events: none; }
44. 模糊文本
簡單但很漂亮的文本模糊效果,簡單又好看!
.blur { color: transparent; text-shadow: 0 0 5px rgba(0,0,0,0.5);}
45.簡單的方法調整圖片大小
.content img {height:auto;width:500px;}
46.CSS陰影
.shadow {-moz-box-shadow: 3px 3px 5px 6px #ccc;-webkit-box-shadow: 3px 3px 5px 6px #ccc;box-shadow: 3px 3px 5px 6px #ccc;}
47.CSS首字放大
p:first-letter {display: block;float: left;margin: 5px 5px 0 0;color: red;font-size: 1.4em;background: #ddd;font-family: Helvetica;}
48.用CSS翻轉圖像
#content img {-moz-transform: scaleX(-1);-o-transform: scaleX(-1);-webkit-transform: scaleX(-1);transform: scaleX(-1);filter: FlipH;-ms-filter: "FlipH";}
49.移除被點鏈接的點框
a {outline: none}或者a {outline: 0}
50.元素透明
.element {filter:alpha(opacity=50);-moz-opacity:0.5;-khtml-opacity: 0.5;opacity: 0.5;}
51.使用CSS顯示鏈接之后的URL
a:after{content:" (" attr(href) ") ";}這會在鏈接錨點后顯示URL。你也可以用字體或其他樣式定義它。
52.為手持設備定制特殊樣式
<link type="text/css" rel="stylesheet" href="handheldstyle.css" media="handheld">
53.用圖片充當列表標志
ul {list-style: none}ul li {background-image: url("path-to-your-image");background-repeat: none;background-position: 0 0.5em;}
54.禁止自動換行
h1 { white-space:nowrap; }
55.獲得焦點的表單元素
input:focus { border: 2px solid green; }
56.user-select 禁止用戶選中文本
div {user-select: none; /* Standard syntax */}
57.清除手機tap事件后element 時候出現的一個高亮
* {-webkit-tap-highlight-color: rgba(0,0,0,0);}
58.增強用戶體驗,使用偽元素實現增大點擊熱區
.btn::befoer{content:"";position:absolute;top:-10px;right:-10px;bottom:-10px;left:-10px;}
59.偽元素實現換行,替代換行標簽
inline-element ::after{content:"A";white-space: pre;}
60.will-change提高頁面滾動、動畫等渲染性能
/* 關鍵字值 */will-change: auto;will-change: scroll-position;will-change: contents;will-change: transform; /* <custom-ident>示例 */will-change: opacity; /* <custom-ident>示例 */will-change: left, top; /* 兩個<animateable-feature>示例 */will-change的使用也要謹慎,遵循最小化影響原則,不要這樣直接寫在默認狀態中,因為will-change會一直掛著:.will-change {will-change: transform;transition: transform 0.3s;}.will-change:hover {transform: scale(1.5);}可以讓父元素hover的時候,聲明will-change,這樣,移出的時候就會自動remove,觸發的范圍基本上是有效元素范圍。.will-change-parent:hover .will-change {will-change: transform;}.will-change {transition: transform 0.3s;}.will-change:hover {transform: scale(1.5);}
61.box-sizing 讓元素的寬度、高度包含border和padding
{box-sizing: border-box;}
62.calc() function, 計算屬性值
div {width: calc(100% - 100px);}例子就是讓寬度為100%減去100px的值
63.css實現不換行、自動換行、強制換行
//不換行white-space:nowrap;//自動換行word-wrap: break-word;word-break: normal;//強制換行word-break:break-all;
64.perspective 透視
這個屬性的存在決定你看到的元素是2d還是3d。一般設置在包裹元素的父類上。.div-box {perspective: 400px;}
65.設置圖像透明度的兩種方式
opcity:0.6;background:rgba(0,0,0,.6);
66.position定位屬性
position屬性指定一個元素(靜態的、相對的、絕對或固定)的定位方法的類型。position的屬性值:absolute:生成絕對定位的元素;fixed:生成絕對定位的元素,相對于瀏覽器窗口進行定位;relative:生成相對定位的元素,相對于其正常位置經行定位。z-index:指定一個元素的堆疊順序。
67.cursor屬性
cursor屬性定義了鼠標指針放在一個元素邊界范圍內時所用的光標形狀。CSS提供的cursor值:pointer :小手指;help:箭頭加問號;wait:轉圈圈;move:移動光標;crosshair:十字光標。通過pointer屬性我們可以偽造超鏈接:<span >pointer</span>
68.隱藏沒有靜音、自動播放的影片
video[autoplay]:not([muted]) {display: none;}
69.Font-Size 基準
/* 假設瀏覽器的默認的大小是 16px , 首先將其設置為10px (font-size:10/16) */body {font-size:10/16;}/* 然后就可以用em做統一字體單位了 2.4em = 24px */h1 {font-size: 2.4 em}
70.透明容器
.element {filter:alpha(opacity=50); /* for ie */-moz-opacity:0.5; /* for ff */-khtml-opacity: 0.5; /* for webkit as chrome */opacity: 0.5; /* for opera */}
使用css3 的 2D變形中的 skew() 傾斜屬性,讓偽元素傾斜而不是li傾斜,是為了讓li的文本正常顯示。
<style>.keith li { list-style: none; position: relative; display: inline-block; padding: 10px 15px; color: #fff; cursor: pointer;}.keith li::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; top: 0; border-radius: 5px; z-index: -1; background: #2175BC; transform: skewX(-25deg);}.keith li:hover::after { background: #39a3f5;}</style><ul class='keith'> <li>首頁</li> <li>筆記</li> <li>問問</li> <li>學習</li> <li>設置</li></ul>
72、梯形導航條
使用css3 3D 變形中的 perspective()、rotateX()、transform-origin。
perspective(): 用于設置用戶和元素3D空間Z平面之間的距離,值越小,用戶與3D空間Z平面距離越近,視覺效果會明顯;反之,值越大,用戶與3D空間Z平面距離越遠,視覺效果越小。
rotateX(): 3D空間上X軸的旋轉
tansform-origin: 指定元素的旋轉中心點位置,可以控制梯形傾斜。值為bottom,不傾斜;值為left,左傾斜;值為right,右傾斜。
<style>.keith li { list-style: none; position: relative; display: inline-block; padding: 20px 15px 5px 15px; margin-left: -10px; color: #fff; cursor: pointer;}.keith li::after { content: ''; position: absolute; top: 0; bottom: 0; left: 0; right: 0; z-index: -1; background: #2175BC; border: 1px solid #fff; border-top-right-radius: 8px; border-top-left-radius: 8px; transform: perspective(0.5em) rotateX(5deg); transform-origin: bottom;}.keith li:hover::after { background: #39a3f5;}</style><ul class='keith'> <li>首頁</li> <li>筆記</li> <li>問問</li> <li>學習</li> <li>設置</li></ul>
以上就是我收集的一些CSS小技巧,希望能幫助到你,如果你感覺有用,也請你分享給身邊的小伙伴。
馬上我們就要進入下一個階段,也就是HTML和CSS實現前端界面的階段了,想必很多小伙伴都想給自己的頁面加點酷炫的特效,今天,我就給大家整理了一些非常酷炫的文字特效來裝點你的頁面!有些是從網絡上找的,有些是自己寫出來的
這里介紹一點寫這些特效時需要用到的屬性,(帶-webkit-開頭的是只有Safari和Chrome等使用webkit或chromium內核的瀏覽器才可以使用)
這個屬性用于設置文本的填充色,與直接設置顏色(color屬性)不同,它可以設置transparent(透明)
這個屬性用于設置文字的描邊,第一個值寫描邊線的寬度,第二個寫描邊線的顏色
文字陰影,這個屬性由四個部分組成:第一個值寫陰影在x軸上的偏移;第二個值是在y軸上的偏移;第三個值是模糊程度(可以寫0~?)值越大,越模糊,為0時不模糊;第四個值是陰影顏色。與box-shadow基本一致
注意:這四個值直接不需要逗號分隔,它們四個作為一個整體參數。同時也可以寫多個參數用逗號隔開來實現更強的效果(下方有多個效果都運用到了這個技巧)
將背景按照設定的參數裁切,一般書寫text(即按照文本的樣式裁切,僅保留文本的部分)然后將文本設為透明(webkit-text-fill-color屬性)就能實現漸變色文字等
下面就是一些字體實例了
.loukong{ /* 設置文字為透明,設置文本描邊*/ background-color: #00c4ff; -webkit-text-fill-color: transparent; -webkit-text-stroke:1px #000; }
.liti{ /* 文字左上設置多層淺色陰影,右下設置多層暗色陰影,文字色同背景色 */ background-color: #d2d500; color: #d2d500; text-shadow: -1px -1px 0px #e6e600,-2px -2px 0px #e6e600, -3px -3px 0px #e6e600,1px 1px 0px #bfbf00,2px 2px 0px #bfbf00,3px 3px 0px #bfbf00; }
.nihong{ /* 深色底色,淺色文字,多層淺色文字陰影,彌散大 */ background-color: darkgray; color: white; text-shadow: 0px 0px 15px #00FFFF,0px 0px 15px #00FFFF,0px 0px 15px #00FFFF; }
英文或者筆畫稀疏的文本比較適合,筆畫多看起來會不太好
.chongdie{ /* 兩層背景,一層與被背景色相同,一層與文字色相同 */ background-color: gray; color: #eee; text-shadow: 5px 5px 0 #666, 7px 7px 0 #eee; }
.huanse{ /* 兩層背景,沒啥技巧 */ background-color: darkgray; color: white; text-shadow: 1px 1px 0px #0000FF,2px 2px 0px #0000FF,-1px -1px 0px #E31B4E,-2px -2px 0px #E31B4E; }
.fangsheng{ /* 要把陰影與大小配合好,一般來說大小都是偏大時采用 */ font-family: "Arial Rounded MT Bold", "Helvetica Rounded", Arial, sans-serif; text-transform: uppercase;/* 全開大寫 */ font-size: 92px; color: #f1ebe5; text-shadow: 0 8px 9px #c4b59d, 0px -2px 1px #fff; font-weight: bold; letter-spacing: -4px; background: linear-gradient(to bottom, #ece4d9 0%,#e9dfd1 100%); }
因為需要用到背景裁切(-webkit-background-clip),所以需要再嵌套一個背景div
.jianbian{ background-color: #009195; } .jianbian-inner{ background: linear-gradient(90deg,#f88,#88f); -webkit-background-clip: text; -webkit-text-fill-color: transparent; /* -webkit-text-stroke: 1px #000000; */ }
以上就是全部內容了,靈活運用css的屬性,就能創造出很多你想得到的和想都想不到的特效,甚至一些連寫腳本都很難實現的特效,所以,努力探索css吧,沖沖沖!
轉自簡書:喬一丁_2020強化班
原文鏈接:https://www.jianshu.com/p/b7fd3cf53924
天分享下如何給圖片加陰影,可以是單張,也可批量處理。
想象有如下一個場景:寫文章的時候,背景色是白色,然后你截了一張圖周圍的邊緣也是白色,那截圖和背景之間就完全融為一體,完全沒有邊界感。如下圖:
如果給圖片加上陰影,文字和圖片之間就有了一層邊界,圖片內容也就更突出。
當然給圖片加陰影的方式也很多。比如word和powerpoint中使用圖片效果選項就可以給圖片加陰影,css來給圖片加陰影顯示效果、mac的窗口截圖可以自帶陰影,或者一些付費軟件WinSnap、Ashampoo Snap等。
我們今天介紹的是一款免費軟件——“ImageMagick”。這是一款強大的圖像處理工具,macos、linux和windows都有相應的版本。連photoshop安裝路徑下都有它的身影。
本文介紹windows下的使用。
首先你需要先去官網下載:
地址:https://imagemagick.org/script/download.php
選擇windows適用的版本。或者你可以直接在
https://wwp.lanzoul.com/icoyF0ep9vrc
密碼:4em8
獲取安裝包。
下載好后直接一路“next”安裝就ok了。不建議你在百度上隨便搜一下,下載一個任意版本的安裝包,互聯網確實是個寶庫,但同時它也是個名副其實的垃圾場。網上很多過時的信息,還需你自己分辨。如果要百度搜的話記得選7.0版本以后的。我就被網上的信息坑過。
4.1安裝時需要注意
在安裝imagemagick的時候,安裝程序會默認將magick.exe添加到環境變量里。安裝程序上默認勾選的選項不用更改。
4.2命令的基本格式
magick convert的基本格式是:
magick convert 源文件 [參數] 處理后的文件
4.3使用實例
打開cmd命令行窗口。輸入:(注:下面這些是一行代碼)
magick convert "要轉換的圖像路徑名稱" ( +clone -background grey -shadow 60x20+0+24 ) +swap -background none -layers merge +repage "轉換后圖像的路徑名稱"
比如你在D盤下的一個文件"D:/1.png",加陰影,加陰影后的文件還在D盤,叫"2.png",應輸入如下命令:
magick convert "D:/1.png" ( +clone -background grey -shadow 60x20+0+24 ) +swap -background none -layers merge +repage "D:/2.png"
演示視頻:
<script src="https://lf3-cdn-tos.bytescm.com/obj/cdn-static-resource/tt_player/tt.player.js?v=20160723"></script>
4.4命令參數簡介
shadow命令官方頁面:
https://legacy.imagemagick.org/Usage/blur/#shadow_offset
這里大家要注意上方命令的幾個參數:一般不用更改,但是你要想嘗試可修改下面幾個參數。
60x20+0+24和grey。
60:代表陰影圖層的不透明度。對圖片影響不大,沒必要改。
20:代表陰影模糊度,20左右就挺好看,你也可以根據自己喜好修改。如果是0,就是一個硬陰影。如下圖圖片中灰色的部分:
+0:代表陰影左右偏移量,0表示不向右偏移,+1向右偏移1個px,-1向左偏移1個px。
+24:代表陰影左右偏移量,0表示不向下偏移,+24向右偏移24個px,-24向左偏移24個px。
grey:代表陰影顏色,你可以更改為navy"海軍藍"等其他顏色。
使用quicker動作"圖片陰影"。它的原理就是使用上面介紹的這個imagemagick命令。所以這個方法使用的前提是先安裝好imagemagick。。
關于quicker的下載及動作的安裝可參考這個視頻:
https://www.bilibili.com/video/BV1Be4y177j4/
把搜索動作的關鍵詞替換為"圖片陰影"即可。
然后這個動作的使用方法:安裝好動作之后,選中需要加陰影的文件,運行動作即可。
本文完。覺得有幫助的話幫忙點個贊吧朋友們~ 拜拜~
*請認真填寫需求信息,我們會在24小時內與您取得聯系。