HTML标签CSS默认值研究

摘要:
如果设置了*{margin:0;padding:0;},则在需要使用边距时需要恢复HTML默认CSS值。除了内联和块的定义外,还应注意body |h1~h6|blockquote|menu|ul|ol|dd和其他标签的默认样式。

   最近写css的时候,发现在div元素里面添加ul元素后发现,ul列表在div里面距离最上方总是有一段空行,当时很奇怪,以为是哪个css出了问题,就把css去掉了,发现问题依旧,然后就查了一下发现html标签在不同浏览器里面是有默认的css样式的,要去掉默认样式,在样式表里添加 *{margin:0;padding:0;}即可,同时找到一个很有用的文档

<<HTML标签CSS属性默认值汇总>>,这个东西,在你需要还原默认值的时候,比较有用。

如果设置了 *{margin:0;padding:0;},当需要使用边距的时候,就需要还原HTML默认CSS值了。

除了inline和block的定义,主要是要注意body|h1~h6|blockquote|menu|ul|ol|dd等标签的默认样式(margin和font-size)。

html, address,
blockquote,
body, dd, div,
dl, dt, fieldset, form,
frame, frameset,
h1, h2, h3, h4,
h5, h6, noframes,
ol, p, ul, center,
dir, hr, menu, pre   { display: block }
li              { display: list-item }
head            { display: none }
table           { display: table }
tr              { display: table-row }
thead           { display: table-header-group }
tbody           { display: table-row-group }
tfoot           { display: table-footer-group }
col             { display: table-column }
colgroup        { display: table-column-group }
td, th          { display: table-cell; }
caption         { display: table-caption }
th              { font-weight: bolder; text-align: center }
caption         { text-align: center }
body            { margin: 8px; line-height: 1.12 }
h1              { font-size: 2em; margin: .67em 0 }
h2              { font-size: 1.5em; margin: .75em 0 }
h3              { font-size: 1.17em; margin: .83em 0 }
h4, p,
blockquote, ul,
fieldset, form,
ol, dl, dir,
menu            { margin: 1.12em 0 }

h5              { font-size: .83em; margin: 1.5em 0 }
h6              { font-size: .75em; margin: 1.67em 0 }
h1, h2, h3, h4,
h5, h6, b,
strong          { font-weight: bolder }
blockquote      { margin-left: 40px; margin-right: 40px }
i, cite, em,
var, address    { font-style: italic }
pre, tt, code,
kbd, samp       { font-family: monospace }
pre             { white-space: pre }
button, textarea,
input, object,
select          { display:inline-block; }
big             { font-size: 1.17em }
small, sub, sup { font-size: .83em }
sub             { vertical-align: sub }
sup             { vertical-align: super }
table           { border-spacing: 2px; }
thead, tbody,
tfoot           { vertical-align: middle }
td, th          { vertical-align: inherit }
s, strike, del  { text-decoration: line-through }
hr              { border: 1px inset }
ol, ul, dir,
menu, dd        { margin-left: 40px }
ol              { list-style-type: decimal }
ol ul, ul ol,
ul ul, ol ol    { margin-top: 0; margin-bottom: 0 }
u, ins          { text-decoration: underline }
br:before       { content: ”A” }
:before, :after { white-space: pre-line }

center          { text-align: center }
abbr, acronym   { font-variant: small-caps; letter-spacing: 0.1em }
:link, :visited { text-decoration: underline }
:focus          { outline: thin dotted invert }


BDO[DIR="ltr"]  { direction: ltr; unicode-bidi: bidi-override }
BDO[DIR="rtl"]  { direction: rtl; unicode-bidi: bidi-override }

*[DIR="ltr"]    { direction: ltr; unicode-bidi: embed }
*[DIR="rtl"]    { direction: rtl; unicode-bidi: embed }

