CSS垂直居中網(wǎng)頁布局實現(xiàn)的5種方法
互聯(lián)網(wǎng) 發(fā)布時間:2009-04-02 19:37:54 作者:佚名
我要評論
網(wǎng)頁制作Webjx文章簡介:利用 CSS 來實現(xiàn)對象的垂直居中有許多不同的方法,比較難的是選擇那個正確的方法。我下面說明一下我看到的好的方法和怎么來創(chuàng)建一個好的居中網(wǎng)站。
利用 CSS 來實現(xiàn)對象的垂直居中有許多不同的方法,比
利用 CSS 來實現(xiàn)對象的垂直居中有許多不同的方法,比較難的是選擇那個正確的方法。我下面說明一下我看到的好的方法和怎么來創(chuàng)建一個好的居中網(wǎng)站。
哪個方法?
我最喜歡的是方法三,缺點不多。因為 content 會清除浮動,所以可以在它上面放置別的元素,并且當(dāng)窗口縮放時,
居中的 content 不會把另外的元素蓋住???例子。
<div id="top">
<h1>Title</h1>
</div>
<div id="content">
Content Here</div>
#floater{float:left; height:50%; margin-bottom:-120px;}
#top{float:right; width:100%; text-align:center;}
#content{clear:both; height:240px; position:relative;}
現(xiàn)在你知道是怎么回事了,現(xiàn)在我們開始創(chuàng)建一個簡單但是有趣的網(wǎng)站。最終的樣子是這樣的:
步驟一
以語義化標(biāo)簽開始是很好的。下面是我們的頁面構(gòu)成:
#floater/*把 content 置中*/
#contred/*centre 盒*/
#side
#logo
#nav/*無序列表*/
#content
#bottom/*放置版權(quán)等*/
這是我用到的 xhtml 代碼:
A Centred Company
<div id="centered">
<div id="side">
<div id="logo">
<strong><span>A</span> Company</strong></div>
<ul id="nav">
<li><a href="#">Home</a></li>
<li><a href="#">Products</a></li>
<li><a href="#">Blog</a></li>
<li><a href="#">Contact</a></li>
<li><a href="#">About</a></li>
</ul>
</div>
<div id="content">
<h1>Page Title</h1>
Holisticly re-engineer value-added outsourcing after process-centric collaboration and idea-sharing.
Energistically simplify impactful niche markets via enabled imperatives.
Holisticly predominate premium innovation after compelling scenarios.
Seamlessly recaptiualize high standards in human capital with leading-edge manufactured products.
Distinctively syndicate standards compliant schemas before robust vortals.
Uniquely recaptiualize leveraged web-readiness vis-a-vis out-of-the-box information.
<h2>Heading 2</h2>
Efficiently embrace customized web-readiness rather than customer directed processes.
Assertively grow cross-platform imperatives vis-a-vis proactive technologies.
Conveniently empower multidisciplinary meta-services without enterprise-wide interfaces.
Conveniently streamline competitive strategic theme areas with focused e-markets.
Phosfluorescently syndicate world-class communities vis-a-vis value-added markets.
Appropriately reinvent holistic services before robust e-services.</div>
</div>
<div id="bottom">
Copyright notice goes here</div>
相關(guān)文章
純CSS定位的固定垂直居中浮動層代碼,附經(jīng)典解說 《詳解定位與定位應(yīng)用
關(guān)于在html中浮動層是眾多網(wǎng)頁愛好者剛開始的難點,主要在于定位。如果你對CSS定位還不夠了解 可以接著往下看,運行里面的內(nèi)容即可。 【需求】: 將一個網(wǎng)頁分成頭、身2009-07-01- 如題,用html,css如何實現(xiàn)垂直居中。水平居中我們知道最簡便的方法就是margin:auto,但是margin只是相對寬度有效。2010-03-18
用CSS讓img input select button 圖片,文本框,下拉菜單,按扭垂直居中的
一直以來,在HTML中,img input select button 這里元素,垂直對齊,比較難。結(jié)果我長大了。我發(fā)現(xiàn)了一個現(xiàn)像,其實解決這些問題只是一句話的事。2011-03-08- 用過 Fireworks / PhotoShop 的人應(yīng)該都知道,在畫布中將一個頁面模塊居中是多容易的事,可如果是垂直居中,前端就苦逼了2011-10-30
- 全屏垂直居中的一個辦法 DIV+CSS , 這個方面有一點不好, 就是不能自動適應(yīng),必須把高和寬寫死!2011-10-07
- 寬度自適應(yīng):就是元素的寬度根居里面的內(nèi)容來變化2012-06-14
- 盡管有CSS的vertical-align特性,但是并不能有效解決未知高度的垂直居中問題(在一個DIV標(biāo)簽里有未知高度的文本或圖片的情況下)。2010-06-06
- 圖片的寬度和高度是未知的,沒有一個固定的尺寸,在這個前提下要使圖片在一個固定了寬度和高度的容器中垂直居中,想想感覺還是挺麻煩的,由于最近的項目可能會用到這個方案2010-12-18
- 最近上網(wǎng)上找了些關(guān)于CSS實現(xiàn)垂直居中的方法,方法挺多,下面就我看到的幾種好方法在這里說明一下,使用 CSS 實現(xiàn)垂直居中并不容易。2011-09-05
- 看到問此問題的很多,所以花點時間整理下,歡迎大家提意見,做補充修改,謝謝2012-01-21

