Home Backend Development PHP Tutorial 韩顺平_php从入门到精通_视频教程_第19讲_网站推荐_定位_学习札记_源代码图解_PPT文档整理

韩顺平_php从入门到精通_视频教程_第19讲_网站推荐_定位_学习札记_源代码图解_PPT文档整理

Jun 13, 2016 pm 01:05 PM
div gt lt quot

韩顺平_php从入门到精通_视频教程_第19讲_网站推荐_定位_学习笔记_源代码图解_PPT文档整理
书再多,视频再多,都不如自己动手写一个项目,就会有心得。
对于开源项目,跑起来,看懂,并二次修改。模仿 -------->创新,抓核心。

CSS核心内容――定位
定位―基本概念
CSS定位(Positioning)属性允许你对元素进行定位。Positioning属性值:
static(默认值):元素框正常生成。块级元素生成一个矩形框,作为文档流/标准流的一部分,行内元素则会创建一个或多个行框,置于其父元素中。
relative:元素框偏离某个距离。元素仍保持其为定位前的形状,它原本所占的空间仍保留,从这一角度看,好像该元素仍然在文档流/标准流一样。
absolute:元素框从文档流完全删除,并相对于其包含块定位。包含块可能是文档中的另一个元素或者是初始包含块。元素原先在正常文档流中所占的空间会关闭,就好像元素原来不存在一样。元素定位后生成一个块级框,而不论原来它在正常流中生成何种类型的框。
fixed:元素框的表现类似于将position设置为absolute,不过其包含块是视窗本身。

这几个定位,真正要搞明白,并不是特别容易的事情,借助案例来明白。
常见的定位有四种
1.stacit 定位(默认值)
2.relative相对定位(相对谁)
3.absolute 绝对定位(相对于谁参照呢)
4.fixed固定定位


(1)静态定位不讲了,前面讲的都是静态定位。



(2)定位――相对定位:relative

内容2虽然脱离了它原有的文档流,但是它的位置不希望被别人占用。我走了,但是位置还是我的,停薪留职。

改变内容2位置
relative相对谁呢,相对它原先应该在的位置,进行重新定位。

这里我们可以看出,所谓相对定位是指,相对该元素应当显示的左上角重新定位,虽然它脱离了标准流,但是它的空间,不能被占用。

relative.html


	
		<link rel="stylesheet" type="text/css" href="relative.css">
		<title>relative 相对定位</title>
	
	
		<div class="div1">内容1</div>
		<div class="div1" id="spe">内容2</div>
		<div class="div1">内容3</div>
		<div class="div1">内容4</div>
	
Copy after login

relative.css

.div1{
	width: 70px;
	height: 30px;
	background: silver;
	float: left;
	margin-left: 5px;
}

#spe{
	position: relative;
	left: 40px;
	top: 100px;
}
Copy after login

(3)定位――绝对定位absolute



===

从上图看,所谓绝对定位是指,对该元素最近的那个脱离了标准流的元素定位,如果没有父元素(或者有父元素,但是父元素没有脱离标准流),则相对body左上角定位。

绝对定位,究竟是对哪个点定位。

absolute.html


	
		<link rel="stylesheet" type="text/css" href="absolute.css">
		<title>绝对定位</title>
	
	
		<div class="div1">内容1</div>
		<div class="div1" id="spe">内容2</div>
		<div class="div1">内容3</div>
		<div class="div1">内容4</div>
	
Copy after login

absolute.css

*{
	margin: 0px;
	padding: 0px;
}

.div1{
	width: 70px;
	height: 30px;
	background: silver;
	float: left;
	margin-left: 5px;
}

#spe{
	position: absolute; /*绝对定位(究竟对谁)*/
	left: 40px; /*left为正,则向右移动*/
	top: 100px; /*top为正,则向下移动*/
}
Copy after login


用一个div把内容2包起来,重点讲解“对该元素最近的那个脱离了标准流的元素定位”

absolute2.html


	
		<link rel="stylesheet" type="text/css" href="absolute2.css">
		<title>绝对定位2</title>
	
	
		<div class="div1">内容1</div>
		<div class="div1">内容3</div>
		<div class="div1">内容4</div>
		<div class="div2">测试
			<div class="div1" id="spe">内容2</div>	
		</div>
	
Copy after login

absolute2.css

*{
	margin: 0px;
	padding: 0px;
}

.div1{
	width: 70px;
	height: 30px;
	background: silver;
	float: left;
	margin-left: 5px;
}

#spe{
	position: absolute;/*绝对定位(究竟对谁)*/
	left: 40px; /*left为正,则向右移动*/
	top: 100px; /*top为正,则向下移动*/
}

