Archive

Archive for the ‘Css’ Category

CSS Background-Position: left right center top buttom属性的解释

May 16th, 2012 Tony hu No comments

1.background-position:left top;

背景图片的左上角和容器(container)的左上角对齐,超出的部分隐藏。

等同于 background-position:0,0;

也等同于background-position:0%,0%;

2.background-position:right bottom;

背景图片的右下角和容器(container)的右下角对齐,超出的部分隐藏。

等同于background-positon:100%,100%;

也等同于background-positon:容器(container)的宽度-背景图片的宽度,容器(container)的高度-背景图片的高度

3.background-position:500px 15px;

背景图片从容器(container)左上角的地方向右移500px,向下移15px,超出的部分隐藏。

4.background-position:-500px -15px;

背景图片从容器(container)左上角的地方向左移500px,向上移15px,超出的部分隐藏。

5.background-position:50% 50%;这句经常让新手出错!

等同于left:{容器(container)的宽度—背景图片的宽度}*left百分比,超出的部分隐藏。

等同于right:{容器(container)的高度—背景图片的高度}*right百分比,超出的部分隐藏。

例如:background-position:50% 50%;就是background-position:(1000-2000)*50%px,(500-30)*50%px;即background- position:-500px,235px;也就是背景图片从容器(container)的左上角向左移500px,向下移235px;

6.(这种情况背景图片应该用bg2.jpg才能看出效果,bg.jpg的高度太小效果不明显)

background-position:-50% -50%;

等同于left:-{{容器(container)的宽度—背景图片的宽度}*left百分比(百分比都取正值)},超出的部分隐藏。

等同于right:-{{容器(container)的高度—背景图片的高度}*right百分比(百分比都取正值)},超出的部分隐藏。

例如:background-position:-50% -50%;就是background-position:-{(1000-500)*50%}px,-{(500-360)*50%}px;即 background- position:-250px,-70px;也就是背景图片从容器(container)的左上角向左移250px,向上移70px;

—————————————————

之前一直没有理解,今天终于搞明白了,强大的CSS啊。

转自 http://blog.csdn.net/yja886/article/details/7171135

Categories: Css Tags:

ie6中hover伪类的兼容性问题

April 11th, 2011 Tony hu No comments

在IE6中,因为只支持css1,而hover伪类在css1中只支持<a>标签使用,其他标签一概不接纳,今天我们就来破除这个可恶的规矩!

第一步
 
打开记事本,复制如下代码:
 
