两列布局的设置方法总结_html/css_WEB-ITnose

WBOY
發布: 2016-06-24 11:31:10
原創
1356 人瀏覽過

今天看到了这样一道题

用两种不同的方法来实现一个两列布局,其中左侧部分宽度固定、右侧部分宽度随浏览器宽度的变化而自适应变化 

自己感觉有好几种方法,再此总结下:

 一、使用position:absolute方法,因为把元素设置为absolute,那元素就脱离了文档流,后面的元素就会占据他原来的位置:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title></head><style type="text/css">        .side{width:190px;height:80px;background-color:#F00;<strong>position:absolute;</strong>}    .exta{height:80px;background-color:#0f0;<strong>margin-left:190px;</strong> }        </style><body>    <div class="pd">           <div class="side">side</div>        <div class="exta">exta</div>    </div></body></html>
登入後複製

二、使用float方法

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title></head><style type="text/css">       .side{width:190px;height:80px;background-color:#F00;     <strong> float</strong><strong>:left;</strong>    }    .exta{height:80px;background-color:#0f0; }//<strong>不能添加float:left;否则其宽度就会随内容变窄,不是随浏览器变化了</strong>        </style><body>    <div class="pd">                <div class="side">side</div>        <div class="exta">exta</div>    </div></body></html><br /><br />
登入後複製

 

來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!