css3之圖形繪製

来源:https://www.cnblogs.com/wpshan/archive/2018/08/18/9498171.html
-Advertisement-
Play Games

由於近期的項目中出現了不規則的邊框和圖形, 所以重新溫習一下CSS3的圖形繪製。。。樣式繪製的圖形比圖片的性能要好,體驗更佳,關鍵一點是更加有趣! 以下幾個例子主要是運用了css3中border、bordr-radius、transform、偽元素等屬性來完成的,我們先瞭解下它們的基本原理。 bor ...



由於近期的項目中出現了不規則的邊框和圖形, 所以重新溫習一下CSS3的圖形繪製。。。樣式繪製的圖形比圖片的性能要好,體驗更佳,關鍵一點是更加有趣!

以下幾個例子主要是運用了css3中border、bordr-radius、transform、偽元素等屬性來完成的,我們先瞭解下它們的基本原理。

      border:簡單的來說border語法主要包含(border-width、border-style、border-color)三個屬性。

    • „ border-top(上邊框):border-width border-style border-color
    • „ border-right(右邊框):border-width border-style border-color
    • „ border-bottom(下邊框):border-width border-style border-color
    • „ border-left(左邊框):border-width border-style border-color

     border-radius:border-radius 的語法比我們想像中靈活得多。你可能會驚訝地發現 border-radius 原來是一個簡寫屬性。它所對應的各個展開式屬性:

    • „ border-top-left-radius(左上圓角半徑)
    • „ border-top-right-radius (右上圓角半徑)
    • „ border-bottom-right-radius (右下圓角半徑)
    • „ border-bottom-left-radius(左下圓角半徑)

     border-image:共有三個屬性,分別是圖片(border-image-source)、剪裁位置(border-image-slice)、重覆性(border-image-repeat)。

      圖片:使用URL調用

      剪裁位置:共有1~4個參數,沒有單位(預設是像素),也可以用百分比

    • 第一個參數a:距離上邊相應長度進行裁剪
    • 第二個參數b:距離右邊相應長度進行裁剪
    • 第三個參數c:距離下邊相應長度進行裁剪
    • 第四個參數d:距離左邊相應長度進行裁剪

      重覆性:有三個參數 stretch(預設值),round,repeat

    • 預設值是stretch,拉伸的意思,可以看到上面的效果圖中,“2”是垂直拉伸的,“>”是水平拉伸的,而中間的格子是水平垂直一起拉伸的。
    • round是平鋪
    • repeat是重覆

 

話不多說,來直接看下效果:

1、三角形系列(三角形、倒三角、左三角、右三角、左上三角、右上三角、左下三角、右下三角)

    主要用到的是:寬度高度設置為0, border的各個邊的設置(各個邊的透明或不透明);

 .triangle-up {
			/* 三角形 */
			width: 0;
			height: 0;
			border-left: 50px solid transparent;
    		        border-right: 50px solid transparent;
        	        border-bottom: 100px solid #f00;
		}
		.triangle-down {
			/* 倒三角 */
			width: 0;
			height: 0;
			border-left: 50px solid transparent;
    		        border-right: 50px solid transparent;
        	        border-top: 100px solid #f00;
		}
		.triangle-left {
			/* 左三角 */
			width: 0;
			height: 0;
			border-top: 50px solid transparent;
    		        border-bottom: 50px solid transparent;
        	        border-right: 100px solid #f00;
		}
		.triangle-right {
			/* 右三角 */
			width: 0;
			height: 0;
			border-top: 50px solid transparent;
    		        border-bottom: 50px solid transparent;
        	        border-left: 100px solid #f00;
		}
		.triangle-topleft {
			/* 左上三角 */
			width: 0;
			height: 0;
    		        border-right: 100px solid transparent;
        	        border-top: 100px solid #f00;
		}
		.triangle-topright {
			/* 右上三角 */
			width: 0;
			height: 0;
			border-left: 100px solid transparent;
        	        border-top: 100px solid #f00;
		}
		.triangle-downleft {
			/* 左下三角 */
			width: 0;
			height: 0;
    		        border-right: 100px solid transparent;
        	        border-bottom: 100px solid #f00;
		}
		.triangle-downright {
			/* 右下三角 */
			width: 0;
			height: 0;
			border-left: 100px solid transparent;
        	        border-bottom: 100px solid #f00;
		}

 2、梯形(三角形的變體,設置左右兩條邊相等,並且給它設置一個寬度)

 

       .Trapezium {
                    height: 0;
                    width: 100px;
                    border-bottom: 100px solid #dc2500;
                    border-left: 50px solid transparent;
                    border-right: 50px solid transparent;
                  }

  

 

