CSS中属性position位置详解功能讲解与实例分析_html/css_WEB-ITnose

WBOY
Freigeben: 2016-06-24 11:38:37
Original
1127 Leute haben es durchsucht

position有五个值:static、relative、absolute、fixed、inherit。

static

是默认值。就是按正常的布局流从上到下从左到右布局,平常我们做网页制作时,没有指定 position,也就表示使用 static。

relative

没有脱离布局流,此时可以使用 top、right、bottom、left 属性。

top 和 bottom 共存时,使用 top 值,忽略 bottom 值;

left 和 right 共存时,使用 left 值,忽略 right 值;

relative 是相对位置,指相对于元素的 position 为 static 时的位置:

top 相对于 static 下移多少像素(若 top 是负值,则上移)。

right 相对于 static 左移多少像素(若 right 是负值,则右移)。

bottom 相对于 static 上移多少像素(若 bottom 是负值,则下移)。

left 相对于 static 右移多少像素(若 left 是负值,则左移)。

使用 relative 之后:

原来的空间不会被其他元素挤占。

元素在最终位置时也不会挤占其他元素的空间,它浮动到其它元素的上方。

absolute

脱离布局流,此时可以使用 top、right、bottom、left,但这些属性不再是相对于 static 时的位置,而是相对于 containing block 的,相对于其边框内边缘的,而不是其 padding 内边缘。

使用 absolute 之后:

原来的空间会被其他元素挤占。

元素在最终位置时也不会挤占其他元素的空间,它浮动到其它元素的上方。

fixed

它的模式与 absolute 相同,不过无论怎么拖动滚动条,它始终固定在屏幕的指定位置。在 IE6 中不支持这个属性;在 IE7 中支持这个属性但需要指明 DOCTYPE;Firefox 等浏览器支持这个属性。

top、right、bottom、left 属性指相对于视口的。

inherit

继续父元素的 position 值。

名称解释

视口-通过解析文档,连续媒体(比如屏幕就是连续媒体,而打印机则是基于页的媒体)给用户产生一个视口(一个窗口或其它在屏幕上显示的区域)。

Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!