這樣寫(xiě)吧:

專(zhuān)注于為中小企業(yè)提供網(wǎng)站設(shè)計(jì)制作、成都做網(wǎng)站服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)鄰水免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了成百上千企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過(guò)網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
div class="meter"
span style="width: 25%"/span
/div
.meter {
height: 20px; /* Can be anything */
position: relative;
background: #555;
-moz-border-radius: 25px;
-webkit-border-radius: 25px;
border-radius: 25px;
padding: 10px;
box-shadow: inset 0 -1px 1px rgba(255,255,255,0.3);
}
.meter span {
display: block;
height: 100%;
border-top-right-radius: 8px;
border-bottom-right-radius: 8px;
border-top-left-radius: 20px;
border-bottom-left-radius: 20px;
background-color: rgb(43,194,83);
background-image: linear-gradient(
center bottom,
rgb(43,194,83) 37%,
rgb(84,240,84) 69%
);
box-shadow:
inset 0 2px 9px rgba(255,255,255,0.3),
inset 0 -2px 6px rgba(0,0,0,0.4);
position: relative;
overflow: hidden;
}
.orange span {
background-color: #f1a165;
background-image: linear-gradient(to bottom, #f1a165, #f36d0a);
}
.red span {
background-color: #f0a3a3;
background-image: linear-gradient(to bottom, #f0a3a3, #f42323);
}
.meter span:after {
content: "";
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
background-image: linear-gradient(
-45deg,
rgba(255, 255, 255, .2) 25%,
transparent 25%,
transparent 50%,
rgba(255, 255, 255, .2) 50%,
rgba(255, 255, 255, .2) 75%,
transparent 75%,
transparent
);
z-index: 1;
background-size: 50px 50px;
animation: move 2s linear infinite;
border-top-right-radius: 8px;
border-bottom-right-radius: 8px;
border-top-left-radius: 20px;
border-bottom-left-radius: 20px;
overflow: hidden;
}
body
div style=" width:50px; height:50px; background-color:#F00; border-radius:25px;"
span style="height:50px; line-height:50px; display:block; color:#FFF; text-align:center"4/span
/div
/body
首先我們需要分析一下整個(gè)牌的構(gòu)造,以普通數(shù)字牌1為例,共可分為5個(gè)部分,分別是1、外框2、顏色3、上下角標(biāo)數(shù)字4、里面的白色橢圓5、中間的大數(shù)字
對(duì)應(yīng)不同的部分,我們將其分解為5部分的html代碼并為其添加class,1、卡牌背景2、卡牌顏色(由于布局相同只有顏色不同,故將顏色抽出成為單獨(dú)的類(lèi))3、上下角標(biāo)數(shù)字4、白色橢圓背景5、大數(shù)字
以下均采用代碼和效果圖對(duì)比的方式展示效果
布好局之后,為其添加樣式。首先新建css樣式表,并將其關(guān)聯(lián)至html文件
首先寫(xiě)背景的樣式,按牌的比例寫(xiě)出寬高,留白使用padding來(lái)寫(xiě),css3的新特性我們使用了如圖的圓角和陰影,為牌制造立體的感覺(jué)
然后來(lái)寫(xiě)牌的背景顏色,Uno牌一共有黑紅黃綠藍(lán)5種顏色,因此我們只需要事先定義好這五種顏色,之后將其對(duì)應(yīng)的類(lèi)名添加進(jìn)來(lái)就可以了。
另外,因?yàn)樯舷陆菢?biāo)的數(shù)字需要使用絕對(duì)定位,因此它們的父級(jí)元素就需要定義為相對(duì)定位
下面來(lái)寫(xiě)上下角標(biāo)的數(shù)字,由于這里使用的是em行內(nèi)元素標(biāo)簽,因此設(shè)置寬高的時(shí)候要記得display:inline-block。
絕對(duì)定位到需要的位置,然后將右下角的數(shù)字使用css3的旋轉(zhuǎn)函數(shù)180度旋轉(zhuǎn),就可以制造出倒過(guò)來(lái)的數(shù)字了
中間的白色橢圓要怎么畫(huà)呢,我們知道border-radius的值與寬高相等可以畫(huà)出圓形,那么當(dāng)它的值為寬的一半比高的一半時(shí),則可以畫(huà)出橢圓形,這時(shí)我們?cè)賹⑺D(zhuǎn)到合適的角度,就可以得到想要的橢圓
最后就是中間的數(shù)字,由于它是橢圓形的子元素,因此橢圓形旋轉(zhuǎn)的時(shí)候,它也跟著一起旋轉(zhuǎn),要想讓它擺在一個(gè)比較正的位置,還應(yīng)將它旋轉(zhuǎn)回來(lái)。并為它挑選一個(gè)合適的字體
至此,我們的普通數(shù)字牌已經(jīng)寫(xiě)好了
這個(gè)時(shí)鐘不需要很多HTML,這是因?yàn)樗艽蟮囊徊糠郑窆ぷ魅盏拿Q(chēng)和數(shù)字都是動(dòng)態(tài)生成的。 下面是你需要在你頁(yè)面上使用時(shí)鐘時(shí)要有的標(biāo)簽:
index.html
div id="clock" class="light"
div class="display"
div class="weekdays"/div
div class="ampm"/div
div class="alarm"/div
div class="digits"/div
/div
/div
主元素為#clock的div,包含.display的div,用于容納平日列表、AM/PM標(biāo)記、鬧鈴和時(shí)間。 下面代碼為每個(gè)數(shù)字生成一個(gè)標(biāo)簽:
div class="zero"
span class="d1"/span
span class="d2"/span
span class="d3"/span
span class="d4"/span
span class="d5"/span
span class="d6"/span
span class="d7"/span
/div
.digits元素包含6個(gè)像這樣帶span的div,每個(gè)div為時(shí)鐘的一個(gè)數(shù)字。就像你在上面片段中所見(jiàn)到的一樣,這些div擁有一個(gè)從0到9的樣式名稱(chēng),并且包含7個(gè)帶獨(dú)立樣式的span元素,這些span是數(shù)字的一部分,像老的數(shù)字時(shí)鐘一樣:
數(shù)字說(shuō)明
它們完全用CSS樣式渲染且默認(rèn)設(shè)置為 opacity:0 。定義在它們父div上的樣式將決定它們的可見(jiàn)性。下面是數(shù)字“0”的CSS:
assets/css/styles.css
/* 0 */
#clock .digits div.zero .d1,
#clock .digits div.zero .d3,
#clock .digits div.zero .d4,
#clock .digits div.zero .d5,
#clock .digits div.zero .d6,
#clock .digits div.zero .d7{
opacity:1;
}
除了中間一個(gè),所有的片斷都是可見(jiàn)的,我已經(jīng)向所有的這些span添加了CSS3轉(zhuǎn)換屬性,當(dāng)在數(shù)字之間切換時(shí)出現(xiàn)漸變效果。
樣式表里有很多其他CSS,我不再這列舉。我相信最好的方式去學(xué)習(xí)CSS如何工作就是在Firebug、Chrome的審查器或你瀏覽器里的開(kāi)發(fā)者工具里即時(shí)審查demo的代碼。
黑色主題
jQuery 代碼
要想要時(shí)鐘工作,我們將使用jQuery生成每個(gè)數(shù)字的標(biāo)簽,并且設(shè)置一個(gè)定時(shí)器每秒鐘更新一次樣式,為了更簡(jiǎn)單,我們使用moment.js 庫(kù)(快速開(kāi)始) 來(lái)補(bǔ)償JavaScript原生日期和時(shí)間方法的缺陷。
assets/js/script.js
$(function(){
// Cache some selectors
var clock = $('#clock'),
alarm = clock.find('.alarm'),
ampm = clock.find('.ampm');
// Map digits to their names (this will be an array)
var digit_to_name = 'zero one two three four five six seven eight nine'.split(' ');
// This object will hold the digit elements
var digits = {};
// Positions for the hours, minutes, and seconds
var positions = [
'h1', 'h2', ':', 'm1', 'm2', ':', 's1', 's2'
];
// Generate the digits with the needed markup,
// and add them to the clock
var digit_holder = clock.find('.digits');
$.each(positions, function(){
if(this == ':'){
digit_holder.append('div class="dots"');
}
else{
var pos = $('div');
for(var i=1; i8; i++){
pos.append('span class="d' + i + '"');
}
// Set the digits as key:value pairs in the digits object
digits[this] = pos;
// Add the digit elements to the page
digit_holder.append(pos);
}
});
// Add the weekday names
var weekday_names = 'MON TUE WED THU FRI SAT SUN'.split(' '),
weekday_holder = clock.find('.weekdays');
$.each(weekday_names, function(){
weekday_holder.append('span' + this + '/span');
});
var weekdays = clock.find('.weekdays span');
// Run a timer every second and update the clock
(function update_time(){
// Use moment.js to output the current time as a string
// hh is for the hours in 12-hour format,
// mm - minutes, ss-seconds (all with leading zeroes),
// d is for day of week and A is for AM/PM
var now = moment().format("hhmmssdA");
digits.h1.attr('class', digit_to_name[now[0]]);
digits.h2.attr('class', digit_to_name[now[1]]);
digits.m1.attr('class', digit_to_name[now[2]]);
digits.m2.attr('class', digit_to_name[now[3]]);
digits.s1.attr('class', digit_to_name[now[4]]);
digits.s2.attr('class', digit_to_name[now[5]]);
// The library returns Sunday as the first day of the week.
// Stupid, I know. Lets shift all the days one position down,
// and make Sunday last
var dow = now[6];
dow--;
// Sunday!
if(dow 0){
// Make it last
dow = 6;
}
// Mark the active day of the week
weekdays.removeClass('active').eq(dow).addClass('active');
// Set the am/pm text:
ampm.text(now[7]+now[8]);
// Schedule this function to be run again in 1 sec
setTimeout(update_time, 1000);
})();
// Switch the theme
$('a.button').click(function(){
clock.toggleClass('light dark');
});
});
/*text-align:?justify;*//*默認(rèn)left,可設(shè)right、center、justify、start、end*/
/*line-height:?3;*//*設(shè)置行高:normal、數(shù)字、百分比、px、em*/
/*text-indent:?20px;*//*設(shè)置首行縮進(jìn):像素、百分比、em*/
/*text-decoration:line-through?overline?underline;*//*默認(rèn)值none在超鏈接去掉默認(rèn)下劃線時(shí)可用到,下劃線underline,上劃線overline,刪除線line-through,閃爍文本blink*/
/*letter-spacing:?2em;*//*設(shè)置字符間距,默認(rèn)normal,可用像素、em,可設(shè)負(fù)值*/
/*word-spacing:?2em;*//*類(lèi)似letter-spacing,可設(shè)負(fù)值*/
/*text-transform:?lowercase;*//*none默認(rèn);capitalize每個(gè)單詞以大寫(xiě)字母開(kāi)頭,uppercase轉(zhuǎn)換為大寫(xiě)字母,lowercase轉(zhuǎn)換為小寫(xiě)字母*/
/*text-shadow:?3px?3px?3px?red,?-6px?-6px?3px?green;*//*四個(gè)參數(shù):橫向偏移、縱向偏移、模糊度、顏色,可加多個(gè)陰影用逗號(hào)隔開(kāi)*/
/*white-space:?pre;*//*設(shè)置元素中空白處理方式:默認(rèn)normal;pre空白會(huì)保留,類(lèi)似pre標(biāo)簽;nowrap文本不會(huì)換行,文本會(huì)在同一行上繼續(xù),直到遇到br標(biāo)簽為止;pre-wrap保留空白正常換行;pre-line合并空白正常換行*/
/*direction:?rtl;*//*默認(rèn)ltr*/
/*unicode-bidi:?bidi-override;*//*從右向左讀文字,一般配合direction使用,默認(rèn)normal,可設(shè)embed*/????
text-overflow設(shè)置是否使用一個(gè)省略標(biāo)記...標(biāo)示對(duì)象內(nèi)文本溢出:clip默認(rèn)值,當(dāng)對(duì)象內(nèi)文本溢出時(shí)不顯示省略標(biāo)記,而是將溢出部分裁掉;ellipsis當(dāng)對(duì)象內(nèi)文本溢出時(shí)顯示省略號(hào)。此屬性要和over-flow:hidden屬性,white-space:nowrap配合使用。*/
text-outline規(guī)定文本的輪廓;
text-justify規(guī)定當(dāng)text-align設(shè)置為justify時(shí)所使用的對(duì)齊方式;
text-align-last設(shè)置如何對(duì)齊最后一行或緊挨強(qiáng)制換行符之前的行;
text-emphasis向元素的文本應(yīng)用重點(diǎn)標(biāo)記以及重點(diǎn)標(biāo)記的前景色;
hanging-punctuation規(guī)定標(biāo)點(diǎn)字符是否位于線框之外;
punctuation-trim規(guī)定是否對(duì)標(biāo)點(diǎn)字符進(jìn)行修剪;
tab-size設(shè)定一個(gè)tab在頁(yè)面中的顯示長(zhǎng)度;
text-wrap規(guī)定文本的換行規(guī)則。
什么漢字可以,數(shù)字不行了?首先你得知道什么是豎向排列
第二張圖是正確的豎向排列
第一張圖數(shù)字是順時(shí)針旋轉(zhuǎn)了90°漢字是豎向排列的
方法一圖片去做
方法二用用css3把數(shù)字旋轉(zhuǎn)transform:rotate(90deg),漢字豎向排,你是限制寬度還是用其他方法都可以。
備注(我沒(méi)試過(guò),但是應(yīng)該還會(huì)有其他問(wèn)題,本人覺(jué)得這種動(dòng)態(tài)文字排版不合理)
分享文章:css3數(shù)字樣式,css3數(shù)字變化
標(biāo)題網(wǎng)址:http://chinadenli.net/article18/dsegidp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計(jì)、品牌網(wǎng)站建設(shè)、網(wǎng)站維護(hù)、微信公眾號(hào)、網(wǎng)站制作、域名注冊(cè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)