2、愛心(心形的製作是非常複雜的,可以使用偽元素來製作,分別將偽元素旋轉不同的角度,並修改transform-origin屬性來元素的旋轉中心點)

                .love {
			/* 愛心 */
			position: relative;
		}
		.love:before {
			content: "";
			width: 70px;
			height: 110px;
			background: #f00;
			position: absolute;
			border-top-left-radius: 50%;
			border-top-right-radius: 50%;
			transform: rotate(45deg);
		}
		.love:after {
			content: "";
			width: 70px;
			height: 110px;
			background: #f00;
			position: absolute;
			border-top-left-radius: 50%;
			border-top-right-radius: 50%;
			transform: rotate(-45deg);
			left: -30px;
		}

 3、 食人豆(吃豆人的製作方法是先在一個圓形裡面製作一個透明的三角形)

                .pacman {
			/* 食人豆 */
			width: 0;
		        height: 0;
		        border: 60px solid #f00;
		        border-right: 60px solid transparent;
		        border-radius: 100%;
		}

  

4、對話框(消息提示框可以先製作一個圓角矩形,然後在需要的地方放置一個三角形)

               .alertDialog {
			/* 對話框:一個圓角矩形和一個小三角形 */
			width: 150px;
			height: 100px;
			background: #f00;
			border-radius: 10px;
			position: relative;
		}
		.alertDialog:before {
			content: "";
			width: 0;
			height: 0;
			position: absolute;
		        left: -20px;
		        top: 40px;
			border-top: 10px solid transparent;
		        border-bottom: 10px solid transparent;
		        border-right: 20px solid #f00;	
		}

  5、鑽石(首先畫一個直角梯形,再通過偽類元素在其下方畫一個三角形)

               .diamond {
			/* 鑽石:梯形和三角形組成 */
			width: 50px;
			height: 0;
			position: relative;
			border-bottom: 25px solid #f00;
			border-left: 25px solid transparent;
			border-right: 25px solid transparent;
		}
		.diamond:before {
			content: "";
			width: 0;
			height: 0;
			position: absolute;
		        border-left: 50px solid transparent;
		        border-right: 50px solid transparent;
		        border-top: 70px solid #f00;
		        left: -25px;
		        top: 25px;
		}

  6、五角星(星形的實現方式比較複雜,主要是使用transform屬性來旋轉不同的邊)

                .starFive {
			/* 五角星: */
			width: 0;
			height: 0;
			position: relative;
			border-left: 80px solid transparent;
			border-right: 80px solid transparent;
			border-bottom: 60px solid #f00;
			transform: rotate(35deg);
		}
		.starFive:before {
			content: "";
			position: absolute;
			width: 0;
			height: 0;
			border-left: 80px solid transparent;
			border-right: 80px solid transparent;
			border-bottom: 60px solid #f00;
			transform: rotate(-70deg);
			top: 3px;
			left: -80px;
		}
		.starFive:after {
			content: "";
			position: absolute;
			width: 0;
			height: 0;
			border-bottom: 60px solid #f00;
			border-right: 20px solid transparent;
			border-left: 20px solid transparent;
			transform: rotate(-35deg);
		        top: -40px;
		        left: -49px;
		}

  7、菜單(結合::before和::after兩個偽元素)

   

