Table of Contents
传送门:JavaScript权威设计--CSS(简要学习笔记十六)
Home Web Front-end HTML Tutorial css权威指南-基本视觉格式化(水平与垂直)_html/css_WEB-ITnose

css权威指南-基本视觉格式化(水平与垂直)_html/css_WEB-ITnose

Jun 24, 2016 am 11:31 AM

1.基本概念

    (1)正常流:是指西方语言文本从左向右,从上向下显示。如果要让一个元素不在正常流中国,唯一的办法

                    就是使之成为浮动或定位元素。

    (2)非替换元素:如果元素的内容包含在文档中,则称之为非替换元素。

    (3)替换元素:指用作为其他内容占位符的一个元素。例子:img中的图像

    (4)块级元素:在正常流中,会在其框之前和之后生成“换行”

                        所以出于正常流中的块级元素会垂直摆放。

    (5)行内元素:不会再之前或之后生成行分隔符,它们是块级元素的后台。

    (6)根元素:位于文档树顶端的元素。在HTML中,就是元素HTML。

 

2.水平格式化

通常我们指的元素的宽度,指的是其内容的宽度,不包括内补,外补,边。

传送门:JavaScript权威设计--CSS(简要学习笔记十六)

水平格式化的七大属性:margin-left,border-left,padding-left,width,padding-right,border-right,margin-left

这七个水平属性的总和要等于父元素的width。

这里面只有width,margin-left,margin-left这三个可以设置为:auto

其他都必须设为特定的值或者默认宽度为0.

 

下面就以这三个auto的组合来展现问题:auto会自动补齐宽度(屏幕总宽度1366)

    设置margin-left为auto:    

<p style="margin-left:auto;width:100px;margin-right: 100px">水平格式化</p>
Copy after login

设置margin-right为auto:

<p style="margin-left:100px;width:100px;margin-right: auto">水平格式化</p>
Copy after login

Copy after login
Copy after login
Copy after login
Copy after login

设置width为auto:

<p style="margin-left:100px;width:auto;margin-right: 100px">水平格式化</p>
Copy after login

Copy after login
Copy after login
Copy after login
Copy after login

设置margin-left和margin-right为auto:

<p style="margin-left:auto;width:100px;margin-right: auto">水平格式化</p>
Copy after login

Copy after login
Copy after login
Copy after login
Copy after login

设置margin-left和margin-right和width都为auto:

<p style="margin-left:auto;width:auto;margin-right: auto">水平格式化</p>
Copy after login

设置margin-left和margin-right和width都不为auto:

<p style="margin-left:100px;width:100px;margin-right: 100px">水平格式化</p>
Copy after login

下面会遇到一种复杂特殊奇怪的现象:那就是外边距可以是负值

<div style="width:400px;border:2px solid red">    <p style="margin-left:10px;width: auto;margin-right: -50px;">zqzqzq</p></div>
Copy after login


可以看出来宽度是440(width;auto这里440是实时计算的值,而不是显示的指定的值,

其实这里涉及到一个问题:有些是实时计算的值,有些DOM可以获取实时计算的值。),比父400还要宽!说好的不能比父元素宽呢?

但是这个计算没有错误:

10+0+0+440+0+0-50=400

最终还是等于400。

前面说的都是费替换元素的水平格式化,下面来说替换元素的水平格式化。( 典型的替换元素就是img

示例图片:w:200px,h:300px.

当我们改变她的宽度的时候,高度也同比例改变。

200x300

300x450

3.垂直格式化

一个元素的默认高度由其内容决定。

高度还会受到内容宽度的影响。

段落越窄,相应的就会越高,以便容纳其中所有的内联内容。

对应于水平格式化,它也有7个属性:

margin-top,border-top,padding-top,height,padding-bottom,border-bottom,margin-bottom.

同样这七个值必须等于包含元素块的高。

这七个值中只有三个值可以设为auto:height,margin-top,margin-bottom,其他四个必须设为特定的值或默认为0.

当高度小于显示内容的高度:浏览器会处理为有个滚动条(overflow),以容纳下内联元素。

垂直格式化的另一个重要的是合并垂直外边距(重叠垂直外边距)

<ul>    <li>大师兄</li>    <li>师傅</li>    <li>被妖怪</li>    <li>抓走啦</li>    <li>俺老孙来也</li></ul>li{ margin-top: 10px; margin-bottom: 15px; 
Copy after login

Copy after login
Copy after login
Copy after login
Copy after login

相邻列表之间的距离是15px,不是25px。

因为相邻的外边距沿着垂直方向合并了,大边距覆盖小边距。

 

 

 

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 尊渡假赌尊渡假赌尊渡假赌
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
1664
14
PHP Tutorial
1269
29
C# Tutorial
1248
24
Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

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.

The Role of HTML: Structuring Web Content The Role of HTML: Structuring Web Content Apr 11, 2025 am 12:12 AM

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and 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.

See all articles