顯示具有 CSS 標籤的文章。 顯示所有文章
顯示具有 CSS 標籤的文章。 顯示所有文章

2015年12月10日 星期四

[CSS3] justify-content 使用

來源網址: http://css.doyoe.com/properties/flex/justify-content.htm

justify-content:flex-start | flex-end | center | space-between | space-around


<!DOCTYPE html> <html lang="zh-cmn-Hans"> <head> <meta charset="utf-8" /> <title>CSS参考手册</title> <meta name="author" /> <style> h1{font:bold 20px/1.5 georgia,simsun,sans-serif;} .box{ display:-webkit-flex; display:flex; width:400px;height:100px;margin:0;padding:0;border-radius:5px;list-style:none;background-color:#eee;} .box li{margin:5px;padding:10px;border-radius:5px;background:#aaa;text-align:center;} #box{ -webkit-justify-content:flex-start; justify-content:flex-start; } #box2{ -webkit-justify-content:flex-end; justify-content:flex-end; } #box3{ -webkit-justify-content:center; justify-content:center; } #box4{ -webkit-justify-content:space-between; justify-content:space-between; } #box5{ -webkit-justify-content:space-around; justify-content:space-around; } </style> </head> <body> <h1>justify-content示例:</h1> <h2>justify-content:flex-start</h2> <ul id="box" class="box"> <li>a</li> <li>b</li> <li>c</li> </ul> <h2>justify-content:flex-end</h2> <ul id="box2" class="box"> <li>a</li> <li>b</li> <li>c</li> </ul> <h2>justify-content:center</h2> <ul id="box3" class="box"> <li>a</li> <li>b</li> <li>c</li> </ul> <h2>justify-content:space-between</h2> <ul id="box4" class="box"> <li>a</li> <li>b</li> <li>c</li> </ul> <h2>justify-content:space-around</h2> <ul id="box5" class="box"> <li>a</li> <li>b</li> <li>c</li> </ul> </body> </html> 

結果: http://jsfiddle.net/XmW49/497/ 

2015年11月30日 星期一

[引用]讓 ul 置中

我們常利用ul做選單、做列表、做頁碼 …等等,但會碰到一種狀況,是想讓ul置中,如果你直接寫text-align:center會發現ul完全不鳥你!
這是因為ul預設為display:block,所以如果想讓他置中,必須更改他的display狀態。
<div class="wrap"> <ul> <li>Hello</li> <li>World</li> </ul> </div> .wrap { text-align: center; } .wrap ul { display: inline-block; }
若是沒有上一層, 則給他一個class wrap, 然後使用 margin: 0 auto;
<ul class="wrap"> <li>Hello</li> <li>World</li> </ul> ul.wrap { display: table; margin: 0 auto; }

2015年7月16日 星期四

純CSS tooltip

Demo : http://codepen.io/anon/pen/aOjbgq
沒想到Css 也能透過 <div data-tooltip="提示資訊">XXX</div>
來呈現tooltip , Css 真是太威了.
[data-tooltip] { position: relative; z-index: 2; cursor: pointer; } /* Hide the tooltip content by default */ [data-tooltip]:before, [data-tooltip]:after { visibility: hidden; -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; filter: progid: DXImageTransform.Microsoft.Alpha(Opacity=0); opacity: 0; pointer-events: none; } /* Position tooltip above the element */ [data-tooltip]:before { position: absolute; bottom: 150%; left: 50%; margin-bottom: 5px; margin-left: -80px; padding: 7px; width: 160px; -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px; background-color: #000; background-color: hsla(0, 0%, 20%, 0.9); color: #fff; content: attr(data-tooltip); text-align: center; font-size: 14px; line-height: 1.2; } /* Triangle hack to make tooltip look like a speech bubble */ [data-tooltip]:after { position: absolute; bottom: 150%; left: 50%; margin-left: -5px; width: 0; border-top: 5px solid #000; border-top: 5px solid hsla(0, 0%, 20%, 0.9); border-right: 5px solid transparent; border-left: 5px solid transparent; content: " "; font-size: 0; line-height: 0; } /* Show tooltip content on hover */ [data-tooltip]:hover:before, [data-tooltip]:hover:after { visibility: visible; -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; filter: progid: DXImageTransform.Microsoft.Alpha(Opacity=100); opacity: 1; }

2015年7月1日 星期三

用Js setAttribute 寫css 速度差異.

用Js 寫css 速度差異. http://jsfiddle.net/XmW49/455/
var thing = document.getElementById("first"); console.time("first"); thing.setAttribute("style", "width: 100px; height: 100px; background-color: block;"); console.timeEnd("first"); var thing3 = document.getElementById("thing-3"); console.time("green"); thing3.style.cssText = "width: 100px; height: 100px; background-color: green;"; console.timeEnd("green"); var thing = document.getElementById("thing-4"); console.time("blue"); thing.style.width = "100px"; thing.style.height = "100px"; thing.style.backgroundColor = "blue"; console.timeEnd("blue"); var thing2 = document.getElementById("thing-2"); console.time("yellow"); thing2.setAttribute("style", "width: 100px; height: 100px; background-color: yellow;"); console.timeEnd("yellow"); var thing1 = document.getElementById("thing-1"); console.time("red"); thing1.setAttribute("style", "width: 100px; height: 100px; background-color: red;"); console.timeEnd("red"); console.log('---------');

Result :
first: 0.13ms
green: 0.15ms
blue: 0.11ms
yellow: 0.08ms
red: 0.06ms

心得:  第一次執行的, 都明顯偏慢. 但是當調換 thing-* 的執行順序, 結果又不近相同. 看來這種設定 css 方法, 若是多次執行, 可能會變很快吧.(ps: 謝謝提醒, 改變了做法.)

2014年10月27日 星期一

css and javascript 防止文字被選取.

<body style="-moz-user-select: none;" onselectstart="return false" oncontextmenu="return false" ondragstart="return false" >

2013年12月11日 星期三

bootstrap 3.0 讓 nav-tab 可以置中顯示.

來源網址: http://stackoverflow.com/questions/9421966/how-do-i-center-the-twitter-bootstrap-tabs-on-the-page


.nav-tabs > li, .nav-pills > li { float:none; display:inline-block; *display:inline; /* ie7 fix */ zoom:1; /* hasLayout ie7 trigger */ } .nav-tabs, .nav-pills { text-align:center; }


demo

2013年8月16日 星期五

[css] for 各種瀏覽器文字, url 自動斷行or 換行

參考連結 作法一: 不過這個做法有缺點, 會把英文字母拆開. -ms-word-break: break-all; word-break: break-all; /* Non standard for webkit */ word-break: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto;
參考連結 作法二: 這作法堪稱完美. .wordwrap { /* wrap long text and urls */ white-space: pre; /* CSS 2.0 */ white-space: pre-wrap; /* CSS 2.1 */ white-space: pre-line; /* CSS 3.0 */ white-space: -pre-wrap; /* Opera 4-6 */ white-space: -o-pre-wrap; /* Opera 7 */ white-space: -moz-pre-wrap; /* Mozilla */ word-wrap: break-word; /* IE 5+ */ }

2013年2月22日 星期五

[引用]IE8 Beta1、IE7、IE6、Firefox2.0.0.12的一些CSS HACK測試



對IE8、IE7、IE6、Firefox2.0.0.12做了簡單的一些CSS HACK測試。下文中的 IE8 暫時僅代表IE8 beta1)。
CSS定義:p {color:#f00;}
xhtml結構:文字
主要是測試"文字"這個顏色在不同瀏覽器下使用hack的一些結果報告:
* html p {color:#f00;} 支持 IE6 不支持FF IE7 IE8b1
*+html p {color:#f00;} 支持 IE7 IE8b1 不支持FF IE6
p {*color:#f00;} 支持 IE7 IE6 不支持FF IE8b1
相關測試:
p {+color:#f00;}
支持IE7 IE6
不支持FF IE8b1
p {_color:#f00;}
支持IE6
不支持FF
p {color:#00f !important;}
p {color:#f00;}
支持IE6 IE7 IE8b1 FF

p {color:#00f !important;color:#f00;}
支持IE7 IE8b1 FF
不支持IE6
head:first-child+body p {color:#f00;}
支持IE7 IE8b1 FF
不支持IE6
/**//*/
p {color:#f00;}
/**/
支持IE8b1
不支持IE6 IE7 FF
html*p {color:#f00;}
支持IE6 IE7
不支持IE8b1 FF
body>p {color:#f00;}
支持IE7 IE8b1 FF
不支持IE6
html[xmlns] p {color:#f00;}
支持IE7 IE8b1 FF
不支持IE6
@import 'style.css';
@import "style.css";
@import url(style.css);
@import url('style.css');
@import url("style.css");
支持IE6 IE7 IE8b1 FF

P {/*/*color:#f00;/* */}
支持IE6 IE7 FF
不支持IE8b1

IE8 中增加了 CSS3 中的子串匹配的屬性選擇器(substring matching attribute selectors),具體規則與正則中的匹配很相似:
E[att^='val'] //子串以'val' 開始
E[att$='val'] //子串以'val' 結束
E[att*='val'] //子串中包含'val'
IE8 支持絕大多數基本的 CSS2.1 選擇器,不支持的包括但不限於:[:first-line] 、[:first-letter]。
對於 CSS2.1 中的 generated content 部分,即通過使用偽元素 :before 和 :after 添加文本內容,IE8 中支持 並未完全 。
而對於幾乎在其他瀏覽器中都支持的 opacity 和 RGBA ,IE8 中依舊沒有支持。
對於原來用來區分 IE 的 HACK 在 IE8 中基本失效(比如*property:value、*property:value等)。
原有 IE 的 list-item whitespace bug 在 IE8 中依舊存在。
原有 IE 的 z-index bug 在 IE8 中依舊存在。
IE8 中產生新的 bug:當 line-heigth 小於正常值時,超出的部分將被裁切掉。
IE8 中依然不支持 display:table 。
IE8 中依然不支持 border 的 transparent 值。
IE8 中 @import 只支持三層嵌套。
IE8中 border的 transparent 不被支持
IE8中產生新的BUG:line-heigth BUG
/*/p{ color:#1e90ff}/*/ 只針對IE8的hack,可以是屬性也可以是類

[引用]IE5、IE6、IE7、IE8 的CSS HACK兼容列表

引用來源:http://www.5dsky.com/blog/a/?id=62

官方信息

IETester is a free WebBrowser that allows you to have the rendering and javascript engines of IE8 beta 1, IE7 IE 6 and IE5.5 on Vista and XP, as well as the installed IE in the same process. New in v0.2.1 : Improved stability and multi-lingual interface !
This is an alpha release, so feel free to post comments/bugs on the IETester forum or contact me directly. Minimum requirement : Windows Vista or Windows XP with IE7 (Windows XP with IE6 has some minor problems and IE7/IE8 instances do not work under this config)
IETester
如何像上圖那樣左右分tab——按緊其中一個tab,然後拉向右面,放手即可

下載

一、CSS HACK
以下兩種方法幾乎能解決現今所有HACK.

1, !important
隨著IE7對!important的支持, !important 方法現在只針對IE6的HACK.(注意寫法.記得該聲明位置需要提前.)


2, IE6/IE77對FireFox
*+html 與 *html 是IE特有的標籤, firefox 暫不支持.而*+html 又為 IE7特有標籤.


注意:
*+html 對IE7的HACK 必須保證HTML頂部有如下聲明:
http://www.w3.org/TR/html4/loose.dtd">

二、萬能 float 閉合
關於 clear float 的原理可參見 [How To Clear Floats Without Structural Markup]
將以下代碼加入Global CSS 中,給需要閉合的div加上 class="clearfix" 即可,屢試不爽.

三、其他兼容技巧
1, FF下給 div 設置 padding 後會導致 width 和 height 增加, 但IE不會.(可用!important解決)
2, 居中問題.
1).垂直居中.將 line-height 設置為 當前 div 相同的高度, 再通過 vertical-align: middle.( 注意內容不要換行.)
2).水平居中. margin: 0 auto;(當然不是萬能)
3, 若需給 a 標籤內內容加上 樣式, 需要設置 display: block;(常見於導航標籤)
4, FF 和 IE 對 BOX 理解的差異導致相差 2px 的還有設為 float的div在ie下 margin加倍等問題.
5, ul 標籤在 FF 下面默認有 list-style 和 padding . 最好事先聲明, 以避免不必要的麻煩. (常見於導航標籤和內容列表)
6, 作為外部 wrapper 的 div 不要定死高度, 最好還加上 overflow: hidden.以達到高度自適應.
7, 關於手形光標. cursor: pointer. 而hand 只適用於 IE.

1 針對firefox ie6 ie7的css樣式
現在大部分都是用!important來hack,對於ie6和firefox測試可以正常顯示,
但是ie7對!important可以正確解釋,會導致頁面沒按要求顯示!找到一個針
對IE7不錯的hack方式就是使用"*+html",現在用IE7瀏覽一下,應該沒有問題了。
現在寫一個CSS可以這樣:

#1 { color: #333; } /* Moz */
* html #1 { color: #666; } /* IE6 */
*+html #1 { color: #999; } /* IE7 */
那麼在firefox下字體顏色顯示為#333,IE6下字體顏色顯示為#666,IE7下字體顏色顯示為#999。

2 css佈局中的居中問題
主要的樣式定義如下:

body {TEXT-ALIGN: center;}
#center { MARGIN-RIGHT: auto; MARGIN-LEFT: auto; }
說明:
首先在父級元素定義TEXT-ALIGN: center;這個的意思就是在父級元素內的內容居中;對於IE這樣設定就已經可以了。
但在mozilla中不能居中。解決辦法就是在子元素定義時候設定時再加上"MARGIN-RIGHT: auto;MARGIN-LEFT: auto; "
需要說明的是,如果你想用這個方法使整個頁面要居中,建議不要套在一個DIV裡,你可以依次拆出多個div,
只要在每個拆出的div裡定義MARGIN-RIGHT: auto;MARGIN-LEFT: auto; 就可以了。

3 盒模型不同解釋
#box{ width:600px; //for ie6.0- w\idth:500px; //for ff+ie6.0}
#box{ width:600px!important //for ff width:600px; //for ff+ie6.0 width /**/:500px; //for ie6.0-}

4 浮動ie產生的雙倍距離
#box{ float:left; width:100px; margin:0 0 0 100px; //這種情況之下IE會產生200px的距離 display:inline; //使浮動忽略}
這裡細說一下block,inline兩個元素,Block元素的特點是:總是在新行上開始,高度,寬度,行高,邊距都可以控制(塊元素);Inline元素的特點是:和其他元素在同一行上,...不可控制(內嵌元素);

#box{ display:block; //可以為內嵌元素模擬為塊元素 display:inline; //實現同一行排列的的效果 diplay:table;
IE不認得min-這個定義,但實際上它把正常的width和height當作有min的情況來使。這樣問題就大了,如果只用寬度和高度,
正常的瀏覽器裡這兩個值就不會變,如果只用min-width和min-height的話,IE下面根本等於沒有設置寬度和高度。
比如要設置背景圖片,這個寬度是比較重要的。要解決這個問題,可以這樣:
#box{ width: 80px; height: 35px;}html>body #box{ width: auto; height: auto; min-width: 80px; min-height: 35px;}

6 頁面的最小寬度
min-width是個非常方便的CSS命令,它可以指定元素最小也不能小於某個寬度,這樣就能保證排版一直正確。但IE不認得這個,
而它實際上把width當做最小寬度來使。為了讓這一命令在IE上也能用,可以把一個

放到 標籤下,然後為div指定一個類:
然後CSS這樣設計:
#container{ min-width: 600px; width:expression(document.body.clientWidth < 600? "600px": "auto" );}
第一個min-width是正常的;但第2行的width使用了Javascript,這只有IE才認得,這也會讓你的HTML文檔不太正規。它實際上通過Javascript的判斷來實現最小寬度。
7 清除浮動
.hackbox{ display:table; //將對象作為塊元素級的表格顯示}或者.hackbox{ clear:both;}
或者加入:after(偽對象),設置在對象後發生的內容,通常和content配合使用,IE不支持此偽對象,非Ie 瀏覽器支持,
所 以並不影響到IE/WIN瀏覽器。這種的最麻煩的......#box:after{ content: "."; display: block; height: 0; clear: both; visibility: hidden;}

8 DIV浮動IE文本產生3像素的bug
左邊對象浮動,右邊採用外補丁的左邊距來定位,右邊對象內的文本會離左邊有3px的間距.
#box{ float:left; width:800px;}#left{ float:left; width:50%;}#right{ width:50%;}*html #left{ margin-right:-3px; //這句是關鍵}
HTML代碼

9 屬性選擇器(這個不能算是兼容,是隱藏css的一個bug)
p[id]{}div[id]{}
這個對於IE6.0和IE6.0以下的版本都隱藏,FF和OPera作用
屬性選擇器和子選擇器還是有區別的,子選擇器的範圍從形式來說縮小了,屬性選擇器的範圍比較大,如p[id]中,所有p標籤中有id的都是同樣式的.

10 IE捉迷藏的問題
當div應用複雜的時候每個欄中又有一些鏈接,DIV等這個時候容易發生捉迷藏的問題。
有些內容顯示不出來,當鼠標選擇這個區域是發現內容確實在頁面。
解決辦法:對#layout使用line-height屬性 或者給#layout使用固定高和寬。頁面結構儘量簡單。

11 高度不適應
高度不適應是當內層對象的高度發生變化時外層高度不能自動進行調節,特別是當內層對象使用
margin 或paddign 時。
例:


p對象中的內容

CSS:#box {background-color:#eee; }
#box p {margin-top: 20px;margin-bottom: 20px; text-align:center; }
解決方法:在P對象上下各加2個空的div對象CSS代碼:.1{height:0px;overflow:hidden;}或者為DIV加上border屬性。
 

添加:
X-UA-Compatible是針對ie8新加的一個設置,對於ie8之外的瀏覽器是不識別的,這個區別與 content="IE=7"在無論頁面是否包含指令,都像是使用了 Windows Internet Explorer 7的標準模式。而content="IE=EmulateIE7"模式遵循指令。對於多數網站來說,它是首選的兼容性模 式。
目前IE8尚在測試版中,所以為了避免製作出的頁面在IE8下面出現錯誤,建議直接將IE8使用IE7進行渲染。也就是直接在頁面的header的meta標籤中加入如下代碼:
這樣我們才能使得頁面在IE8里面表現正常!

2012年6月8日 星期五

[引用]文字的垂直與水平置中

單行文字的置中。以下方法都不使用 TABLE 元素,而是要在 DIV 元素 置中。單行文字的置中,其水平置中可用 text-align:center。垂直置中可以將 line-height 宣告與 height 相同,此法只能用在單行文字的情形。 <style type='text/css'> .out1 {width:160px; border:solid 1px red; height:100px; } </style> <div class=out1 style='text-align:center'> <span>水平置中</span> </div> <div class=out1 style='line-height:100px'> <span>垂直置中</span> </div> <div class=out1 style='text-align:center; line-height:100px'> <span>中央</span> </div>
  • 執行結果:
    水平置中
    垂直置中
    中央

  • 區塊元素的置中。先要將子區塊元素設為 display:inline-block。水平置中可用 text-align:center。垂直置中可以將父元素 line-height 宣告與 height 相同,然後子區塊必須設成 vertical-align:middle;line-height:1em。為了在 IE6 達成垂直置中,還必須加上 margin:expression();此法使用 parentNode, clientHeight 與數學函式 floor() 計算 margin。expression() 這行在個人電腦測試正常,可是移到部落格之後,會導致 IE6 停頓,所以用註解取消其功能;使用時請多測試。
    <style type='text/css'> .blk {width:200px; height:120px; border:solid 1px red; line-height:120px; text-align:center; } .blk DIV {width:100px; background:blue; display:inline-block; vertical-align:middle; line-height:1em; /* margin:expression(Math.floor( (this.parentNode.clientHeight-this.clientHeight)/2 )+'px auto'); */ } </style> <div class=blk> <div>中央<br />中央</div> </div>
    執行結果:

    中央
    中央

    來源網站:螞蟻的css還有圖片垂直與水平置中喔.

    2012年5月8日 星期二

    Css 控制table 表格

    簡易的用css控制table 的表格.記下來~ #show_table table { background: none repeat scroll 0 0 #FFFFFF; text-align: left; background: none repeat scroll 0 0 #F9F9F9; border: 1px solid #AAAAAA; border-collapse: collapse; color: black; } #show_table th { background: none repeat scroll 0 0 #F2F2F2; text-align: center; } #show_table th, #show_table td { border: 1px solid #AAAAAA; padding: 0.2em; } table { font-size: 100%; }
    結果如下:

    2011年10月12日 星期三

    [引用]CSS 排版觀念 position 參數說明

    引用來源: http://my-web-design.blogspot.com/2007/10/css-divposition.html

    CSS 排版觀念 position 參數說明
    position 參數

    / 參數說明
    absolute relative static(預設值) fixed
    中文意義 絕對位置 相對位置 靜態位置 固定位置
    畫面位置參考基準 父元素內容區邊界 原本應該在的位置 不變 不指定:原本應該在的位置

    指定:螢幕視窗最大可視範圍邊界 (或框架邊界)
    移動參考基準 文件 文件 文件 螢幕視窗最大可視範圍
    可改變顯示位置
    可調整大小 display 為 block :是

    display 為 inline :否
    display 為 block :是

    display 為 inline :否
    從顯示流程中去除

    當我們對元素的 position 屬性,指定了 absolute、 relative 或 fixed 後,這個元素就可以移動了。我們可以用 top, left, right, bottom 這四種屬性來指定元素要呈現的位置。

    由於 IE 不支援 position: fixed ,使得固定位置這個好用的技巧一直不受大家的重視。但在這裡我還是提一下。你可以使用 FireFox 來感受一下固定位置的強大威力,或是等待新版的 IE 支援。

    接下來我們來解釋上面的表列裡,每個參數說明的意義。

    畫面位置參考基準


    以絕對位置 (position: absolute) 而言,故名思義,它是以父元素的邊界為絕對起點。例如如果我們設定 top: 50px ,那麼這個元素就會在距離父元素內容區上邊界 50px 的地方呈現,如下圖:

    position: absolute

    補充:如果父元素的 position 不是 absolute 或 relative 時,那麼元素的位置就會再對應到父元素的上層元素;如果其親代元素的 position 都沒有設定 absolute 或 relative 時,就以螢幕視窗最大可視範圍邊界為基準。

    而以相關位置 (position: relative) 而言,其意義就是相對於原本的位置。例如我們指定 top: 50px 時,那麼這個元素就會從原本應該呈現的位置往下移動 50px 。如下圖,紅色虛線部份就是未設定 position: relative 前,元素原該應該在的位置:

    position: relative

    而固定位置 (position: fixed) 指的就是固定在螢幕視窗最大可視範圍上,如果不指定位置 (top, left, right, bottom) 時,那元素就會固定在原本的位置;而指定位置後,就會以螢幕視窗最大可視範圍的邊界為絕對基準點。如果頁面內容超過螢幕視窗最大可視範圍大小時,那麼不論 我們如何捲動頁面,元素都會固定在螢幕視窗最大可視範圍上我們所指定的位置。

    移動參考基準


    當頁面可以捲動的時候,absolute 、 relative 、 static 都會跟著移動。只有 fixed 會固定在螢幕視窗最大可視範圍上,不會跟著移動。

    可改變顯示位置


    就是我們可以透過指定元素的 top, left, right, bottom 四個屬性,使元素改變顯示位置。如果元素是 position: static 時,會自動忽略所設定的 top, left, right, bottom 。

    可調整大小


    我們可以透過 width, height 來調整元素內容區的大小,不過當 position 是 relative 或是 static 時,元素的 display 屬性必須為 block 才可調整其大小。

    從顯示流程中去除


    顯示流程的意義就是頁面上的每一個元素的呈現,換句話說,就是該元素會出現的位置,及其佔用的空間等等。

    我們可以將原來的頁面想成是一個圖層,每個元素都是一個一個緊接在前一個元素後面。如下圖,在尚未指定 position 時,粉紫色區塊會緊接在淺藍色區塊後。
    從顯示流程中去除_1

    請注意,我在這裡提到的圖層,指的是瀏覽器去解譯 HTML 後,將元素呈現出來的圖層,而非一般我們所認為,以絕對位置呈現的圖層;你可以把它想像成是 Photoshop 裡的圖層。

    當我們指定淺藍色區塊的 position 屬性為 absolute 或 fixed 後,淺藍色區塊就會跑到另一個圖層;而粉紫色區塊因為淺藍色區塊已經從原圖層的顯示流程中去除了,所以它就自動往上跑。如下圖,紅色虛線就是粉紫色區塊原本的位置。

    從顯示流程中去除_2

    而元素如果指定為 relative 時,雖然也能移動,但原本的頁面圖層還是會保留該元素所佔有的空間。

    2011年10月11日 星期二

    Adding * To Required Field Using CSS

    很實用的CSS :


    HTML: <label class="required" for="username">Email address</label>

    CSS: .required { background-image:url(/path/to/your/images/dir/required-field.png); background-position:top right; background-repeat:no-repeat; padding-right:10px; }
    參考文章:http://www.techchorus.net/adding-required-zendform-field-using-css

    圖片:required-field.png

    2011年8月11日 星期四

    CSS 強制縮圖

    為避免使用者插入過大圖片,可利用CSS來將之強制縮圖!

    div. className img {
    max-width: 500px;
    width:expression(this.width > 500? "500px" : this.width);
    overflow:hidden;
    }

    div. className img中的500則是指定圖片寬度上限,超過此上限,會強制縮到500px,這樣就不用擔心被圖稱破版面了。
    「max-width」IE不支援,所以才用CSS Expression來讓IE縮放寬度
    IE 8 版本在標準模式下,不再支援CSS Expression

    2010年11月18日 星期四

    [引述]CSS Hack 在各瀏覽器的差異、用法 整理

    引述:http://plog.longwin.com.tw/document-ebook/2009/11/19/paper-css-hack-browser-diff-howto-2009



    處理不同瀏覽器畫面錯亂問題

    CSS 在排版的時後, 都會遇到在 Firefox 排版完成, 但是在 IE 亂了, 而且在 IE 6 看是好的, 在 IE 7 可能又亂了.....
    解法就是在屬性前面加上特殊符號, 那些符號是 IE 認識, 但 Firefox 不認識, 用這種方法來將畫面做微調.
    解法如下述幾點:
    1. *: IE 7 以前的版本認得(7以後的不知道, 還沒出..)
    2. _: IE 7 不認得, IE 6 以前的版本認得_
    3. Firefox 不認得 _, *
    4. 將畫面在 FF 寫好後, 然後再用 *, _ 來對 IE 做微調

    IE6IE7IE8FirefoxOperaGoogle範例
    .YYNNNN.type { .color: #F00; }
    *YYNNNN.type { *color: #F00; }
    _YNNNNN.type { _color: #F00; }
    !importantYYYYYY.type { color: #F00 !important; }
    *+YYNNNN.type { *+color: #F00; }

    2010年11月15日 星期一

    [CSS] clear:both cross browser

    Source: How To Clear Floats Without Structural Markup

    修正 CSS 對於 float 區塊, 使用 clear:both 無效的解法



    Clearing the divs has always been a solution for web 2.0 sites but there are many ways to implement it. The reason of this post is not to go in the details but giving a simple cross-browser css solution. BTW I prefer this css solution rather than adding the ugly empty clear div all over your html and polluting the markup.

    Bad Solution :

    <div style="clear:both"></div>
    Perfect Cross Browser Solution:

    add the css below to your site wide CSS file. and then apply the class clearfix to any containers that need to be cleared, or the containers in which you are adding the clear-div. and yes remove the clear-div of-course.

    view sourceprint?

    .clearfix:after {
    content: ".";
    display: block;
    clear: both;
    visibility: hidden;
    line-height: 0;
    height: 0;
    }

    .clearfix {
    display: inline-block;
    }

    html[xmlns] .clearfix {
    display: block;
    }

    * html .clearfix {
    height: 1%;
    overflow: visible;
    }

    2010年11月12日 星期五

    CSS table border

    用下列 css 讓 table border 比較好看.

    #qc_table {
    border: 1px solid #000000;
    width:800px;
    border-collapse: collapse;
    }
    #qc_table td { border: 1px solid #000000; }
    #qc_table th { border: 1px solid #000000; }


    Name Description

    2010年11月2日 星期二

    [引用]JavaScript Fix CSS, 讓 IE 5/6 的 CSS 顯示/動作 跟 IE 7 一樣

    同樣的 CSS 在 IE5/6/7 顯示的效果都有可能會有所不同, 所以就有人寫 JavaScript 來解決 IE7 上可以跑, IE5/6 不能跑(或不能顯示)的問題. (ex: png 透明圖 就是最常遇到的問題).

    出處
    這是一段 JavaScript, 目前最新版是 0.9 版, 可由此下載: IE7 JavaScript fix download, 就算不使用, 也可以上去看一下 IE5/6/7 有哪些問題, 如何修正等. 整理的很齊全~

    官方網站: IE7 { css2: auto; }, 此 Library 目標:

        IE7 is a JavaScript library to make IE behave like a standards-compliant browser. It fixes many CSS issues and makes transparent PNG work correctly under IE5 and IE6

    要看 Source 就抓 IE7_0_9-source.zip, 要直接使用就抓 IE7_0_9.zip(有做JS壓縮, 並且有 README.txt), 使用方法很簡單, 只要下面步驟即可:

       1. cd 網站路徑
       2. unzip IE7_0_9.zip
       3. 在 <head></head>中加入此行即可

              <!--[if lt IE 7]><script src="/ie7/ie7-standard-p.js" type="text/javascript"></script><![endif]-->

    2010年7月26日 星期一

    [引用]CSS 防止表格被內容撐開

    在我們設計網頁的時候,總會遇到一些不愉快的事情,最常見的莫過於在後台添加內容後才發現顯示的頁面被撐開,導致網頁極度不美觀。以前大家基本上都是設計 表格,網上自然不少對於的解決方法,如今還有div+css標準設計,很少看到相關好的方法,現在把平時找到的防止表格被撐開的好方法總結歸納一下,和大 家一起分享。

    防止表格被撐開或div層被撐開的多種方法在 我們設計網頁的時候,總會遇到一些不愉快的事情,最常見的莫過於在後台添加內容後才發現顯示的頁面被撐開,導致網頁極度不美觀。以前大家基本上都是設計表 格,網上自然不少對於的解決方法,如今還有div+css標準設計,很少看到相關好的方法,現在把平時找到的防止表格被撐開的好方法總結歸納一下,和大家 一起分享。
    一、直接在網頁裡設置圖片大小,比如代碼:http://www.krjpg.cn/www.xxol.net.jpg" width="600" height="500" border="0">,這樣雖然可以限制了圖片大小,但是需要在上傳圖片之前手動修改圖片大小,否則上傳的圖片就會變形。

    二、使用如下代碼:http://www.krjpg.cn/www.xxol.net.jpg" onload="javascript:if(this.width>600}{this.resized=true;this.style.width=600;}">

    這種方法會在調用圖片的時候,自動按比例縮小到指定的寬度,不會引起圖片的變形,並且也不會撐破表格,但是缺點是,如果圖片太大,在圖片下載過程中,也就是圖片顯示過程中,會先以圖片原大小顯示,這時就會撐破表格,頁面很難看,二當圖片完全顯示後,圖片又會自動縮小。

    三、 我們可以針對表格的屬性來限制大小防止被撐開,比如在裡添加代碼「style="table-layout:fixed;word- wrap:break-word; word-break;break-all;"」,其中「table-layout:fixed; 」是為了將表格佈局固定住,就可以有效地防止表格被撐開,「word-wrap:break-word; 」是控制換行的,也就是強制執行換行,這個在文本內容較多的情況下需要使用到,特別是重複的內容出現,不執行換行的話,表格就被撐開了;而「word- break: break-all; 」可以解決IE的框架被英文(非亞洲語言文本行)撐開的問題,但是不會強制換行,只顯示表格寬度裡的內容。一般情況下只要用到 「style="table-layout:fixed;word-wrap:break-word;"」就可以。當然,上面調用的語句可以定義在css 裡,比如

    table {
    table-layout: fixed;
    word-wrap:break-word;
    }

    四、用css控制圖片自適應大小,代碼如:
    img {
    max-width: 600px;
    width:expression(this.width > 600 ? "600px" : this.width);
    overflow:hidden;
    }
    其 中 max-width:600px; 在IE7、FireFox等其他非IE瀏覽器下最大寬度為600px,但在IE6中無效;width:600px; 在所有瀏覽器中圖片的大小為600px,當圖片大小大於600px,自動縮小為600px,在IE6中有效;而 overflow:hidden;  指將超出設置大小的部分隱藏,避免控制圖片大小失敗而引起的表格撐開變形。

    五、最後總結一下最實用的代碼:
    如果是表格,請用:
    table {
    table-layout: fixed;
    word-break: break-all;
    }
    如果是div層,請用:
    div {
    table-layout: fixed;
    word-wrap: break-word;
    width: 加上寬度;
    overflow: hidden;    (讓多出來的不顯示。)  
    }

    引用內容:
    /* 解決英文斷字、避頭尾、段落左右邊界不齊問題 */
    table td {
       /* 自訂寬度 */
       width: 500px;
       
       /* 英文單字自動換行 */
       word-wrap: break-word;
       /* 正常避頭尾 */
       word-break: normal;
       /* 文字左右對齊 */
       text-align:justify;
       text-justify:inter-ideograph;
    }

    /* 解決版面撐開:針對連續符號與冗長網開,需使用div?#93;覆 */
    table div {
       /* 防止撐開 fot IE */
       table-layout: fixed;
       /* 防止撐開 fot FF */
       overflow: auto;
    }

    在IE能正確折行,不被撐開,且左右對齊(如果不考慮FF,可以省略包一層div)
    再FF需多加一層div來顯示完整內容(有些人是直接隱藏超出去的部份,就不用再包一層div,但是內容被隱藏總是覺得不夠好,所以需要再加一層div來成呈現完整內容)

    ps. 解決英文斷字、避頭尾、段落左右邊界不齊問題:在中文上比較沒有影響(若不是英文為主的網站可以略過)

    本文出處:http://blog.pixnet.net/pinkyvivi/trackback/a0e1f8530b/13333373

    2010年6月17日 星期四

    CSS ie6 問題與解決方式.

    ie6 造成的 div border 消失與 tab 切換時display:none , 顯示隱藏tab 位置跑掉的問題.

    #content {
    zoom:1;
    }

    #teaser {
    /* this makes the borders in the teaser box show up properly in IE6 */
    position:relative;
    display:block;
    }

    //處理ie6 Div border 後面消失的問題.
    * html #sitemap-panel {height: 1px;}


    來源:http://www.webdeveloper.com/forum/showthread.php?t=187328