Home Web Front-end HTML Tutorial html+css基础知识点_html/css_WEB-ITnose

html+css基础知识点_html/css_WEB-ITnose

Jun 24, 2016 am 11:27 AM

以下是自己平时学习累计的,比较杂,欢迎大家指正和补充

一、css重置(css  reset)

这是我简单整理的,并不全,大家可以根据自己需要继续补充:

body,p,h1,h2,h3,h4,h5,h6,dl,dd{margin:0;font-size:12px;}
ol,ul{margin:0;padding:0;list-style:none;}
a{text-decoration:none;}
img{border:none;}

不用*{margin:0;padding:0;}是因为:div没有内外边距,p只有外边距问题没有内边距问题等等,性能问题也不好,大家可以自己写标签通过比如火狐的F12来看到元素的内外边距情况。

二、全屏遮罩

页面文档结构是:body

三、内嵌和块元素

内嵌元素:内容撑开宽度,不支持宽高,不支持margin和padding的上下边距,左右支持,代码换行被解析为空格(即并没有紧挨着在一排显示,而是每行显示一个那种情况)这种是被解析为一个空格的大小的间隙,是页面中文字大小的一半,比如body中设置为font-size为12px,则间隙为6像素
块属性标签:没有宽度时,默认撑满一排,支持宽高,支持所有css命令
img既不是内联也不是块,而是inline-block内联块元素
inline-block特性有:没有宽度的时候内容撑开宽度
ie6、ie7不支持块属性标签的inline-block(解决方案:用浮动)

四:cursor属性

cursor:url(xxx.cur),pointer;意思是:可以jpg、gif、png等,但可能有兼容性问题,最好用.cur格式,pointer意思是如果前面图片出问题出不来了,则使用pointer,相当于是个备用

五、浮动
1、不设置宽度情况下还是由内容撑开宽度

2、设置为浮动后则脱离了文档流

六、定位

定位:
1、绝对定位和浮动一样,使元素脱离了文档流,如果没设置宽度,则使块属性标签内容撑开宽度;
2、绝对定位使得内嵌元素支持宽高;
3、定位元素默认后者比前者的层级高(堆叠层次,但始终不到1),如需改变则使用z-index
4、fixed定位不设置宽度的话,可以让块元素内容撑开宽度,与绝对定位基本一致,的差别是始终相对整个文档进行定位,IE6不支持固定定位,可以通过js一起解决
5、在IE6下,父级的overflow:hidden是包不住设置为position:relative的子级的(这是当子元素高度高于父元素情况下,在一般情况下,设置为relative是对元素本身没影响的),那么要解决这个问题就是给父级加定位属性(相对或绝对定位都行)
6、在IE6下,如果定位元素的父级的宽高是奇数的话,那么该定位元素的right和bottom都有1像素的偏差,未找到较好的解决方案,则避免父元素宽高为奇数

七、清除浮动

1、给父级也加浮动,但父级还要父级怎么办?一层层加?扩展性不好,会导致:页面中所有元素都加浮动,margin左右自动失效(floats bad !),结论:不适用,放弃!!
2、给浮动元素的父级加display:inline-block,结论:不好,margin:0 auto失效!

3、给浮动元素后面加个空div,height:0px,但是在IE6下有个最小高度19px,但并不是所有元素都有最小元素,为了解决此问题,加个font-size:0;,但是也不能解决IE6下还剩2px的问题,(样式为:加个空div,class为clear,样式为:clear:both;font-size:0;height:0;)解决方案请听下回分解

4、给浮动元素后面加
,这个属性还有left、right等值,br是没有高度的,在br里的clear属性跟用clear:both作用是一样的,在ie6/7下都起作用了也省事,是可以用方案,但是,但是,不符合w3c标准:结构、样式、行为分离(写了个br标签,改结构了)
5、after伪类并不会改变文档结构,content:"内容内容"是不会改变结构的(通过F12可以看到,文档结构里的“内容内容”这几个字并不存在,但却可以在页面上显示出来,能看见),比如样式:p:after{content:"内容",background:red;width:10px;height:10px;}那么背景色变为红色的地方只会是“内容”,即这个content里的东西,p里面的文字背景色不会变化,并且宽和高也是对content里的东西起作用,不会影响p元素,但是在IE6/7下只支持a标签的那个4个伪类,不支持after伪类,但是没关系,因为在IE6/7下浮动元素的父级有宽度就不用清浮动,那不支持after伪类也没关系,为啥父级有宽度就不用清浮动了呢?这是因为在ie中有个haslayout的东西(不知道就百度百科)默认为false,有了width就能触发为true(哪些能触发去百度),haslayout会根据元素内容的大小或者父级的大小来重新计算元素高度,那么如果父级不给width怎么办呢?这时候就用zoom:1(百度百科里提到zoom除了normal外的值能激发haslayout为true),zoom有放大、缩小效果,所以一般这样用:给浮动元素的父级.clear{zoom:1};.clear:after{conetent:"";display:block;clear:both;}(前者解决ie6/7下的清浮动,后者解决其他浏览器下的清浮动),现在都是推崇这种清浮动方法,推荐、推荐!!
6、overflow可以包含着浮动元素,所以overflow可以制造清浮动假象,是加给浮动元素的父级的,此方法也可用,但是在IE6下有问题:因为overflow没有把元素提升层级的功能,那么配合zoom:1使用,可以激发haslayout,此方法还是少用,可能会隐藏本来应该显示出来的内容,推荐用第5种方法。

注意:clear这个属性只能加给块元素,对于内嵌是不起作用的!!

 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1668
14
PHP Tutorial
1273
29
C# Tutorial
1256
24
HTML: The Structure, CSS: The Style, JavaScript: The Behavior HTML: The Structure, CSS: The Style, JavaScript: The Behavior Apr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The Future of HTML, CSS, and JavaScript: Web Development Trends The Future of HTML, CSS, and JavaScript: Web Development Trends Apr 19, 2025 am 12:02 AM

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

The Future of HTML: Evolution and Trends in Web Design The Future of HTML: Evolution and Trends in Web Design Apr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

HTML vs. CSS vs. JavaScript: A Comparative Overview HTML vs. CSS vs. JavaScript: A Comparative Overview Apr 16, 2025 am 12:04 AM

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTML: Building the Structure of Web Pages HTML: Building the Structure of Web Pages Apr 14, 2025 am 12:14 AM

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

HTML vs. CSS and JavaScript: Comparing Web Technologies HTML vs. CSS and JavaScript: Comparing Web Technologies Apr 23, 2025 am 12:05 AM

HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

HTML: Is It a Programming Language or Something Else? HTML: Is It a Programming Language or Something Else? Apr 15, 2025 am 12:13 AM

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

From Text to Websites: The Power of HTML From Text to Websites: The Power of HTML Apr 13, 2025 am 12:07 AM

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

See all articles