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 標籤外

Here’s a quick way to style an input button

From: http://www.red-team-design.com/style-an-input-button

Here’s a quick way to style an input button
October 23, 2009 by Catalin Rosu – 12 comments
I assume there was at least one time when you wanted to add more appeal to a html input and at that moment you didn’t knew how.
We all know how boring looks an input when we use it without styling it and that’s why today I will show you the way to get rid of this old-style input.

For the beginning here is how a non-styled input looks like:

When styling and input button, we have two alternatives, to style it using only CSS with pout a background image, or using a custom background image.
1.USE ONLY CSS WITHOUT BACKGROUND IMAGE
First add a class or an id to your button. For this tutorial we will add an id because we do not intend to use this kind of button several times into a page:

Now let’s add some styles for the id:

#btn
{
border: 1px solid #777777;
background: #6e9e2d;
color: white;
font: bold 11px ‘Trebuchet MS’;
padding: 4px;
cursor: pointer;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
}
The final result looks like this:

 

Please note that border-radius actually is working only on Mozilla/Firefox, Google Chrome and Safari 3.

2.USE A CUSTOM BACKGROUND IMAGE
Start by creating a new .psd file with 78x28px size. From the left panel choose “Rounded Rectangle Tool” (ALT+U for Windows Users) and set a 4px radius.Fill it with #6e9e2d (green) color and apply some effects.

This is my result and also this is the Photoshop source file (please use it as you wish).

Download Photoshop FREE source file

 

Now, back to our code ….this image is 78x28px and we will use it as background image for our input.Here you have the new css code for it.
Note that this time you don’t need to use the value attribute anymore.

#btn
{
background: url(test-button-2.png);
cursor: pointer;
width: 78px;
height: 28px;
display: block;
border: none;
}
That’s it, i hope you’ll find it useful!

IE7浮動圖層背景透明內容文字也透明的問題

在 IE 要讓容器有透明背景,但內容文字不透明的寫法,是在父容器設置 CSS:filter.opacity(50),而內層子容器上的 CSS:position 屬性設置為「absolute」或是「relative」這樣就可以達到透明背景不透明內容的效果。在正常的情況下 IE7 和 IE8 都可以運作的很好,但是當父容器是浮動圖層時(position:absolute)IE7 會背景和內容全都變透明,而IE8卻不會受到影響。

要解決 IE7 浮動圖層背景透明且文字內容也透明的問題,可以在浮動圖層裏加上一子容器。然後在新加上來的子容器上設置透明背景,而不像先前那樣直接在浮動圖層上設置透明背景。如此 IE7就不會有浮動圖層上背景和文字都透明的問題發生。

實作說明(請用IE7、IE8來比較差異)

一般狀況IE透明背景設定

文字不透明、背景透明

浮動圖層IE7透明背景設定

IE7 文字不透明、背景透明

IE8 文字不透明、背景透明

IE7 文字透明、背景透明

IE8 文字不透明、背景透明

看到了沒!!這些文字是在透明圖層的下面喔。

這是上面這些結果的 html 程式碼

<!--一般狀況IE透明背景設定-->
<div style="filter:alpha(opacity=50);background-color:green;width:200px;height:100px;">
<div style="position:relative;">文字不透明、背景透明</div>
</div>

<!--浮動圖層IE7透明背景設定-不直接在浮動圖層上設置透明背景,在加一層做透明圖-->層。
<div style="position:absolute;width:200px;height:100px;top:925px;">
<div style="filter:alpha(opacity=50);background-color:green;width:100%;height:100%;">
<div style="position:relative;">
<p>IE7 文字不透明、背景透明</p>
<p>IE8 文字不透明、背景透明</p>
</div>
</div>
</div>

<!--浮動圖層IE7透明背景設定-直接在浮動圖層上設置透明背景-->
<div style="filter:alpha(opacity=50);background-color:green;width:200px;height:100px;position:absolute;top:925px;left:280px;">
<div style="position:relative;">
<p>IE7 文字透明、背景透明</p>
<p>IE8 文字不透明、背景透明</p>
</div>
</div>

為什現在還是有人在使用 IE7 真是想不通,明明瀏覽器這麼多款可以選擇不什麼不換一換呢?

使用 PCRE 尋找指定的字串區塊,並將此區塊內特定的字串替換。

從 WordPress.com ‘s Blog 把文章匯出成xml檔案,匯出後就可以拿來匯入自已架的 WordPress 網站裏。這樣匯出匯入的步驟並不難,但是如果遇到文章內容包含[sourcecode lang="sh"]….[/sourcecode], 這類的程式語法標籤時,匯入自已架的 WordPress 後顯示出來的結果可能和我們預期的不一樣。

我們檢查匯出的XML檔案,可以發現[sourcecode]的標籤區塊雖然存在,但是它裏面包含的一些特殊符號,已經被轉換成 html 的符號編碼(程式語法一定會包含需要Escapse的符號,例如“或是&、…)。
繼續閱讀