CSS 背景色漸層設定 linear-gradient

From: https://developer.mozilla.org/en-US/docs/Web/CSS/linear-gradient

HTML

<div id='background_div'
style='width:200px;height:200px;border:1px solid black;padding:5px;'>
我的背景色是漸層喔!
</div>

CSS

#background_div {
background-color: #F07575; /* fallback color if gradients are not supported */
background-image: -webkit-linear-gradient(top, hsl(0, 80%, 70%), #bada55); /* For Chrome and Safari */
background-image: -moz-linear-gradient(top, hsl(0, 80%, 70%), #bada55); /* For old Fx (3.6 to 15) */
background-image: -ms-linear-gradient(top, hsl(0, 80%, 70%), #bada55); /* For pre-releases of IE 10*/
background-image: -o-linear-gradient(top, hsl(0, 80%, 70%), #bada55); /* For old Opera (11.1 to 12.0) */
background-image: linear-gradient(to bottom, hsl(0, 80%, 70%), #bada55); /* Standard syntax; must be last */
}

範例結果:
http://jsfiddle.net/UzKX2/

廣告

CSS 如何指定顏色 (16進位值、RGB、RGBA、HSL、HSLA)

From: http://www.w3schools.com/cssref/css_colors_legal.asp

Hexadecimal Colors

Hexadecimal color values are supported in all major browsers.

A hexadecimal color is specified with: #RRGGBB, where the RR (red), GG (green) and BB (blue) hexadecimal integers specify the components of the color. All values must be between 0 and FF.

For example, the #0000ff value is rendered as blue, because the blue component is set to its highest value (ff) and the others are set to 0.

Example

Define different HEX colors:

#p1 {background-color:#ff0000;} / * red */
#p2 {background-color:#00ff00;} / * green */
#p3 {background-color:#0000ff;} / * blue */

RGB Colors

RGB color values are supported in all major browsers.

An RGB color value is specified with: rgb(red, green, blue). Each parameter (red, green, and blue) defines the intensity of the color and can be an integer between 0 and 255 or a percentage value (from 0% to 100%).

For example, the rgb(0,0,255) value is rendered as blue, because the blue parameter is set to its highest value (255) and the others are set to 0.

Also, the following values define equal color: rgb(0,0,255) and rgb(0%,0%,100%).

Example

Define different RGB colors:

#p1 {background-color:rgb(255,0,0);} / * red */
#p2 {background-color:rgb(0,255,0);} / * green */
#p3 {background-color:rgb(0,0,255);} / * blue */

RGBA Colors

RGBA color values are supported in IE9+, Firefox 3+, Chrome, Safari, and in Opera 10+.

RGBA color values are an extension of RGB color values with an alpha channel – which specifies the opacity of the object.

An RGBA color value is specified with: rgba(red, green, blue, alpha). The alpha parameter is a number between 0.0 (fully transparent) and 1.0 (fully opaque).

Example

Define different RGB colors with opacity:

#p1 {background-color:rgba(255,0,0,0.3);} / * red with opacity */
#p2 {background-color:rgba(0,255,0,0.3);} / * green with opacity */
#p3 {background-color:rgba(0,0,255,0.3);} / * blue with opacity */

HSL Colors

HSL color values are supported in IE9+, Firefox, Chrome, Safari, and in Opera 10+.

HSL stands for hue, saturation, and lightness – and represents a cylindrical-coordinate representation of colors.

An HSL color value is specified with: hsl(hue, saturation, lightness).

Hue is a degree on the color wheel (from 0 to 360) – 0 (or 360) is red, 120 is green, 240 is blue. Saturation is a percentage value; 0% means a shade of gray and 100% is the full color. Lightness is also a percentage; 0% is black, 100% is white.

Example

Define different HSL colors:

#p1 {background-color:hsl(120,100%,50%);} / * green */
#p2 {background-color:hsl(120,100%,75%);} / * light green */
#p3 {background-color:hsl(120,100%,25%);} / * dark green */
#p4 {background-color:hsl(120,60%,70%);} / * pastel green */

HSLA Colors

HSLA color values are supported in IE9+, Firefox 3+, Chrome, Safari, and in Opera 10+.

HSLA color values are an extension of HSL color values with an alpha channel – which specifies the opacity of the object.

An HSLA color value is specified with: hsla(hue, saturation, lightness, alpha), where the alpha parameter defines the opacity. The alpha parameter is a number between 0.0 (fully transparent) and 1.0 (fully opaque).

Example

Define different HSL colors with opacity:

#p1 {background-color:hsla(120,100%,50%,0.3);} / * green with opacity */
#p2 {background-color:hsla(120,100%,75%,0.3);} / * light green with opacity */
#p3 {background-color:hsla(120,100%,25%,0.3);} / * dark green with opacity */
#p4 {background-color:hsla(120,60%,70%,0.3);} / * pastel green with opacity */

[轉貼] 如何取得網頁元素的 “scrollbar" 右移最大值 ,scrollWidth、clientWidth 定義

來源:http://www.360doc.com/content/11/1025/09/432969_158877433.shtml ,http://stackoverflow.com/questions/5138373/how-do-i-get-the-max-value-of-scrollleft

如何取得網頁元素的 “scrollbar" 右移最大值

下面這行就可得知元素的 “scrollbar" 右移的最大值。

var maxScrollLeft = element.scrollWidth – element.clientWidth;

scrollHeight: 獲取對象的滾動高度。
scrollLeft: 設置或獲取位於對象左邊界和窗口中目前可見內容的最左端之間的距離
scrollTop: 設置或獲取位於對象最頂端和窗口中可見內容的最頂端之間的距離
scrollWidth: 獲取對象的滾動寬度

offsetHeight: 獲取對象相對於版面或由父坐標 offsetParent 屬性指定的父坐標的高度
offsetLeft: 獲取對象相對於版面或由 offsetParent 屬性指定的父坐標的計算左側位置
offsetTop: 獲取對象相對於版面或由 offsetTop 屬性指定的父坐標的計算頂端位置
offsetWidth: 是對象的可見寬度,包滾動條等邊線,會隨窗口的顯示大小改變

event.clientX 相對文檔的水平座標
event.clientY 相對文檔的垂直座標
clientWidth: 是對象可見的寬度,不包滾動條等邊線,會隨窗口的顯示大小改變。
clientHeight: 都認為是內容可視區域的高度,也就是說頁面瀏覽器中可以看到內容的這個區域的高度,一般是最後一個工具條以下到狀態欄以上的這個區域,與頁面內容無關。 內容來自17jquery

event.offsetX 相對容器的水平坐標
event.offsetY 相對容器的垂直坐標
document.documentElement.scrollTop 垂直方向滾動的值
event.clientX+document.documentElement.scrollTop 相對文檔的水平座標+垂直方向滾動的量 一起

以上主要指IE之中,FireFox差異如下:
IE6.0、FF1.06+:
clientWidth = width + padding
clientHeight = height + padding
offsetWidth = width + padding + border
offsetHeight = height + padding + border
IE5.0/5.5:
clientWidth = width – border
clientHeight = height – border
offsetWidth = width
offsetHeight = height

(需要提一下:CSS中的margin屬性,與clientWidth、offsetWidth、clientHeight、offsetHeight均無關) 1

[轉貼] a:link / a:visited / a:hover / a:active 使用上的順序

來源:http://www.dotblogs.com.tw/joysdw12/archive/2011/01/07/20651.aspx

在網站超連結效果使用上常常用到 a:link / a:visited / a:hover / a:active 這幾個css屬性。但是在使用上必須注意到的是這些屬性是有順序的。

使用上的順序如下:

        /* 未連結 */
        a:link
        {
            color: #000000;
        }
        /* 已連結過 */
        a:visited
        {
            color: #FF0000;
        }
        /* 滑鼠移至連結 */
        a:hover
        {
            color: #00FF00;
        }
        /* 選擇的連結 */
        a:active
        {
            color: #0000FF;
        }
 

a:hover 需放置在 a:link 跟 a:visited 之後,則 a:active 放置在 a:hover 之後。

Partial URLs are interpreted relative to the source of the style sheet

6.4 URL

A Uniform Resource Locator (URL) is identified with a functional notation:

BODY { background: url(http://www.bg.com/pinkish.gif) }
The format of a URL value is ‘url(‘ followed by optional white space followed by an optional single quote (‘) or double quote (“) character followed by the URL itself (as defined in [11]) followed by an optional single quote (‘) or double quote (“) character followed by optional whitespace followed by ‘)’. Quote characters that are not part of the URL itself must be balanced.

Parentheses, commas, whitespace characters, single quotes (‘) and double quotes (“) appearing in a URL must be escaped with a backslash: ‘\(‘, ‘\)’, ‘\,’.

Partial URLs are interpreted relative to the source of the style sheet, not relative to the document:

BODY { background: url(yellow) }

Style a Select Box Using Only CSS

From: http://bavotasan.com/2011/style-select-box-using-only-css/

<div class="styled-select">
<select>
<option>Here is the first option</option>
<option>The second option</option>
</select>
</div>

.styled-select select {
background: transparent;
width: 268px;
padding: 5px;
font-size: 16px;
line-height: 1;
border: 0;
border-radius: 0;
height: 34px;
-webkit-appearance: none;
}

div 包在 select 標籤外