search
HomeWeb Front-endHTML TutorialDIV CSS Summary Experience_html/css_WEB-ITnose

让你使用DIV+CSS排版 不是让你用换个标签然后再去按照表格的方式去排版
而是做到内容与表现的分离
1: ID用于标识页面单独元素以及持久行的结构性元素 方便JS的调用
类用于标识同一页面可重复定义使用的结构性元素 ID与类的命名需与表现形式无关 :leftContent 而使用有意义的定义方式:sideBar等等。命名方式遵循“驼峰式大小写(标志符由多个单词组成 除首词首字母小写外 其余单词首字母均大写)”
2:避免滥用类 当类型的结构需要不一样的表现时 记得什么是层叠样式表 具体结构中的p a h1等可使用如下方式:div.sideBar p{}定义即后代选择器+ID或类选择器组合方式。
3:DIV与SPAN DIV(块级框)用于对块级元素的分组 SPAN(行内框)用于对行内元素分组标识
4:对于页面基本默认的方式可以选择通用选择器(*标识)进行定义 * { padding:0; margin:0;}
5: body 也是可以添加ID和类的 这样就可以为其添加特别样式。
6:样式表中导入样式表需在顶端 覆盖规则为本身样式覆盖导入样式
7:CSS样式表细分化 颜色 布局 风格 表单 均可分离 这样对以后的修改和风格设计更方便
8:盒模型:内→外
content←width height(补充:height只有在父元素定义了绝对高度时其%才有意义)
border
padding(内补丁)-“填充”
background-image
background-color
margin(外补丁)-“空白边”透明 可为负值
记住:在css中 width是指内容区域的宽度
IE/WIN与盒模型:
IE5.5/IE6怪异模式下: 元素框总宽度=content.width+margin.width
FireFox/Opera/..   :  元素框总宽度=content.width+padding.width+border.width+margin.width
差异在于:IE5.5/IE6怪异模式下 width=有效content.width+padding.width+border.width 内补丁和边框被算在内容宽度里面
#select{width:750px;padding:10px;border:5px} IE怪异模式:总宽度:750px FF/OP:780px
                                              IE怪异模式:有效内容宽度:750-20-10 FF/OP:750
IE6正常模式下:同于FF/OP
处理方法:在父元素或子元素中使用padding 本身不使用
空白边叠加:当两个空白边叠加时 顶或底边将会叠加 实际空白边高度=空白边大的值
例:


The height of the blank margin is 20px
But if you add a border or padding at this time, it will no longer be superimposed

//Positioning mechanism//
9: Relative positioning (relative): Absolute positioning relative to its default initial position: Relative to the parent element or canvas, HTML elements have nothing to do with the document flow and can cover other elements using Z-INDEX to control their hierarchy. When setting the right bottom under IE5.5/IE6, you need to set the width and height of the box and then position it according to the right bottom of the canvas
Absolute positioning (absolute)
10: float floating: Remember: "Float in standard browsers" Elements are separated from the document flow and do not occupy the surrounding container space." Once you understand this, you will understand why the performance is different between IE and FIREFOX. IE5.5 and IE6 floating elements still occupy the peripheral container space
For example: How can the feet be normal under IE but run up under Firefox? ^_^ Clear the float
Under IE, a double error occurs when float and text-align define the same direction: select{float:left;text-align:left;margin:0 10px;}
Actual left margin-left: 20px; FF/OP: 10px Solution: add display: inline;

11: Thoroughly understand "clear float" clear
clear: none, left, right, both,
Indicates which sides of the current box element should not be next to the floating box
After understanding the performance of float in different browsers in 10, you will know how to use it clearly.
12: Positioning of the background image: only talk about percentage background:url(image-url.gif)no-repeat 20% 30%
20%: Align 20% of the X-axis of the image with 20% of the X-axis of the parent element Top=0% bottom=100% left=0% right=100% center=50%
13: Sliding door/
The backgrounds of the two left and right DIVs are defined separately. Generally, the left background image is longer; Left background positioning: left center Right background positioning: right center
The width of the external control container is generally less than or equal to two backgrounds. In this way, when the content changes dynamically, the right background image feels like it is sliding on the left background image, hence the name.
This can also be achieved:
css:
#nav a{float:left;background:url("../images/navLeft.gif") no -repeat left top;padding:0;text-decoration:none; cursor:hand;}
#nav a span {float:left;display:block;background:url("../images/navRight.gif" ) no-repeat right top;padding:5px 36px 5px 40px;color:#ffffff}
The principles are similar, pay attention to the positioning of the background image.
14: The perfect central layout: Body {text-align: center; mini-width: 760px;}
DIV#Wrapper {margin: 0 Auto; text-align: left; width: 750px;}
mini-width IE does not know that this is for old browsers, but it is OK if this value is larger than the actual page you need

15: Small icons sometimes add a lot of color to the page. Remember to plan before using it. It’s better to fit it into one big picture, which can reduce the number of server requests

Statement
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
What is the difference between an HTML tag and an HTML attribute?What is the difference between an HTML tag and an HTML attribute?May 14, 2025 am 12:01 AM

HTMLtagsdefinethestructureofawebpage,whileattributesaddfunctionalityanddetails.1)Tagslike,,andoutlinethecontent'splacement.2)Attributessuchassrc,class,andstyleenhancetagsbyspecifyingimagesources,styling,andmore,improvingfunctionalityandappearance.

The Future of HTML: Evolution and TrendsThe Future of HTML: Evolution and TrendsMay 13, 2025 am 12:01 AM

The future of HTML will develop in a more semantic, functional and modular direction. 1) Semanticization will make the tag describe the content more clearly, improving SEO and barrier-free access. 2) Functionalization will introduce new elements and attributes to meet user needs. 3) Modularity will support component development and improve code reusability.

Why are HTML attributes important for web development?Why are HTML attributes important for web development?May 12, 2025 am 12:01 AM

HTMLattributesarecrucialinwebdevelopmentforcontrollingbehavior,appearance,andfunctionality.Theyenhanceinteractivity,accessibility,andSEO.Forexample,thesrcattributeintagsimpactsSEO,whileonclickintagsaddsinteractivity.Touseattributeseffectively:1)Usese

What is the purpose of the alt attribute? Why is it important?What is the purpose of the alt attribute? Why is it important?May 11, 2025 am 12:01 AM

The alt attribute is an important part of the tag in HTML and is used to provide alternative text for images. 1. When the image cannot be loaded, the text in the alt attribute will be displayed to improve the user experience. 2. Screen readers use the alt attribute to help visually impaired users understand the content of the picture. 3. Search engines index text in the alt attribute to improve the SEO ranking of web pages.

HTML, CSS, and JavaScript: Examples and Practical ApplicationsHTML, CSS, and JavaScript: Examples and Practical ApplicationsMay 09, 2025 am 12:01 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.

How do you set the lang attribute on the  tag? Why is this important?How do you set the lang attribute on the tag? Why is this important?May 08, 2025 am 12:03 AM

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

What is the purpose of HTML attributes?What is the purpose of HTML attributes?May 07, 2025 am 12:01 AM

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

How do you create a list in HTML?How do you create a list in HTML?May 06, 2025 am 12:01 AM

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.

See all articles

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

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools