幾個簡單實用的css效果

來源:互聯網
上載者:User

標籤:style   blog   http   io   ar   color   os   使用   sp   

1.要使按鈕具有3D效果,只要將它的左上部分邊框設定為淺色,右下部分邊框設定為深色即可。

eg:#button {
    background: #888;
    border: 2px solid;
    border-color: #999 #777 #777 #999;
  }

 

2. 實現透明效果

將一個容器設為透明,可以使用下面的代碼:

  .element { 
    filter:alpha(opacity=50); 
    -moz-opacity:0.5; 
    -khtml-opacity: 0.5; 
    opacity: 0.5; 
  }

在這四行CSS語句中,第一行是IE專用的,第二行用於Firefox,第三行用於webkit核心的瀏覽器,第四行用於Opera。

3. CSS三角形效果

先編寫一個空元素<div class="triangle"></div>,然後將它四個邊框中的三個邊框設為透明,剩下一個設為可見,就可以產生三角形效果:

   .triangle{

         display:block;
         height:0px;
         width:0px;
         border:50px solid #000;
         border-color:transparent transparent green transparent;
         border-style:solid;
}

效果如下所示:


 

4.CSS提示框效果

<div class="tip-bubble tip-bubble-left">Arrow on left </div>

<div class="tip-bubble tip-bubble-right">Arrow on Right</div>

<div class="tip-bubble tip-bubble-top">Arrow on top</div>

<div class="tip-bubble tip-bubble-bottom">Arrow on bottom</div>

.tip-bubble {
position: relative;
background-color: #202020;
width: 100px;
padding: 20px;
color: #CCC;
text-align: center;
border-radius: 10px;
margin: 50px;
border: 1px solid #111;
border-shadow: 1px 1px 2px #CCC;
text-shadow: 0px 0px 5px #404040;
}

.tip-bubble:after {
content: ‘‘;
position: absolute;
width: 0;
height: 0;
border: 15px solid;
}

/* Position the Arrow */
.tip-bubble-top:after {
border-bottom-color: #202020;
left: 50%;
bottom: 100%;
margin-left: -15px;
}
.tip-bubble-right:after {
border-left-color: #202020;
left: 100%;
top: 50%;
margin-top: -15px;
}

.tip-bubble-bottom:after {
border-top-color: #202020;
top: 100%;
left: 50%;
margin-left: -15px;
}

.tip-bubble-left:after {
border-right-color: #202020;
top: 50%;
right: 100%;
margin-top: -15px;
}

效果如下所示:

5.固定位置的頁首效果

 body{ margin:0;padding:100px 0 0 0;}

  div#header{
    position:absolute;
    top:0;
    left:0;
    width:100%;
    height:<length>;
  }

  @media screen{
    body>div#header{position: fixed;}
  }

  * html body{overflow:hidden;}

  * html div#content{height:100%;overflow:auto;}

6. 用圖片替換文字

有時我們需要在標題列中使用圖片,但是又必須保證搜尋引擎能夠讀到標題,CSS語句可以這樣寫:

  h1 { 
    text-indent:-9999px; 
    background:url("h1-image.jpg") no-repeat; 
    width:200px; 
    height:50px; 
  }

幾個簡單實用的css效果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.