<attach event=”ondocumentready” handler=”parseStylesheets” />
<script>
/**
* Whatever:hover – V1.42.060206 – hover & active
* ————————————————————
* (c) 2005 – Peter Nederlof
* Peterned – http://www.xs4all.nl/~peterned/
* License – http://creativecommons.org/licenses/LGPL/2.1/
*
* Whatever:hover is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* Whatever:hover is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* Credits and thanks to:
* Arnoud Berendsen, Martin Reurings, Robert Hanson
*
* howto: body { behavior:url(“csshover.htc”); }
* ————————————————————
*/
var csshoverReg = /(^|\s)(([^a]([^ ]+)?)|(a([^#.][^ ]+)+)):(hover|active)/i,
currentSheet, doc = window.document, hoverEvents = [], activators = {
onhover:{on:’onmouseover’, off:’onmouseout’},
onactive:{on:’onmousedown’, off:’onmouseup’}
}
function parseStylesheets() {
if(!/MSIE (5|6)/.test(navigator.userAgent)) return;
window.attachEvent(‘onunload’, unhookHoverEvents);
var sheets = doc.styleSheets, l = sheets.length;
for(var i=0; i<l; i++)
parseStylesheet(sheets[i]);
}
function parseStylesheet(sheet) {
if(sheet.imports) {
try {
var imports = sheet.imports, l = imports.length;
for(var i=0; i<l; i++)
parseStylesheet(sheet.imports[i]);
} catch(securityException){}
}
try {
var rules = (currentSheet = sheet).rules, l = rules.length;
for(var j=0; j<l; j++) parseCSSRule(rules[j]);
} catch(securityException){}
}
function parseCSSRule(rule) {
var select = rule.selectorText, style = rule.style.cssText;
if(!csshoverReg.test(select) || !style) return;
var pseudo = select.replace(/[^:]+:([a-z-]+).*/i, ‘on$1′);
var newSelect = select.replace(/(\.([a-z0-9_-]+):[a-z]+)|(:[a-z]+)/gi, ‘.$2′ + pseudo);
var className = (/\.([a-z0-9_-]*on(hover|active))/i).exec(newSelect)[1];
var affected = select.replace(/:(hover|active).*$/, ”);
var elements = getElementsBySelect(affected);
if(elements.length == 0) return;
currentSheet.addRule(newSelect, style);
for(var i=0; i<elements.length; i++)
new HoverElement(elements[i], className, activators[pseudo]);
}
function HoverElement(node, className, events) {
if(!node.hovers) node.hovers = {};
if(node.hovers[className]) return;
node.hovers[className] = true;
hookHoverEvent(node, events.on, function() { node.className += ‘ ‘ + className; });
hookHoverEvent(node, events.off, function() { node.className = node.className.replace(new RegExp(‘\\s+’+className, ‘g’),”); });
}
function hookHoverEvent(node, type, handler) {
node.attachEvent(type, handler);
hoverEvents[hoverEvents.length] = {
node:node, type:type, handler:handler
};
}
function unhookHoverEvents() {
for(var e,i=0; i<hoverEvents.length; i++) {
e = hoverEvents[i];
e.node.detachEvent(e.type, e.handler);
}
}
function getElementsBySelect(rule) {
var parts, nodes = [doc];
parts = rule.split(‘ ‘);
for(var i=0; i<parts.length; i++) {
nodes = getSelectedNodes(parts[i], nodes);
} return nodes;
}
function getSelectedNodes(select, elements) {
var result, node, nodes = [];
var identify = (/\#([a-z0-9_-]+)/i).exec(select);
if(identify) {
var element = doc.getElementById(identify[1]);
return element? [element]:nodes;
}
var classname = (/\.([a-z0-9_-]+)/i).exec(select);
var tagName = select.replace(/(\.|\#|\:)[a-z0-9_-]+/i, ”);
var classReg = classname? new RegExp(‘\\b’ + classname[1] + ‘\\b’):false;
for(var i=0; i<elements.length; i++) {
result = tagName? elements[i].all.tags(tagName):elements[i].all;
for(var j=0; j<result.length; j++) {
node = result[j];
if(classReg && !classReg.test(node.className)) continue;
nodes[nodes.length] = node;
}
}
return nodes;
}
</script>
 
然后保存为hover.htc
 
 
第二步
 
在css文件中插入一条【注意htc文件的路径】:
 
body { behavior: url(“hover.htc”) }
 
完成!
 
现在进去看看,是不是li:hover  、 p:hover 都能起效果了呢?好了,尽管发挥吧!有问题?
Categories: Asp, Css, Web standard Tags:

中华家教吧官网首页标准化验证Passed

October 27th, 2009 Tony hu No comments

这两在做中华家教吧页面的web standard validation.

终于成功了,演示地址: http://www.zhjj8.com/

CSS也验证到了CSS 2.1版本。

时间主要浪费在:

  1. 要将网址链接中的“&”改成“&amp;” 才可以。
  2. 所有HTML都要小写
  3. 所有HTML的标签的属性的值都要加“”,如 width=”30px” 而不可以 width=30
  4. <img 标签需要有 alt ,就算是没有任何意义的,也需要改成 alt=”", 最好要合上标签 即  “/>

Read more…

Categories: Css, Myself, Tutor, Web standard Tags: , ,

推荐的 CSS 书写顺序

August 24th, 2009 Tony hu No comments
//显示属性
display
list-style
position
float
clear

//自身属性
width
height
margin
padding
border
background

//文本属性
color
font
text-decoration
text-align
vertical-align
white-space
other text
content
Categories: Css Tags:

CSS position

August 10th, 2009 Tony hu No comments

定义

position 属性把元素放置到一个静态的、相对的、绝对的、或固定的位置中。

例子

h1
  {
  position: absolute;
  left: 100px;
  top: 150px;
  }

可能的值

描述
static 默认。位置设置为 static 的元素,它始终会处于页面流给予的位置(static 元素会忽略任何 top、bottom、left 或 right 声明)。
relative 位置被设置为 relative 的元素,可将其移至相对于其正常位置的地方,因此 “left:20″ 将向元素的 LEFT 位置添加 20 个像素。
absolute 位置设置为 absolute 的元素,可定位于相对于包含它的元素的指定坐标。此元素的位置可通过 “left”、”top”、”right” 以及”bottom” 属性来规定。
fixed 位置被设置为 fixed 的元素,可定位于相对于浏览器窗口的指定坐标。此元素的位置可通过 “left”、”top”、”right” 以及”bottom” 属性来规定。不论窗口滚动与否,元素都会留在那个位置。工作于 IE7(strict 模式)。

其它&扩展

Z-index可被用于将在一个元素放置于另一元素之后。默认是0。
z-index:0; 表示一般的平级,即所有元素都在同一个平台上。
z-index:-1;表示此元素位于其它元素的下一层。
z-index:1;很显然,表示浮于其它元素之上。
Categories: Css Tags: ,