我打算使用 Eric Meyer 的 CSS 重置,但我偶然发现了一些跨浏览器的差异(如input
边距)。在此基础上,我想出了一个更激进的方法:
(这个已经过时了。别忘了在这个问题的最后检查当前的修订版本,并随意批评它)
/* CSS Reset by Hugo Leonardo. Based on Eric Meyer's CSS Reset (just google it). */
* {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font: inherit;
text-decoration: none;
/* in case "font: inherit" fails (IE7) */
font-family: "times new roman";
font-size: 100%;
font-style: normal;
font-variant: normal;
font-weight: normal;
/* remove this block if you DON'T want to support lame browsers */
}
:before, :after {
content: '';
}
:link, :visited, :hover, :active {
color: inherit;
color: #000; /* for IE7 'inherit' problem (again) */
text-decoration: none;
}
:focus {
outline: 0;
}
ol li, ul li {
list-style: none;
}
table {
/* "collapse" here is because of IE7 (maybe others?). don't remove it as it affects other browsers as well */
border-collapse: collapse;
border-spacing: 0;
}
/* this entire block was copied from Eric Meyer's CSS reset */
/* HTML5 "display" reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
它在所有经过测试的浏览器中都能正常运行:
- IE7
- IE8
- 铬(最新)
- 火狐(最新)
- 歌剧(最新)
问题是:有人看到这里有什么问题吗?我认为自己在 CSS 方面不太好,所以我不知道这是否会给我带来任何麻烦。
观察:此重置仅适用于跨浏览器问题。它应该(或必须!)遵循诸如input
、a
、等元素的通用规则code
(例如:input
“文本”类型将是不可见的,没有边框!)。稍后我将添加诸如通用a
样式之类的东西。现在我正在重置东西,摆脱(几乎)所有在主要浏览器中不一样的东西。
到目前为止发现的问题
选择
*
器可能会导致性能问题。具有某些规则的
*
选择器会以无法恢复的方式覆盖某些元素的默认样式。input
例如: “提交”类型的默认样式。令人惊讶的
:before, :after { content: ''; }
是,它破坏了 Firefox 中的选择元素。在修订版中,我尝试设置
margin: 0
为所有输入元素。大多数浏览器在输入类型checkbox
和radio
.
经过修改的版本
/* CSS Reset by Hugo Leonardo Leão Mota
Based on Eric Meyer's CSS Reset: http://meyerweb.com/eric/thoughts/2011/01/03/reset-revisited/
Helped by fellows in stackoverflow: http://stackoverflow.com/questions/6892982/is-this-css-reset-okay */
/* resetting style for every visible element except 'ruby' family and form controls
browsers deal with controls (and ruby style) in their own way */
a, abbr, acronym, address, b, big, blockquote, body,
br, caption, cite, code, col, colgroup, dd, del, dfn, div,
dl, dt, em, fieldset, form, h1, h2, h3, h4, h5, h6, hr, html, i,
img, ins, kbd, label, legend, li, noscript, object, ol, p, pre, q, samp,
small, span, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, ul, var {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font: inherit;
text-decoration: none;
/* in case "font: inherit" fails (IE7) */
font-family: "times new roman";
font-size: 100%;
font-style: normal;
font-variant: normal;
font-weight: normal;
/* remove this block if you DON'T want to support lame browsers */
}
/* browsers are free to handle controls but
we can't let them mess up with the other elements */
button, select, textarea,
input[type=text], input[type=password], input[type=submit],
input[type=image], input[type=reset], input[type=button], input[type=file] {
margin: 0;
}
:link, :visited, :hover, :active {
color: inherit;
color: #000; /* for IE7 'inherit' problem (again) */
text-decoration: none;
}
:focus {
outline: 0;
}
ol li, ul li {
list-style: none;
}
table {
/* "border-collapse" here is because of IE7 different behaviour (maybe others?).
don't remove it as it affects other browsers as well */
border-collapse: collapse;
border-spacing: 0;
}
/* the next two blocks were copied from Eric Meyer's CSS reset */
blockquote:before, blockquote:after, q:before, q:after {
content: '';
}
/* HTML5 "display" reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
结尾
好吧,我越是尝试改进我的重置,它看起来越像meyer 的 css 重置,所以我放弃了我的并采用了它。工作得很好:p