自己用過的一些比較有用的css3新屬性

來源:互聯網
上載者:User

標籤:style   http   io   color   ar   使用   java   sp   for   

        css3剛推出不久,雖然大多數的css3屬性在很多流行的瀏覽器中不支援,但我個人覺得還是要盡量開始慢慢的去瞭解並使用css3(還有html5),因為我覺得這是一種趨勢,它是一種已經被制定的標準。我並不是專門在做前端的,只是有時不得不自己去寫這些東西,有時喜歡研究研究這些,所有以上只是我的個人看法。

 

 1、在之前我想在頁面做出一個邊框為圓角框,貌似需要寫挺多css代碼的(可能我沒瞭解到更好的辦法),在css3裡有一個屬性建立圓角是非常容易的 ,設定好角度也可以建立一個圓

border-radius:

     
     

 
 css代碼:

 

#test

{

text-align:center;

padding:10px 40px; 

background:gray;

width:350px;

border-radius:10px;

-moz-border-radius:10px; /* 為了讓老的 Firefox版本支援 */

}

</style>

 

html代碼:

<body>

<div id="test">border-radius 做圓角的例子。</div>

</body>

 

 

2、CSS3 邊框陰影,之前我都是直接利用圖片做背景實現的效果,用css3中的box-shadow屬性也可以做到

box-shadow:

   
        
       

 

css代碼:

 

#test1

{

box-shadow: 10px 10px 5px #A5A5A5;

 

width:300px;

height:100px;

}

 

html代碼:

<body>

<div id="test1"></div>

</body>

 

3、css3 支援背景圖片可以用多張圖片

 

CSS3 多重背景圖片

    

     
        

 

.box

{

width:464px;

height:300px;

background:url(test1.jpg) 0 0 no-repeat,url(test2.jpg) 100% 0 no-repeat;

}

</style>

</head>

<body>

<div class="box"></div>

</body>

 

4、text-overflow 屬性規定當文本溢出包含元素時發生的事情。

此屬性支援切斷容器中的文本,當文本溢出可以給出了一個省略符號的特性。


     
    
  

   
 
 .test3 {

   text-overflow:ellipsis;

   overflow:hidden;

   white-space:nowrap;

   border: 1px solid black;

   width: 400px;

   padding: 20px;

   cursor: pointer;

}

#test3:hover {

  white-space: normal;

  color: rgba(0,0,0,1);

  background: #e3e3e3;

  border: 1px solid #666;

}

</style>

</head>

<body>

<div class="test3" id="test3">當這裡顯示的內容溢出是會有省略符號,滑鼠移到文本上面會顯示所有內容</div>

</body>

 

5、過渡效果,通過 CSS3,我們可以在不使用 Flash 動畫或 JavaScript 的情況下,當元素從一種樣式變換為另一種樣式時為元素添加效果。

 

效果用貼圖比較難體現出來,有興趣自己運行下面代碼:

 

<style>

 

div

 

{

 

width:100px;

 

height:100px;

 

background:blue;

 

transition:width 2s, height 2s;

 

-moz-transition:width 2s, height 2s, -moz-transform 2s; /* 可以支援Firefox 4 */

 

-webkit-transition:width 2s, height 2s, -webkit-transform 2s; /* 可以支援Safari and Chrome */

 

-o-transition:width 2s, height 2s, -o-transform 2s; /* 可以支援Opera */

 

}

 

 

 

div:hover

 

{

 

width:200px;

 

height:200px;

 

transform:rotate(180deg);

 

-moz-transform:rotate(180deg); /* 可以支援Firefox 4 */

 

-webkit-transform:rotate(180deg); /* 可以支援Safari and Chrome */

 

-o-transform:rotate(180deg); /* 可以支援Opera */

 

}

 

</style>

 

</head>

 

<body>

 

<div>把滑鼠放上該地區,來查看過渡效果。</div>

 

</body>

 

自己用過的一些比較有用的css3新屬性

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.