網(wǎng)頁設(shè)計中的自動邊偏移

  • 2019-03-15 17:53:27
  • 閱讀次數(shù):
  • 作者:盈嵐科技小編
  • 來源:http://www.iy5y368.cn

網(wǎng)站建設(shè)中元素絕對定位時,如果除bottom外某個任意偏移屬性設(shè)置為auto,會有一種特殊的行為。下面以top為例,考慮以下標(biāo)記:

<p>

When we consider Che effect of positioning, it quickly becomes clear that authors

can do a great deal of damage to layout, just as they can do very interesting

things.<span style="position.: absolute; top: auto; left: 0;">[4]</span> This is usually the case with useful technologies: the sword always has at least two edges, both of them sharp.

</P>

會發(fā)生什么呢?對于left,很簡單:元素的左邊界會相對于其包含塊的左邊界放置(可以假設(shè)其包含塊是初始包含塊)。不過,對于top,還會發(fā)生一些更有意思的事情。定位元素的頂端要相對于其未定位前本來的頂端位置對齊。換句話說,假設(shè)網(wǎng)頁設(shè)計人員span的 position值為static,想象一下它會放在哪里,這就是其靜態(tài)位置,也就是計算出的其頂邊應(yīng)在的位置。CSS2.1這樣描述:

……(元素的)“靜態(tài)位置”一詞大致含義是:元素在正常流中原本的位置。更確切地講,“頂端”的錚態(tài)位置是從包含塊的上邊界到假想框的上外邊距邊界之間的距離(假想框是假設(shè)元素“position”屬性為“static”時元素的第一個框)。如果這個假想的元素框在包含塊的上面,則這個值為負。

因此,可以得到如圖10-42所示的結(jié)果,

圖10-42:絕對定位一個元素,與其“靜態(tài)”位置一致

“[4]”位于段落內(nèi)容之外,因為初始包含塊的左邊界在該段落左邊界的左邊。

如果left和right設(shè)置為auto,也適用同樣的基本規(guī)則。在這些情況下,定位元素的左(或右)邊界與元素未定位時該邊界原本的位置對齊。下面修改前面的例子,使top 和left都設(shè)置為auto:

<P>

When we consider the effect of positioning, it quickly becomes clear that

can. do a great deal of damage to layout, just as they can do very interesting

things.<span style="position: absolute; top: auto; left: auto;">[4]</span> This is usually the case with useful technologies: the sword always has at least two edges, both of them sharp.

</P>

圖10-43:絕對定位一個元素,與其“靜態(tài)”位置一致

“[4]”現(xiàn)在就位于其本來位置(即未定位前的位置)。注意,由于它已經(jīng)定位,其正常流空間關(guān)閉。這會導(dǎo)致網(wǎng)站建設(shè)定位元素與正常流內(nèi)容重疊。

注意:應(yīng)該注意到,網(wǎng)站建設(shè)CSS2和CSS2.1都指出在這樣的情況下,*網(wǎng)頁設(shè)計者可以自由猜測可能的[靜態(tài)]位置。當(dāng)前瀏覽器在這方面做得很好,會按要求處理top和left的auto值,使元素的位置與其在正常流中原本的位置一致。

這種自動放置只在某些情況下可行,這些情況下通常對定位元素的其他尺寸沒有什么限制。前面的例子可以自動放置,因為它對其高度或?qū)挾葲]有任何限制,對下邊界和右邊界的放置也沒有限制。不過,假設(shè)出于某種原因確實有這樣一些限制會怎么樣呢?請考慮以下標(biāo)記:

<p>

When we consider the effect of positioning, it' quickly becomes clear that authors

can do a great deal of damage to layout, just as they can do very interesting

things.<span style="position: absolute; Copt auto; left: auto; right: 0; bottom: 0; height: 2em; width: 5em;">[4]</span> This is usually the case with

useful technologies: the sword always has at least two edges, both of them sharp.

</P>

此時無法滿足以上的全部值。要確定此時會發(fā)生什么,這是下一節(jié)要討論的問題。

當(dāng)前文章標(biāo)題:網(wǎng)頁設(shè)計中的自動邊偏移

當(dāng)前URL:http://www.iy5y368.cn/news/wzzz/automatic-offset.html

上一篇:網(wǎng)頁設(shè)計中絕對定位元素的放置和大小

下一篇:網(wǎng)頁設(shè)計中非替換元素的放置和大小

網(wǎng)站建設(shè)、網(wǎng)絡(luò)營銷咨詢專線:181-8386-5875(點擊可一鍵撥號)