.div2{
	width: 200px;
	height: 150px;
	background: pink;
	float: left;
}
Copy after login

(1)把内容2被div2包起来,并把原来的内容2删除,则如下图所示,代码如上。因为div2还是标准流,所以内容2还是相对body左上角定位。
(2)让div2脱离标准流,则显示如下图所示。那么内容2不再按照body来定位,而是按照包含它的div2来进行定位,因为div2是距离内容2最近的脱离了标准流的元素。“对该元素最近的那个脱离了标准流的元素定位”

相应的div2的css属性修改如下

.div2{
	position: relative;
	left: 100px;
	top: 100px;
	width: 200px;
	height: 150px;
	background: pink;
	float: left;
}
Copy after login
动手操作就明白。



(4)定位――fixed定位(绝绝对对)
把内容2修改为绝对定位,则显示如下图所示。不管谁包我还是不包我,我永远对视窗的左上角,body的左上角定位,绝绝对对。

相应的内容2的css属性修改如下
#spe{
	/*position: absolute;*/ /*绝对定位(究竟对谁)*/
	position: fixed;
	left: 40px; /*left为正,则向右移动*/
	top: 100px; /*top为正,则向下移动*/
}
Copy after login

所谓fixed定位就是不管怎样,总是以视窗的左上角定位。


注意:left和top对static没有效果的,★★★static静态定位的左右移动用的margin★★★


z-index
设置对象的层叠顺序

z-index的值越小,越在下面

用于设置对象(div)显示时候,层叠的属性,z-index值越小,则越在下层显示。


 韩顺平_php从入门到精通_视频教程_学习笔记_源代码图解_PPT文档整理_目录

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
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 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)

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Fix: Snipping tool not working in Windows 11 Fix: Snipping tool not working in Windows 11 Aug 24, 2023 am 09:48 AM

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

How to Fix Can't Connect to App Store Error on iPhone How to Fix Can't Connect to App Store Error on iPhone Jul 29, 2023 am 08:22 AM

Part 1: Initial Troubleshooting Steps Checking Apple’s System Status: Before delving into complex solutions, let’s start with the basics. The problem may not lie with your device; Apple's servers may be down. Visit Apple's System Status page to see if the AppStore is working properly. If there's a problem, all you can do is wait for Apple to fix it. Check your internet connection: Make sure you have a stable internet connection as the "Unable to connect to AppStore" issue can sometimes be attributed to a poor connection. Try switching between Wi-Fi and mobile data or resetting network settings (General > Reset > Reset Network Settings > Settings). Update your iOS version:

How to use css to realize that a div is missing a corner How to use css to realize that a div is missing a corner Jan 30, 2023 am 09:23 AM

CSS method to realize that a div is missing a corner: 1. Create an HTML sample file and define a div; 2. Set the width and height background color for the div; 3. Add a pseudo class to the div that needs to delete a corner, and set the pseudo class to Use the same color as the background color, then rotate it 45 degrees, and then position it to the corner that needs to be removed.

Implementation of word-marking translation browser script based on ChatGPT API Implementation of word-marking translation browser script based on ChatGPT API May 01, 2023 pm 03:28 PM

Preface Recently, there is a browser script based on ChatGPTAPI on GitHub, openai-translator. In a short period of time, the star has reached 12k. In addition to supporting translation, it also supports polishing and summarizing functions. In addition to browser plug-ins, it also uses tauri packaging. If you have a desktop client, aside from the fact that tauri uses the rust part, the browser part is still relatively simple to implement. Today we will implement it manually. The interface provided by openAI, for example, we can copy the following code and initiate a request in the browser console to complete the translation //Example constOPENAI_API_KEY="s

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

What are the differences between div and span? What are the differences between div and span? Nov 02, 2023 pm 02:29 PM

The differences are: 1. div is a block-level element, and span is an inline element; 2. div will automatically occupy a line, while span will not automatically wrap; 3. div is used to wrap larger structures and layouts, and span is used to wrap Text or other inline elements; 4. div can contain other block-level elements and inline elements, and span can contain other inline elements.

What is the div box model What is the div box model Oct 09, 2023 pm 05:15 PM

The div box model is a model used for web page layout. It treats elements in a web page as rectangular boxes. This model contains four parts: content area, padding, border and margin. The advantage of the div box model is that it can easily control the layout of the web page and the spacing between elements. By adjusting the size of the content area, inner margin, border and outer margin, various layout effects can be achieved. The box model also provides some Properties and methods can dynamically change the style and behavior of the box through CSS and JavaScript.

See all articles