CSS 技巧積累

來源:互聯網
上載者:User

--CSS 彈出表單後面的半透明效果
style="filter:alpha(opacity=30)"

--DIV高度最低不能為1px
加上font-size:0px;因為DIV有個預設字型大小

--position:absolute
style="position:absolute;"
加上這句,它修飾的對象會絕對服從後面left,top等的設定來定位對象位置。(相當於“浮起來”)
去掉這句,它修飾的對象會自動匹配動態調整來定位對象位置。(相當於“沉下去”)

--TextBox 極細邊框
BorderStyle="Solid" BorderColor="#999999" BorderWidth="1px"

--CSS 表格顯示極細邊框
<table border="0" bgcolor="#cfe5f0" bordercolor="#cfe5f0" cellpadding="0" cellspacing="1" >
<tr bgcolor="white">
<td bgcolor="white" width="100px">單位部門</td>
<td bgcolor="white" width="625px">應急響應</td>
</tr>
</table>

--CSS 表格列印極細邊框
<table border=1 style="display:;border-collapse: collapse">

--CSS 應用DIV高度調適型配置中最小高度(min-height)的妙用(相容IE,FF)
{height:auto !important;height:600px; min-height:600px;}

--CSS 字型強行換行
有時候會遇到給表格設定了寬度而字型過多卻不能換行的問題,特別是英文字型
<table cellspacing = "0" cellpadding = "0" width = "100" border = "1">
我們使用word-break:break-all; 來強行換行即可
<table cellspacing = "0" cellpadding = "0" width = "100" border = "1" style = "WORD-BREAK: break-all">

--CSS 首行縮排
<p style = "text-indent:2em;width:200px;">
有時候,我們需要將段落的首行縮排兩個文字,一般我們都是用4個HTML的空格(&amp;nbsp;)來實現,其實我們還可以用樣式表來達到這種效果!</p>

--CSS 兩個表格並排不換行
<table border="1" style="display:inline;">
<tr>
<td>表格1</td>
</tr>
</table>
<table border="1" style="display:inline;">
<tr>
<td>表格2</td>
</tr>
</table>

--CSS 同時使用兩個類
一般只能給一個元素設定一個類(Class),但這並不意味著不能用兩個:<p class="text side">...</p>
同時給P元素兩個類,中間用空格格開,這樣所有text和side兩個類的屬性都會加到P元素上來。如果它們兩個類中的屬性有衝突的話,後設定的起作用,即在CSS檔案中放在後面的類的屬性起作用。

--CSS用於文檔列印
許多網站上都有一個針對列印的版本,但實際上這並不需要,因為可以用CSS來設定列印風格。
也就是說,可以為頁面指定兩個CSS檔案,一個用於螢幕顯示,一個用於列印:
<link type="text/css" rel="stylesheet" href="/blog/stylesheet.css" media="screen" /> <link type="text/css" rel="stylesheet" href="printstyle.css" media="print" />
第1行就是顯示,第2行是列印,注意其中的media屬性。

--CSS 垂直置中
垂直對齊用表格可以很方便地實現,設定表格單元 vertical-align: middle 就可以了。但對CSS來說這沒用。如果你想設定一個導航條是2em高,而想讓導航文字垂直置中的話,設定這個屬性是沒用的。CSS方法是什麼呢?對了,把這些文字的行高設為 2em:line-height: 2em ,這就可以了。

相關文章

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.