css頁面重構面試題

來源:互聯網
上載者:User

標籤:

偶然間又看到部落格園中這兩道頁面重構面試題。
題一:分別用2個DIV,3個DIV,5個DIV實現水平垂直均置中顯示一個寬50px,高200px的正十字架.
思路:水平垂直均置中的實現,當然非absolute加外邊距負值結合莫屬.閑話略去,看代碼及示範吧.
2個DIV實現的核心CSS代碼:點此查看DEMO

.div_a{width:50px; height:200px; background:#a40000; position:absolute; left:50%; top:50%; margin:-100px 0 0 -25px}.div_b{width:200px; height:50px; background:#a40000; position:absolute; left:50%; top:50%; margin:-25px 0 0 -100px}

3個DIV實現的核心CSS代碼:點此查看DEMO

.div_a{width:200px; height:50px; background:#a40000; magin-top:75px}.div_b{width:50px; height:200px; background:#a40000; margin:-125px 0 0 75px}.div_c{width:200px; width:200px; position:absolute; left:50%; top:50%; margin:-100px 0 0 -100px}

5個DIV實現的核心CSS代碼:點此查看DEMO

.div_a{width:200px; width:200px; position:absolute; background:#a40000; left:50%; top:50%; margin:-100px 0 0 -100px}.div_b,.div_c,.div_d,.div_e{width:75px; height:75px; background:#fff}.div_b,.div_d{float:left}.div_c,.div_e{float:right}.div_b,.div_c{margin-bottom:50px}

題二:這是一道很費腦筋,但很有意思的一道題.這道題也能讓你領略到CSS的博大精深.原題要求是,讓某一圖形水平垂直置中於當前可視頁面,且圖形是一個無限縮小的,就是四個角的正方形依次縮小,在使用者體驗上要滿足盡最多使用者.
思路:既然要求圖形水平垂直置中,那最終它占的肯定是一個正方圖形;從使用者體驗上,滿足最多使用者,主要是受限於使用者的瀏覽器視窗大小.目前主流的顯示器解析度是1024*768,拿大陸使用者量最大的IE來計算,其不安裝外掛程式的情況下可視高度約為590px,所以我們要實現的正方圖形必須限制在590px*590px裡面(解析度寬大於高,所以以高為底線計算).按最中間的圖形大小為200px*200px計算,200+100*2+50*2+25*2+12.5*2+6.25*2~=590.
題二思路借簽自網路,原作者已無從考證,謹此感謝.
核心CSS代碼:點此查看DEMO

.div_center{width:200px;height:200px;left:50%;top:50%;position:absolute;margin:-100px 0 0 -100px;background:#a40000}.div_a,.div_b,.div_c,.div_d{width:50%;height:50%;position:absolute;background:#a40000;}.div_a{left:-50%;top:-50%}.div_b{right:-50%;top:-50%}.div_c{left:-50%; bottom:-50%;}.div_d{right:-50%; bottom:-50%;}

 

html部分:

<div class="div_center">  <div class="div_a">    <div class="div_a">      <div class="div_a">        <div class="div_a">          <div class="div_a">            <div class="div_a"></div>          </div>        </div>      </div>    </div>  </div>  <div class="div_b">    <div class="div_b">      <div class="div_b">        <div class="div_b">          <div class="div_b">            <div class="div_b"></div>          </div>        </div>      </div>    </div>  </div>  <div class="div_c">    <div class="div_c">      <div class="div_c">        <div class="div_c">          <div class="div_c">            <div class="div_c"></div>          </div>        </div>      </div>    </div>  </div>  <div class="div_d">    <div class="div_d">      <div class="div_d">        <div class="div_d">          <div class="div_d">            <div class="div_d"></div>          </div>        </div>      </div>    </div>  </div></div>

 

 

css頁面重構面試題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.