Home Web Front-end HTML Tutorial DIV CSS Summary Experience_html/css_WEB-ITnose

DIV CSS Summary Experience_html/css_WEB-ITnose

Jun 24, 2016 pm 12:32 PM

让你使用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 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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
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)

Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update? Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update? Mar 04, 2025 pm 12:32 PM

The official account web page update cache, this thing is simple and simple, and it is complicated enough to drink a pot of it. You worked hard to update the official account article, but the user still opened the old version. Who can bear the taste? In this article, let’s take a look at the twists and turns behind this and how to solve this problem gracefully. After reading it, you can easily deal with various caching problems, allowing your users to always experience the freshest content. Let’s talk about the basics first. To put it bluntly, in order to improve access speed, the browser or server stores some static resources (such as pictures, CSS, JS) or page content. Next time you access it, you can directly retrieve it from the cache without having to download it again, and it is naturally fast. But this thing is also a double-edged sword. The new version is online,

How do I use HTML5 form validation attributes to validate user input? How do I use HTML5 form validation attributes to validate user input? Mar 17, 2025 pm 12:27 PM

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

How to efficiently add stroke effects to PNG images on web pages? How to efficiently add stroke effects to PNG images on web pages? Mar 04, 2025 pm 02:39 PM

This article demonstrates efficient PNG border addition to webpages using CSS. It argues that CSS offers superior performance compared to JavaScript or libraries, detailing how to adjust border width, style, and color for subtle or prominent effect

What are the best practices for cross-browser compatibility in HTML5? What are the best practices for cross-browser compatibility in HTML5? Mar 17, 2025 pm 12:20 PM

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

What is the purpose of the <datalist> element? What is the purpose of the <datalist> element? Mar 21, 2025 pm 12:33 PM

The article discusses the HTML &lt;datalist&gt; element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

What is the purpose of the <progress> element? What is the purpose of the <progress> element? Mar 21, 2025 pm 12:34 PM

The article discusses the HTML &lt;progress&gt; element, its purpose, styling, and differences from the &lt;meter&gt; element. The main focus is on using &lt;progress&gt; for task completion and &lt;meter&gt; for stati

How do I use the HTML5 <time> element to represent dates and times semantically? How do I use the HTML5 <time> element to represent dates and times semantically? Mar 12, 2025 pm 04:05 PM

This article explains the HTML5 &lt;time&gt; element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

What is the purpose of the <meter> element? What is the purpose of the <meter> element? Mar 21, 2025 pm 12:35 PM

The article discusses the HTML &lt;meter&gt; element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates &lt;meter&gt; from &lt;progress&gt; and ex

See all articles