爲此你必須編寫一些javascript代碼。 我已經使用jQuery完成了,所以你必須在你的項目中包含jQuery自由。
https://jsfiddle.net/452LLs8e/2/
更新CSS是: 一個{ 文字修飾:無 } #navigation { 保證金:0汽車; 寬度:100%; 溢出:隱藏; margin-top:20px; 位置:相對; line-height:24px; }
#navigation ul {
width: 900px;
margin: 0 auto;
list-style:None;
}
#navigation li {
display: inline-block;
padding: 0px 50px 0px 20px;
list-style:None;
vertical-align: super;
font-size: 20px;
color: #000;
text-align:center;
}
#navigation li a {
font-size: 9px;
text-transform:uppercase;
letter-spacing:1px;
display:block;
position:relative;
margin-bottom:-8px;
letter-spacing:2px;
color:#000;
}
#navigation li a:after {
content: '';
display: block;
border-bottom: 2px solid;
border-color: inherit;
width: 0;
position: absolute;
left: 0;
-webkit-transition: 0.6s ease;
transition: 0.6s ease;
}
#navigation li a:hover:after {
width: 100%;
}
JavaScript代碼:
var arrColor=['#ff86b1', '#d162ff', '#9cbdff', '#4fff4f'];
var randIdx=parseInt(Math.random()*arrColor.length);
$('#navigation li a').css('border-color',arrColor[randIdx]);
console.log(arrColor[randIdx]);
我能發現這個問題的時候了:即使在您添加標記'javascript',有在你的小提琴中沒有一個。 – usr2564301
你想只爲隨機顏色一次頁面加載,或每次用戶盤旋鏈接? – br3t
@RadLexus:我想申請Javascript,但我一直無法找到合適的腳本。 – jodietbh