.btn-hamburger i {
    /* position: relative; */
    display: -moz-inline-stack;
    display: inline-block;
    zoom: 1;
    width: 22px;
    height: 3px;
    color: #fff;
    font: bold .24rem/0.4 Helvetica;
    text-transform: uppercase;
    text-indent: -55px;
    background: #fff;
    transition: all 0.2s ease-out;
}
.btn-hamburger i::before, .btn-hamburger i::after {
    content: '';
    width: 22px;
    height: 3px;
    background: #fff;
    position: absolute;
    left: 0;
    transition: 0.2s;
}
.btn-hamburger i::before {
    top: -7px;
}
.btn-hamburger i::after {
    bottom: -7px;
}

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • redis五大數據類型:string(字元串),hash(哈希,類似java的Map),list(列表),set(集合),zset(有序集合) 1、redis的鍵(key) keys 查詢資料庫中的key值,keys * 查出所有,keys rt* 查出匹配的key exists key 判斷key ...
  • weight詳解 是用來等比例劃分區域的屬性。 案例代碼 為什麼出現2:1的案例呢?three怎麼就不見了呢? 1. 每個寬度為 ,屏幕為1,那麼屏幕就是1 3= 2個 2. 計算方法, ,結果是one占了兩份,two占了一份,three什麼都沒有 ,`padding`詳解 代表是偏移,表示組件離容 ...
  • UI的描述 對於 應用程式中,所有用戶界面元素都是由 和`ViewGroup View ViewGroup View ViewGroup`對象的佈局容器! 為我們提供了 和`ViewGroup`的兩個子類的集合,提供常用的一些輸入控制項(比如按鈕,圖片和文本域等)和各種各樣的佈局模式(比如線程佈局,相 ...
  • 前言 lodash受歡迎的一個原因,是其優異的計算性能。而其性能能有這麼突出的表現,很大部分就來源於其使用的演算法——惰性求值。 本文將講述lodash源碼中,惰性求值的原理和實現。 一、惰性求值的原理分析 惰性求值(Lazy Evaluation),又譯為惰性計算、懶惰求值,也稱為傳需求調用(cal ...
  • 五層網路模型 簡介 互聯網的實現,依托於網路協議。網路協議又分為好幾層,關於如何分層有過很多爭論,比較受人認可的有五層模型、七層模型、四層模型。今天我們就來講講五層網路模型。 從名字就可以看出來,五層網路模型將網路協議分為五層,每層都有對應的一些網路協議。從上到下分別是: 應用層 傳輸層 網路層 數 ...
  • 1 2 3 4 5 6 wangEditor上傳圖片到伺服器 7 8 9 10 11 12 13 14 15 16 119 120 121 ...
  • 使用html+css+js實現彈球游戲 效果圖: 代碼如下,複製即可使用: 如果您有更好的方法或更多的功能,可以和我們大家一起分享哦,如有錯誤,歡迎聯繫我改正,非常感謝!!! ...
  • 1.模態框案例 需求: 打開網頁時有一個普通的按鈕,點擊當前按鈕顯示一個背景圖,中心並彈出一個彈出框,點擊X的時候會關閉當前的模態框 代碼如下: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style t ...
一周排行
    -Advertisement-
    Play Games
  • 前言 本文介紹一款使用 C# 與 WPF 開發的音頻播放器,其界面簡潔大方,操作體驗流暢。該播放器支持多種音頻格式(如 MP4、WMA、OGG、FLAC 等),並具備標記、實時歌詞顯示等功能。 另外,還支持換膚及多語言(中英文)切換。核心音頻處理採用 FFmpeg 組件,獲得了廣泛認可,目前 Git ...
  • OAuth2.0授權驗證-gitee授權碼模式 本文主要介紹如何筆者自己是如何使用gitee提供的OAuth2.0協議完成授權驗證並登錄到自己的系統,完整模式如圖 1、創建應用 打開gitee個人中心->第三方應用->創建應用 創建應用後在我的應用界面,查看已創建應用的Client ID和Clien ...
  • 解決了這個問題:《winForm下,fastReport.net 從.net framework 升級到.net5遇到的錯誤“Operation is not supported on this platform.”》 本文內容轉載自:https://www.fcnsoft.com/Home/Sho ...
  • 國內文章 WPF 從裸 Win 32 的 WM_Pointer 消息獲取觸摸點繪製筆跡 https://www.cnblogs.com/lindexi/p/18390983 本文將告訴大家如何在 WPF 裡面,接收裸 Win 32 的 WM_Pointer 消息,從消息裡面獲取觸摸點信息,使用觸摸點 ...
  • 前言 給大家推薦一個專為新零售快消行業打造了一套高效的進銷存管理系統。 系統不僅具備強大的庫存管理功能,還集成了高性能的輕量級 POS 解決方案,確保頁面載入速度極快,提供良好的用戶體驗。 項目介紹 Dorisoy.POS 是一款基於 .NET 7 和 Angular 4 開發的新零售快消進銷存管理 ...
  • ABP CLI常用的代碼分享 一、確保環境配置正確 安裝.NET CLI: ABP CLI是基於.NET Core或.NET 5/6/7等更高版本構建的,因此首先需要在你的開發環境中安裝.NET CLI。這可以通過訪問Microsoft官網下載並安裝相應版本的.NET SDK來實現。 安裝ABP ...
  • 問題 問題是這樣的:第三方的webapi,需要先調用登陸介面獲取Cookie,訪問其它介面時攜帶Cookie信息。 但使用HttpClient類調用登陸介面,返回的Headers中沒有找到Cookie信息。 分析 首先,使用Postman測試該登陸介面,正常返回Cookie信息,說明是HttpCli ...
  • 國內文章 關於.NET在中國為什麼工資低的分析 https://www.cnblogs.com/thinkingmore/p/18406244 .NET在中國開發者的薪資偏低,主要因市場需求、技術棧選擇和企業文化等因素所致。歷史上,.NET曾因微軟的閉源策略發展受限,儘管後來推出了跨平臺的.NET ...
  • 在WPF開發應用中,動畫不僅可以引起用戶的註意與興趣,而且還使軟體更加便於使用。前面幾篇文章講解了畫筆(Brush),形狀(Shape),幾何圖形(Geometry),變換(Transform)等相關內容,今天繼續講解動畫相關內容和知識點,僅供學習分享使用,如有不足之處,還請指正。 ...
  • 什麼是委托? 委托可以說是把一個方法代入另一個方法執行,相當於指向函數的指針;事件就相當於保存委托的數組; 1.實例化委托的方式: 方式1:通過new創建實例: public delegate void ShowDelegate(); 或者 public delegate string ShowDe ...