@media print {
  h1            { page-break-before: always }
  h1, h2, h3,
  h4, h5, h6    { page-break-after: avoid }
  ul, ol, dl    { page-break-before: avoid

--------------------------------------------------------------------------------

同一个页面用多个id有什么影响


 

在样式表定义一个样式的时候,可以定义id也可以定义class,例如:

ID方法:#test{color:#333333},在页面中调用

内容

CLASS方法:.test{color:#333333},在页面中调用
内容

id一个页面只可以使用一次,class可以多次引用。

有网友问,id和class好象没什么区别,我在页面中用了多个id在IE中显示也正常,用多个id有什么影响吗?

回答:第一影响就是不能通过W3的校验。

在页面显示上,目前的浏览器还都允许你犯这个错误,用多个相同ID“一般情况下”也能正常显示。但是当你需要用JavaScript通过id来控制这个div,那就会出现错误。

id是一个标签,用于区分不同的结构和内容,就象你的名字,如果一个屋子有2个人同名,就会出现混淆;
class是一个样式,可以套在任何结构和内容上,就象一件衣服;
概念上说就是不一样的:
id是先找到结构/内容,再给它定义样式;class是先定义好一种样式,再套给多个结构/内容。

web标准希望大家用严格的习惯来写代码,

例如:你可以用 显示粗体,也可以用 来显示,但W3C 建议大家用,因为更有语义

浏览器默认样式

1.页边距
IE默认为10px,通过body的margin属性设置
FF默认为8px,通过body的padding属性设置
要清除页边距一定要清除这两个属性值
body {
   margin:0;
   padding:0;
}

2.段间距
IE默认为19px,通过p的margin-top属性设置
FF默认为1.12em,通过p的margin-bottom属性设
p默认为块状显示,要清除段间距,一般可以设置
p {
   margin-top:0;
   margin-bottom:0;
}

3.标题样式
h1~h6默认加粗显示:font-weight:bold;。
默认大小请参上表
还有是这样的写的
h1 {font-size:xx-large;}
h2 {font-size:x-large;}
h3 {font-size:large;}
h4 {font-size:medium;}
h5 {font-size:small;}
h6 {font-size:x-small;}
个大浏览器默认字体大小为16px,即等于medium,h1~h6元素默认以块状显示字体显示为粗体,
要清除标题样式,一般可以设置
hx {
   font-weight:normal;
   font-size:value;
}

4.列表样式
IE默认为40px,通过ul、ol的margin属性设置
FF默认为40px,通过ul、ol的padding属性设置
dl无缩进,但起内部的说明元素dd默认缩进40px,而名称元素dt没有缩进。
要清除列表样式,一般可以设置
ul, ol, dd {
   list-style-type:none;
   margin-left:0;
   padding-left:0;
}

5.元素居中
IE默认为text-align:center;
FF默认为margin-left:auto;margin-right:auto;

6.超链接样式
a 样式默认带有下划线,显示颜色为蓝色,被访问过的超链接变紫色,要清除链接样式,一般可以设置
a {
   text-decoration:none;
   color:#colorname;
}

7 鼠标样式
IE默认为cursor:hand;
FF默认为cursor:pointer;。该声明在IE中也有效

8 图片链接样式
IE默认为紫色2px的边框线
FF默认为蓝色2px的边框线
要清除图片链接样式,一般可以设置
img {
   border:0;
}

免责声明:文章转载自《HTML标签CSS默认值研究》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇原生java api操作ES数据库layui 时间框选择一闪就消失,打不开问题解决办法下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

font-size:0; 消除空白间隙

使用font-size:0解决设置inline-block引起的空白间隙问题 一、空白间隙问题 在进行页面布局的时候为了页面代码所谓整洁刻度,往往会设置缩进或是换行,但是元素display为inline-block或是inline时,行内元素虽然没有设置  margin值,这些换行或是缩进。还是会出现空白间隙。 如下所示: HTML部分 <div i...

flutter 页面跳转1

import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return Ma...

网页设计太麻烦?15款免费优质Bootstrap UI工具包助你效率倍增!

Bootstrap作为针对响应式设计和移动优先的前端web开发,是当下最流行的设计框架之一。使用 免费的Bootstrap UI工具包让原型设计和网页设计变得更加简单。 摹客的小伙伴们为大家整理了一批使用Bootstrap构建的免费UI工具包,你可以将其用作设计的起点。为方便大家学习,今天为大家分享的这些UI工具包主要从以下几个方面分类: Bootstr...

js中动态载入css js样式

js中动态载入css样式,方法如下: //<link rel="stylesheet" type="text/css" href="http://t.zoukankan.com/http://css.static.m1905.cn/base.min.css"> var addCssLink =function(url){ var lin...

黑金社区 FPGA 那些事儿--Verilog 建模设计 学习 试验九 VGA显示 试验

最近这段时间忙着搬家,然后准备生产相关事情,各种杂事~ 然后光棍节来,给自己和老爸老妈买点东西。。。 效率好低。。要检讨啊~ 不能找借口! 黑金的试验九 --VGA的用法 VGA 液晶显示 主要由5个信号控制 HSYNC : 列同步信号 VSYNC : 行同步信号 RED : 红分量 GREEN : 绿分量 BLUE : 蓝分量 VGA 的扫描是固定的。一...

利用CSS三角形实现的冒泡框

请用CSS实现如下图的样式,相关尺寸如图示,其中dom结构为:<div id=”demo”></div> 这是一道去年的百度笔试题。 涉及定位、三角形、伪元素。 下面是我的解答以及一些知识概述,都在程序里了。 <!DOCTYPE html> <html lang="en"> <head>...