首頁  >  文章  >  web前端  >  實作CSS圓環的5種方法(小結)

實作CSS圓環的5種方法(小結)

青灯夜游
青灯夜游原創
2018-10-11 15:53:053929瀏覽

這篇文章主要介紹了實現CSS圓環的5種方法(小結),有一定的參考價值,有需要的朋友可以參考一下,希望對你們有幫助。

想到去年面試實習的時候被問到實習圓環的問題,特意寫篇文章總結一下吧!總結了一下大概有5種方法。


 

1. 兩個標籤的巢狀:

<p class="element1">
    <p class="child1"></p>
</p>
.element1{
            width: 200px;
            height: 200px;
            background-color: lightpink;
            border-radius: 50%;
        }
        .child1{
            width: 100px;
            height: 100px;
            border-radius: 50%;
            background-color: #009966;
            position: relative;
            top: 50px;
            left: 50px;
        }

2. 使用偽元素,before /after

<p class="element2"></p>
.element2{
            width: 200px;
            height: 200px;
            background-color: lightpink;
            border-radius: 50%;
        }
        .element2:after{
            content: "";
            display: block;
            width: 100px;
            height: 100px;
            border-radius: 50%;
            background-color: #009966;
            position: relative;
            top: 50px;
            left: 50px;
        }

3. 使用border:

#
<p class="element3"></p>
 .element3{
            width: 100px;
            height: 100px;
            background-color: #009966;
            border-radius: 50%;
            border: 50px solid lightpink ;
        }

4. 使用border-shadow

#
<p class="element4"></p>
.element4{
            width: 100px;
            height: 100px;
            background-color: #009966;
            border-radius: 50%;
            box-shadow: 0 0 0 50px lightpink ;
            margin: auto;
        }
<p class="element5">
  .element5{
            width: 200px;
            height: 200px;
            background-color: #009966;
            border-radius: 50%;
            box-shadow: 0 0 0 50px lightpink inset;
            margin: auto;
        }

5. 使用radial-gradient

<p class="element6"></p>
.element6{
            width: 200px;
            height: 200px;
            border-radius: 50%;
            background: -webkit-radial-gradient( circle closest-side,#009966 50%,lightpink 50%);
        }

如果大家有其他的方法,請告訴我吧,謝謝! ! !

總結:以上就是這篇文章的全部內容,希望能對大家的學習有所幫助。更多相關教學請訪問 CSS影片教學

相關推薦:

php公益培訓影片教學

#CSS線上手冊

div/css圖文教學

以上是實作CSS圓環的5種方法(小結)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn