css3 給頁面加個(gè)半圓形導(dǎo)航條主要利用旋轉(zhuǎn)和傾斜樣式
發(fā)布時(shí)間:2014-02-10 16:05:16 作者:佚名
我要評論

利用了css3的 rolate(旋轉(zhuǎn)) 和 skew (傾斜)樣式給頁面加個(gè)半圓形導(dǎo)航條,具體的實(shí)現(xiàn)示例如下,感興趣的朋友不要錯(cuò)過
主要是利用了css3的 rolate(旋轉(zhuǎn)) 和 skew (傾斜)樣式
先上代碼:
html 很簡單
<body>
<button class="cn-button" id="cn-button">+</button>
<div class="cn-wrapper" id="cn-wrapper">
<ul>
<li><a href="a.html"><i class="fa fa-volume-down"></i></a></li>
<li><a href="#"><i class="fa fa-headphones"></i></a></li>
<li><a href="#"><i class="fa fa-home"></i></a></li>
<li><a href="#"><i class="fa fa-trophy"></i></a></li>
<li><a href="#"><i class="fa fa-exclamation-triangle"></i></a></li>
</ul>
</div>
</body>
這里的i標(biāo)簽 用了一個(gè)第三方庫 http://fortawesome.github.io/Font-Awesome/icons/
接下來是css
先來個(gè)半圓形button
.cn-button {
outline: none;
border: none;
color: #f06060;
text-align: center;
font-size: 1.8em;
padding-bottom: 1em;
height: 3.5em;
width: 3.5em;
background-color: #fff;
position: fixed;
left: 50%;
margin-left: -1.75em;
bottom: -1.75em;
border-radius: 50%;
cursor: pointer;
z-index: 11;
}
主要起作用的是
border-radius: 50%;
可以試一下,如果想把一個(gè)div變成圓形,就用這行代碼,那半圓呢? 你把剩下半個(gè)擋住不就OK了!
我們把 cn-warpper也變成半圓的
.cn-wrapper {
width: 26em;
height: 26em;
position: fixed;
z-index: 10;
bottom: 0;
left: 50%;
margin-left: -200px;
border: 1px solid #7C5089;
-webkit-transition: all .3s ease;
transition: all .3s ease;
border-radius: 50%;
overflow: hidden;
bottom: -13em;
-webkit-transform: scale(0);
}
-webkit-transform: scale(0);
是為了讓它一開始不顯示
接下來是重頭戲了,如何把半圓分成5個(gè)li
首先給li加基本樣式,寬高,讓他們重疊
.cn-wrapper li {
position: absolute;
font-size: 1.5em;
width: 10em;
height: 10em;
overflow: hidden;
-webkit-transform-origin: 100% 100%;
transform-origin: 100% 100%;
background-color: #eee;
-webkit-transition: all 1s ease;
transition: all 1s ease;
color: #aaa;
}
overflow: hidden;
這個(gè)必須有,后面說明!
然后 讓li變斜,為什么變斜?如果都是正方形,要不然怎么夠分呢?
.cn-wrapper li:first-child {
left: 50%;
top: 50%;
margin-top: -1.3em;
margin-left: -10em;
overflow: hidden;
-webkit-transform: rotate(0deg) skew(50deg);
}
變斜的關(guān)鍵
-webkit-transform: rotate(0deg) skew(50deg);
skew(50deg)就是在水平方向傾斜50度(姑且稱之為度),rotate圍繞自己旋轉(zhuǎn)0度 也就是不轉(zhuǎn),第一個(gè)li不用轉(zhuǎn),只用傾斜就可以,后面的li要依次旋轉(zhuǎn)36度,為什么36度? 180/5
然后就是li下的a了
.cn-wrapper li a {
display: block;
font-size: 1.2em;
height: 14.5em;
width: 13.5em;
position: absolute;
bottom: -6.75em;
right: -6.75em;
text-decoration: none;
color: white;
-webkit-transition: background-color .3s ease, -webkit-transform .8s ease;
transition: background-color .3s ease, -webkit-transform .8s ease;
transition: background-color .3s ease, transform .8s ease;
text-align: center;
padding-top: 2em;
padding-right: 20px;
-webkit-transform: skew(-50deg) rotate(-70deg);
}
text-align: center;
padding-top: 2em;
padding-right: 20px;
這些都是為了設(shè)置icon的位置,沒什么要說的
-webkit-transform: skew(-50deg) rotate(-70deg);
為了迎合父節(jié)點(diǎn)li的變斜,所以skew為負(fù)50度,rotate負(fù)70 (這樣也是為了icon能在div中間顯示text-align:center)
接下來你可以把上邊的overflow::hidden去掉試試看,是不是全亂了?這段代碼就是為了抱住其子節(jié)點(diǎn)的樣式,即使子節(jié)點(diǎn)的樣式是亂的,只要不讓它顯示出來就可以了。
OK,接下來就是一些基本的樣式了
全部代碼:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet">
<style type="text/css">
* {
box-sizing: border-box;
margin: 0;
padding: 0;
list-style: none;
position: relative;
}
.cn-wrapper {
width: 26em;
height: 26em;
position: fixed;
z-index: 10;
bottom: 0;
left: 50%;
margin-left: -200px;
border: 1px solid #7C5089;
-webkit-transition: all .3s ease;
transition: all .3s ease;
border-radius: 50%;
overflow: hidden;
bottom: -13em;
-webkit-transform: scale(0);
}
.open {
-webkit-transform: scale(1);
}
.cn-wrapper li {
position: absolute;
font-size: 1.5em;
width: 10em;
height: 10em;
overflow: hidden;
-webkit-transform-origin: 100% 100%;
transform-origin: 100% 100%;
background-color: #eee;
-webkit-transition: all 1s ease;
transition: all 1s ease;
color: #aaa;
}
.cn-button {
outline: none;
border: none;
color: #f06060;
text-align: center;
font-size: 1.8em;
padding-bottom: 1em;
height: 3.5em;
width: 3.5em;
background-color: #fff;
position: fixed;
left: 50%;
margin-left: -1.75em;
bottom: -1.75em;
border-radius: 50%;
cursor: pointer;
z-index: 11;
}
.cn-wrapper li a {
display: block;
font-size: 1.2em;
height: 14.5em;
width: 13.5em;
position: absolute;
bottom: -6.75em;
right: -6.75em;
text-decoration: none;
color: white;
-webkit-transition: background-color .3s ease, -webkit-transform .8s ease;
transition: background-color .3s ease, -webkit-transform .8s ease;
transition: background-color .3s ease, transform .8s ease;
text-align: center;
border-radius: 50%;
padding-top: 2em;
padding-right: 20px;
-webkit-transform: skew(-50deg) rotate(-70deg) ;
}
.cn-wrapper li:first-child {
left: 50%; top: 50%; margin-top: -1.3em; margin-left: -10em; overflow: hidden; -webkit-transform: rotate(0deg) skew(50deg);
}
.cn-wrapper li:nth-child(2) {
left: 50%; top: 50%; margin-top: -1.3em; margin-left: -10em; overflow: hidden; -webkit-transform: rotate(36deg) skew(50deg);
}
.cn-wrapper li:nth-child(3) {
left: 50%; top: 50%; margin-top: -1.3em; margin-left: -10em; overflow: hidden; -webkit-transform: rotate(72deg) skew(50deg);
}
.cn-wrapper li:nth-child(4) {
left: 50%; top: 50%; margin-top: -1.3em; margin-left: -10em; overflow: hidden; -webkit-transform: rotate(108deg) skew(50deg);
}
.cn-wrapper li:nth-child(5) {
left: 50%; top: 50%; margin-top: -1.3em; margin-left: -10em; overflow: hidden; -webkit-transform: rotate(144deg) skew(50deg);
}
.cn-wrapper li:nth-child(even) a {
background-color: #a61414;
background-color: hsla(0, 88%, 65%, 1);
}
.cn-wrapper li:nth-child(odd) a {
background-color: #a11313;
background-color: hsla(0, 88%, 63%, 1);
}
.cn-wrapper li a:hover {
background-color: #a11313;
}
body {
background-color:rgba(0,0,0,0.6);
}
</style>
</head>
<body>
<button class="cn-button" id="cn-button">+</button>
<div class="cn-wrapper" id="cn-wrapper">
<ul>
<li><a id="aaa1" href="a.html"><i class="fa fa-volume-down"></i></a></li>
<li><a href="#"><i class="fa fa-headphones"></i></a></li>
<li><a href="#"><i class="fa fa-home"></i></a></li>
<li><a href="#"><i class="fa fa-trophy"></i></a></li>
<li><a href="#"><i class="fa fa-exclamation-triangle"></i></a></li>
</ul>
</div>
</body>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js">
</script>
<script type="text/javascript">
var button = $("#cn-button");
button.click(function(){
$("#cn-wrapper").toggleClass("open");
if (button.text() === "+") {
button.text("-");
} else {
button.text("+");
}
});
//button.addEventLis
</script>
</html>
先上代碼:
html 很簡單
復(fù)制代碼
代碼如下:<body>
<button class="cn-button" id="cn-button">+</button>
<div class="cn-wrapper" id="cn-wrapper">
<ul>
<li><a href="a.html"><i class="fa fa-volume-down"></i></a></li>
<li><a href="#"><i class="fa fa-headphones"></i></a></li>
<li><a href="#"><i class="fa fa-home"></i></a></li>
<li><a href="#"><i class="fa fa-trophy"></i></a></li>
<li><a href="#"><i class="fa fa-exclamation-triangle"></i></a></li>
</ul>
</div>
</body>
這里的i標(biāo)簽 用了一個(gè)第三方庫 http://fortawesome.github.io/Font-Awesome/icons/
接下來是css
先來個(gè)半圓形button
復(fù)制代碼
代碼如下:.cn-button {
outline: none;
border: none;
color: #f06060;
text-align: center;
font-size: 1.8em;
padding-bottom: 1em;
height: 3.5em;
width: 3.5em;
background-color: #fff;
position: fixed;
left: 50%;
margin-left: -1.75em;
bottom: -1.75em;
border-radius: 50%;
cursor: pointer;
z-index: 11;
}
主要起作用的是
復(fù)制代碼
代碼如下:border-radius: 50%;
可以試一下,如果想把一個(gè)div變成圓形,就用這行代碼,那半圓呢? 你把剩下半個(gè)擋住不就OK了!
我們把 cn-warpper也變成半圓的
復(fù)制代碼
代碼如下:.cn-wrapper {
width: 26em;
height: 26em;
position: fixed;
z-index: 10;
bottom: 0;
left: 50%;
margin-left: -200px;
border: 1px solid #7C5089;
-webkit-transition: all .3s ease;
transition: all .3s ease;
border-radius: 50%;
overflow: hidden;
bottom: -13em;
-webkit-transform: scale(0);
}
復(fù)制代碼
代碼如下:-webkit-transform: scale(0);
是為了讓它一開始不顯示
接下來是重頭戲了,如何把半圓分成5個(gè)li
首先給li加基本樣式,寬高,讓他們重疊
復(fù)制代碼
代碼如下:.cn-wrapper li {
position: absolute;
font-size: 1.5em;
width: 10em;
height: 10em;
overflow: hidden;
-webkit-transform-origin: 100% 100%;
transform-origin: 100% 100%;
background-color: #eee;
-webkit-transition: all 1s ease;
transition: all 1s ease;
color: #aaa;
}
復(fù)制代碼
代碼如下:overflow: hidden;
這個(gè)必須有,后面說明!
然后 讓li變斜,為什么變斜?如果都是正方形,要不然怎么夠分呢?
復(fù)制代碼
代碼如下:.cn-wrapper li:first-child {
left: 50%;
top: 50%;
margin-top: -1.3em;
margin-left: -10em;
overflow: hidden;
-webkit-transform: rotate(0deg) skew(50deg);
}
變斜的關(guān)鍵
復(fù)制代碼
代碼如下:-webkit-transform: rotate(0deg) skew(50deg);
skew(50deg)就是在水平方向傾斜50度(姑且稱之為度),rotate圍繞自己旋轉(zhuǎn)0度 也就是不轉(zhuǎn),第一個(gè)li不用轉(zhuǎn),只用傾斜就可以,后面的li要依次旋轉(zhuǎn)36度,為什么36度? 180/5
然后就是li下的a了
復(fù)制代碼
代碼如下:.cn-wrapper li a {
display: block;
font-size: 1.2em;
height: 14.5em;
width: 13.5em;
position: absolute;
bottom: -6.75em;
right: -6.75em;
text-decoration: none;
color: white;
-webkit-transition: background-color .3s ease, -webkit-transform .8s ease;
transition: background-color .3s ease, -webkit-transform .8s ease;
transition: background-color .3s ease, transform .8s ease;
text-align: center;
padding-top: 2em;
padding-right: 20px;
-webkit-transform: skew(-50deg) rotate(-70deg);
}
復(fù)制代碼
代碼如下:text-align: center;
padding-top: 2em;
padding-right: 20px;
這些都是為了設(shè)置icon的位置,沒什么要說的
復(fù)制代碼
代碼如下:-webkit-transform: skew(-50deg) rotate(-70deg);
為了迎合父節(jié)點(diǎn)li的變斜,所以skew為負(fù)50度,rotate負(fù)70 (這樣也是為了icon能在div中間顯示text-align:center)
接下來你可以把上邊的overflow::hidden去掉試試看,是不是全亂了?這段代碼就是為了抱住其子節(jié)點(diǎn)的樣式,即使子節(jié)點(diǎn)的樣式是亂的,只要不讓它顯示出來就可以了。
OK,接下來就是一些基本的樣式了
全部代碼:
復(fù)制代碼
代碼如下:<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet">
<style type="text/css">
* {
box-sizing: border-box;
margin: 0;
padding: 0;
list-style: none;
position: relative;
}
.cn-wrapper {
width: 26em;
height: 26em;
position: fixed;
z-index: 10;
bottom: 0;
left: 50%;
margin-left: -200px;
border: 1px solid #7C5089;
-webkit-transition: all .3s ease;
transition: all .3s ease;
border-radius: 50%;
overflow: hidden;
bottom: -13em;
-webkit-transform: scale(0);
}
.open {
-webkit-transform: scale(1);
}
.cn-wrapper li {
position: absolute;
font-size: 1.5em;
width: 10em;
height: 10em;
overflow: hidden;
-webkit-transform-origin: 100% 100%;
transform-origin: 100% 100%;
background-color: #eee;
-webkit-transition: all 1s ease;
transition: all 1s ease;
color: #aaa;
}
.cn-button {
outline: none;
border: none;
color: #f06060;
text-align: center;
font-size: 1.8em;
padding-bottom: 1em;
height: 3.5em;
width: 3.5em;
background-color: #fff;
position: fixed;
left: 50%;
margin-left: -1.75em;
bottom: -1.75em;
border-radius: 50%;
cursor: pointer;
z-index: 11;
}
.cn-wrapper li a {
display: block;
font-size: 1.2em;
height: 14.5em;
width: 13.5em;
position: absolute;
bottom: -6.75em;
right: -6.75em;
text-decoration: none;
color: white;
-webkit-transition: background-color .3s ease, -webkit-transform .8s ease;
transition: background-color .3s ease, -webkit-transform .8s ease;
transition: background-color .3s ease, transform .8s ease;
text-align: center;
border-radius: 50%;
padding-top: 2em;
padding-right: 20px;
-webkit-transform: skew(-50deg) rotate(-70deg) ;
}
.cn-wrapper li:first-child {
left: 50%; top: 50%; margin-top: -1.3em; margin-left: -10em; overflow: hidden; -webkit-transform: rotate(0deg) skew(50deg);
}
.cn-wrapper li:nth-child(2) {
left: 50%; top: 50%; margin-top: -1.3em; margin-left: -10em; overflow: hidden; -webkit-transform: rotate(36deg) skew(50deg);
}
.cn-wrapper li:nth-child(3) {
left: 50%; top: 50%; margin-top: -1.3em; margin-left: -10em; overflow: hidden; -webkit-transform: rotate(72deg) skew(50deg);
}
.cn-wrapper li:nth-child(4) {
left: 50%; top: 50%; margin-top: -1.3em; margin-left: -10em; overflow: hidden; -webkit-transform: rotate(108deg) skew(50deg);
}
.cn-wrapper li:nth-child(5) {
left: 50%; top: 50%; margin-top: -1.3em; margin-left: -10em; overflow: hidden; -webkit-transform: rotate(144deg) skew(50deg);
}
.cn-wrapper li:nth-child(even) a {
background-color: #a61414;
background-color: hsla(0, 88%, 65%, 1);
}
.cn-wrapper li:nth-child(odd) a {
background-color: #a11313;
background-color: hsla(0, 88%, 63%, 1);
}
.cn-wrapper li a:hover {
background-color: #a11313;
}
body {
background-color:rgba(0,0,0,0.6);
}
</style>
</head>
<body>
<button class="cn-button" id="cn-button">+</button>
<div class="cn-wrapper" id="cn-wrapper">
<ul>
<li><a id="aaa1" href="a.html"><i class="fa fa-volume-down"></i></a></li>
<li><a href="#"><i class="fa fa-headphones"></i></a></li>
<li><a href="#"><i class="fa fa-home"></i></a></li>
<li><a href="#"><i class="fa fa-trophy"></i></a></li>
<li><a href="#"><i class="fa fa-exclamation-triangle"></i></a></li>
</ul>
</div>
</body>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js">
</script>
<script type="text/javascript">
var button = $("#cn-button");
button.click(function(){
$("#cn-wrapper").toggleClass("open");
if (button.text() === "+") {
button.text("-");
} else {
button.text("+");
}
});
//button.addEventLis
</script>
</html>

相關(guān)文章
jQuery+CSS3制作鼠標(biāo)懸停動畫導(dǎo)航條特效源碼
jQuery+CSS3制作鼠標(biāo)懸停動畫導(dǎo)航條特效源碼是一款基于jQuery跟CSS3制作的鼠標(biāo)懸停導(dǎo)航條動畫效果代碼。本段代碼可以在各個(gè)網(wǎng)頁使用,有需要的朋友可以直接下載使用2017-11-20html5+css3鼠標(biāo)懸停hover超鏈接導(dǎo)航條特效源碼 21種
hover超鏈接導(dǎo)航條特效源碼是一個(gè)利用css3 transition屬性制作的21種不同的鼠標(biāo)懸停效果的代碼。鼠標(biāo)hover或懸停時(shí),會觸發(fā)各種動畫效果2016-03-31css3實(shí)現(xiàn)創(chuàng)意圓點(diǎn)導(dǎo)航條樣式特效代碼
css3實(shí)現(xiàn)創(chuàng)意圓點(diǎn)導(dǎo)航條樣式特效代碼,animation屬性制作簡單的滑動下劃線文字導(dǎo)航條,彩色圓點(diǎn)文字下劃線效果代碼。2020-10-12