亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

CSS左側(cè)固定寬 右側(cè)自適應(yīng)的實(shí)現(xiàn)代碼(兼容所有瀏覽器)

  發(fā)布時(shí)間:2016-05-26 10:01:17   作者:佚名   我要評(píng)論
下面小編就為大家?guī)?lái)一篇CSS左側(cè)固定寬 右側(cè)自適應(yīng)的實(shí)現(xiàn)代碼(兼容所有瀏覽器)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

左側(cè)固定寬,右側(cè)自適應(yīng)屏幕寬;

左右兩列,等高布局;

左右兩列要求有最小高度,例如:200px;(當(dāng)內(nèi)容超出200時(shí),會(huì)自動(dòng)以等高的方式增高)

要求不用JS或CSS行為實(shí)現(xiàn);

仔細(xì)分析試題要求,要達(dá)到效果其實(shí)也并不是太難,只是給人感覺像有點(diǎn)問(wèn)題一樣。但是你仔細(xì)看后你會(huì)覺得不是那么回事:

左邊固定,右邊自適應(yīng)布局,這個(gè)第一點(diǎn)應(yīng)該來(lái)說(shuō)是非常的容易,實(shí)現(xiàn)的方法也是相當(dāng)?shù)亩?,那么就可以說(shuō)第一條要求已不是什么要求了;

左右兩列等高布局,這一點(diǎn)相對(duì)來(lái)說(shuō)要復(fù)雜一些,不過(guò)你要是了解了怎么實(shí)現(xiàn)等高布局,那么也是不難。我個(gè)人認(rèn)為這個(gè)考題關(guān)鍵之處就在考這里,考你如何實(shí)現(xiàn)等高布局;所以這一點(diǎn)你需要整明白如何實(shí)現(xiàn);

至于第三條要求,應(yīng)該來(lái)說(shuō)是很方面的,我們隨處都可以看到實(shí)現(xiàn)最小高度的代碼;

第四條這個(gè)要求我想是考官想讓我們面試的人不能使用js來(lái)實(shí)現(xiàn)等高布局和最小高度的功能。

上面簡(jiǎn)單的分析了一下實(shí)現(xiàn)過(guò)程,那么最終關(guān)鍵之處應(yīng)該是就是“讓你的代碼要能同時(shí)實(shí)現(xiàn)兩點(diǎn),其一就是左邊固定,右邊自適應(yīng)的布局;其二就是實(shí)現(xiàn)兩列等高的布局”,如果這兩個(gè)功能完成,那么你也就可以交作業(yè)了。那么下面我們就先來(lái)看看這兩 點(diǎn)是如合實(shí)現(xiàn):

一、兩列布局:左邊固定寬度,右邊自適應(yīng)寬度

這樣的布局,其實(shí)不是難點(diǎn),我想很多同學(xué)都有實(shí)現(xiàn)過(guò),那么我就在此稍微介紹兩種常用的方法:

方法一:浮動(dòng)布局

這種方法我采用的是左邊浮動(dòng),右邊加上一個(gè)margin-left值,讓他實(shí)現(xiàn)左邊固定,右邊自適應(yīng)的布局效果

HTML Markup

CSS Code復(fù)制內(nèi)容到剪貼板
  1. <div id="left">Left sidebar</div>   
  2. <div id="content">Main Content</div>   
  3.   
  4. CSS Code   
  5.   
  6. <style type="text/css">   
  7.   
  8. *{   
  9.   
  10. margin: 0;   
  11.   
  12. padding: 0;   
  13.   
  14. }   
  15.     
  16. #left {   
  17.   
  18. floatleft;   
  19.   
  20. width220px;   
  21.   
  22. background-colorgreen;   
  23.   
  24. }   
  25.   
  26. #content {   
  27.   
  28. background-color: orange;   
  29.   
  30. margin-left220px;/*==等于左邊欄寬度==*/  
  31.   
  32. }   
  33. </style>   

上面這種實(shí)現(xiàn)方法最關(guān)鍵之處就是自適應(yīng)寬度一欄“div#content”的“margin-left”值要等于固定寬度一欄的寬度值,大家可以點(diǎn)擊查看上面代碼的DEMO

方法二:浮動(dòng)和負(fù)邊距實(shí)現(xiàn)

這個(gè)方法采用的是浮動(dòng)和負(fù)邊距來(lái)實(shí)現(xiàn)左邊固定寬度右邊自適應(yīng)寬度的布局效果,大家可以仔細(xì)對(duì)比一下上面那種實(shí)現(xiàn)方法,看看兩者有什么區(qū)別:

HTML Markup

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <div id="left">  
  2. Left Sidebar   
  3. </div>  
  4.   
  5. <div id="content">  
  6.   
  7. <div id="contentInner">  
  8.   
  9. Main Content   
  10.   
  11. </div>  
  12. </div>  

CSS Code

CSS Code復(fù)制內(nèi)容到剪貼板
  1. *{   
  2.   
  3. margin: 0;   
  4.   
  5. padding: 0;   
  6.   
  7. }   
  8.   
  9. #left {   
  10.   
  11. background-colorgreen;   
  12.   
  13. floatleft;   
  14.   
  15. width220px;   
  16.   
  17. margin-right: -100%;   
  18.   
  19. }   
  20.   
  21. #content {   
  22.   
  23. floatleft;   
  24.   
  25. width: 100%;   
  26.   
  27. }   
  28.   
  29. #contentInner {   
  30.   
  31. margin-left220px;/*==等于左邊欄寬度值==*/  
  32.   
  33. background-color: orange;   
  34.   
  35. }  

這種方法看上去要稍微麻煩一點(diǎn),不過(guò)也是非常常見的一種方法,大家可以看看他的DEMO效果。感覺一下,和前面的DEMO有什么不同之處。
 
我 在這里就只展示這兩種方法,大家肯定還有別的實(shí)現(xiàn)方法,我就不在多說(shuō)了,因?yàn)槲覀兘裉煲f(shuō)的不是這個(gè)問(wèn)題。上面完成了試題的第一種效果,那么大家就要想辦 法來(lái)實(shí)現(xiàn)第二條要求——兩列等高布局。這一點(diǎn)也是本次面試題至關(guān)重要的一點(diǎn),如果你要是不清楚如何實(shí)現(xiàn)等高布局的話,我建議您先閱讀本站的《八種創(chuàng)建等高 列布局》,里面詳細(xì)介紹了八種等高布局的方法,并附有相關(guān)代碼,而且我們后面的運(yùn)用中也使用了其中的方法。

現(xiàn)在關(guān)鍵的兩點(diǎn)都完成了,那么我們就需要實(shí)現(xiàn)第三條要求,實(shí)現(xiàn)最小高度的設(shè)置,這個(gè)方法很簡(jiǎn)單:

CSS Code復(fù)制內(nèi)容到剪貼板
  1. min-height200px;   
  2.   
  3. heightauto !important;   
  4.   
  5. height200px;   

上面的代碼就輕松的幫我們實(shí)現(xiàn)了跨瀏覽器的最小高度設(shè)置問(wèn)題。這樣一來(lái),我們可以交作業(yè)了,也完面了這個(gè)面試題的考試。為了讓大家更能形象的了解,我在這里為大家準(zhǔn)備了五種不同的實(shí)現(xiàn)方法:

方法一:

別的不多說(shuō),直接上代碼,或者參考在線DEMO,下面所有的DEMO都有HTML和CSS代碼,感興趣的同學(xué)自己慢慢看吧。

HTML Markup

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <div id="container">  
  2.   
  3. <div id="wrapper">  
  4.   
  5. <div id="sidebar">Left Sidebar</div>  
  6.   
  7. <div id="main">Main Content</div>  
  8.   
  9. </div>  
  10.   
  11. </div>  

CSS Code

CSS Code復(fù)制內(nèi)容到剪貼板
  1. <style type="text/css">   
  2.   
  3. * {   
  4.   
  5. margin: 0;   
  6.   
  7. padding: 0;   
  8.   
  9. }   
  10.   
  11. html {   
  12.   
  13. heightauto;   
  14.   
  15. }   
  16.   
  17.     
  18.   
  19. body {   
  20.   
  21. margin: 0;   
  22.   
  23. padding: 0;   
  24.   
  25.     
  26.   
  27. }   
  28.   
  29.     
  30.   
  31. #container {   
  32.   
  33. background#ffe3a6;   
  34.   
  35. }   
  36.   
  37.     
  38.   
  39. #wrapper {   
  40.   
  41. displayinline-block;   
  42.   
  43. border-left200px solid #d4c376;/*==此值等于左邊欄的寬度值==*/  
  44.   
  45. positionrelative;   
  46.   
  47. vertical-alignbottombottom;   
  48.   
  49. }   
  50.   
  51.     
  52.   
  53. #sidebar {   
  54.   
  55. floatleft;   
  56.   
  57. width200px;   
  58.   
  59. margin-left: -200px;/*==此值等于左邊欄的寬度值==*/  
  60.   
  61. positionrelative;   
  62.   
  63. }   
  64.   
  65.     
  66.   
  67. #main {   
  68.   
  69. floatleft;   
  70.   
  71. }   
  72.   
  73.     
  74.   
  75. #maing,   
  76.   
  77. #sidebar{   
  78.   
  79. min-height200px;   
  80.   
  81. heightauto !important;   
  82.   
  83. height200px;   
  84.   
  85. }   
  86.   
  87. </style>  

方法二

HTML Markup

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <div id="container">  
  2.   
  3. <div id="left" class="aside">Left Sidebar</div>  
  4.   
  5. <div id="content" class="section">Main Content</div>  
  6.   
  7. </div>  

CSS Code

CSS Code復(fù)制內(nèi)容到剪貼板
  1. <style type="text/css">   
  2.   
  3. *{margin: 0;padding: 0;}   
  4.   
  5. #container {   
  6.   
  7. overflowhidden;   
  8.   
  9. }   
  10.   
  11.     
  12.   
  13. #left {   
  14.   
  15. background#ccc;   
  16.   
  17. floatleft;   
  18.   
  19. width200px;   
  20.   
  21. margin-bottom: -99999px;   
  22.   
  23. padding-bottom99999px;   
  24.   
  25.     
  26.   
  27. }   
  28.   
  29.     
  30.   
  31. #content {   
  32.   
  33. background#eee;   
  34.   
  35. margin-left200px;/*==此值等于左邊欄的寬度值==*/  
  36.   
  37. margin-bottom: -99999px;   
  38.   
  39. padding-bottom99999px;   
  40.   
  41. }   
  42.   
  43. #left,   
  44.   
  45. #content {   
  46.   
  47. min-height200px;   
  48.   
  49. heightauto !important;   
  50.   
  51. height200px;   
  52.   
  53. }   
  54.   
  55. </style>  

方法三:

HTML Markup

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <div id="container">  
  2.   
  3. <div id="content">Main Content</div>  
  4.   
  5. <div id="sidebar">Left Sidebar</div>  
  6.   
  7. </div>  

CSS Code

CSS Code復(fù)制內(nèi)容到剪貼板
  1. *{margin: 0;padding: 0;}   
  2.   
  3. #container{   
  4.   
  5. background-color:#0ff;   
  6.   
  7. overflow:hidden;   
  8.   
  9. padding-left:220px/* 寬度大小等與邊欄寬度大小*/  
  10.   
  11. }   
  12.   
  13. * html #container{   
  14.   
  15. height:1%; /* So IE plays nice */  
  16.   
  17. }   
  18.   
  19. #content{   
  20.   
  21. background-color:#0ff;   
  22.   
  23. width:100%;   
  24.   
  25. border-left:220px solid #f00;/* 寬度大小等與邊欄寬度大小*/  
  26.   
  27. margin-left:-220px;/* 寬度大小等與邊欄寬度大小*/  
  28.   
  29. float:rightright;   
  30.   
  31. }   
  32.   
  33. #sidebar{   
  34.   
  35. background-color:#f00;   
  36.   
  37. width:220px;   
  38.   
  39. float:rightright;   
  40.   
  41. margin-left:-220px;/* 寬度大小等與邊欄寬度大小*/  
  42.   
  43. }   
  44.   
  45. #content,   
  46.   
  47. #sidebar {   
  48.   
  49. min-height200px;   
  50.   
  51. heightauto !important;   
  52.   
  53. height200px;   
  54.   
  55. }  

方法四:

HTML Markup

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <div id="container2">  
  2.   
  3. <div id="container1">  
  4.   
  5. <div id="col1">Left Sidebar</div>  
  6.   
  7. <div id="col2">Main Content</div>  
  8.   
  9. </div>  
  10.   
  11. </div>  

CSS Code

CSS Code復(fù)制內(nèi)容到剪貼板
  1. *{padding: 0;margin:0;}   
  2.   
  3. #container2 {   
  4.   
  5.  floatleft;   
  6.   
  7.  width: 100%;   
  8.   
  9.  background: orange;   
  10.   
  11.  positionrelative;   
  12.   
  13.  overflowhidden;   
  14.   
  15.  }   
  16.   
  17.  #container1 {   
  18.   
  19.  floatleft;   
  20.   
  21.  width: 100%;   
  22.   
  23.  backgroundgreen;   
  24.   
  25.  positionrelative;   
  26.   
  27.  left220px;/* 寬度大小等與邊欄寬度大小*/  
  28.   
  29.  }   
  30.   
  31.         
  32.   
  33.  #col2 {   
  34.   
  35.  positionrelative;   
  36.   
  37.  margin-right220px;/* 寬度大小等與邊欄寬度大小*/  
  38.   
  39.  }   
  40.   
  41.         
  42.   
  43.  #col1 {   
  44.   
  45.  width220px;   
  46.   
  47.  floatleft;   
  48.   
  49.  positionrelative;   
  50.   
  51.  margin-left: -220px;/* 寬度大小等與邊欄寬度大小*/  
  52.   
  53.  }   
  54.   
  55.      
  56.   
  57. #col1,#col2 {   
  58.   
  59. min-height200px;   
  60.   
  61. heightauto !important;   
  62.   
  63. height200px;   
  64.   
  65. }  

方法五:

HTML Markup

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <div id="container1">  
  2.   
  3. <div id="container">  
  4.   
  5. <div id="left">Left Sidebar</div>  
  6.   
  7. <div id="content">  
  8.   
  9. <div id="contentInner">Main Content</div>  
  10.   
  11. </div>  
  12.   
  13. </div>  
  14.   
  15. </div>  

CSS Code

CSS Code復(fù)制內(nèi)容到剪貼板
  1. *{padding: 0;margin: 0;}   
  2.   
  3. #container1 {   
  4.   
  5. floatleft;   
  6.   
  7. width: 100%;   
  8.   
  9. overflowhidden;   
  10.   
  11. positionrelative;   
  12.   
  13. background-color#dbddbb;   
  14.   
  15. }   
  16.   
  17. #container {   
  18.   
  19. background-color: orange;   
  20.   
  21. width: 100%;   
  22.   
  23. floatleft;   
  24.   
  25. positionrelative;   
  26.   
  27. left220px;/* 寬度大小等與邊欄寬度大小*/  
  28.   
  29. }   
  30.   
  31. #left {   
  32.   
  33. floatleft;   
  34.   
  35. margin-right: -100%;   
  36.   
  37. margin-left: -220px;/* 寬度大小等與邊欄寬度大小*/  
  38.   
  39. width220px;   
  40.   
  41. }   
  42.   
  43. #content {   
  44.   
  45. floatleft;   
  46.   
  47. width: 100%;   
  48.   
  49. margin-left: -220px;/* 寬度大小等與邊欄寬度大小*/  
  50.   
  51. }   
  52.   
  53. #contentInner {   
  54.   
  55. margin-left220px;/* 寬度大小等與邊欄寬度大小*/  
  56.   
  57. overflowhidden;   
  58.   
  59. }   
  60.   
  61. #left,   
  62.   
  63. #content {   
  64.   
  65. min-height200px;   
  66.   
  67. heightauto !important;   
  68.   
  69. height200px;   
  70.   
  71. }  

針對(duì)上面的面試題要求,我一共使用了五種不同的方法來(lái)實(shí)現(xiàn),經(jīng)過(guò)測(cè)試都能在各瀏覽器中運(yùn)行,最后我有幾點(diǎn)需要特別提出:

上面所有DEMO中,要注意其方向性的配合,并且值要統(tǒng)一,如果您想嘗試使用自己布局需要的寬度值,請(qǐng)對(duì)照相關(guān)代碼環(huán)節(jié)進(jìn)行修改;

上面所有DEMO中,沒有設(shè)置他們之間的間距,如果您想讓他們之間有一定的間距,有兩種方法可能實(shí)現(xiàn),其一在上面的DEMO基礎(chǔ)上修改相關(guān)參數(shù),其二,在相應(yīng)的里面加上"div"標(biāo)簽,并設(shè)置其“padding”值,這樣更安全,不至于打破你的布局

因?yàn)槲覀冞@里有一列使用了自適應(yīng)寬度,在部分瀏覽器下,當(dāng)瀏覽器屏幕拉至到一定的大小時(shí),給我們帶來(lái)的感覺是自適應(yīng)寬度那欄內(nèi)容像是被隱藏,在你的實(shí)際項(xiàng)目中最好能在“body”中加上一個(gè)“min-width”的設(shè)置。

以上這篇CSS左側(cè)固定寬 右側(cè)自適應(yīng)的實(shí)現(xiàn)代碼(兼容所有瀏覽器)就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • HTML5的video標(biāo)簽的瀏覽器兼容性增強(qiáng)方案分享

    使用HTML5時(shí)就應(yīng)該考慮包括桌面以及移動(dòng)端的瀏覽器兼容問(wèn)題,特別是視頻方面瀏覽器對(duì)解碼的支持會(huì)有所不同,所以下面就來(lái)分享一個(gè)HTML5的video標(biāo)簽的瀏覽器兼容性增強(qiáng)方案分
    2016-05-19
  • Win10 Edge瀏覽器無(wú)縫兼容Chrome擴(kuò)展

    此前腳本之家微軟將在3月底正式開啟Edge瀏覽器擴(kuò)展功能公測(cè),而微軟面向開發(fā)者的盛會(huì)Build2016也將在3月30日拉開帷幕,那么Edge瀏覽器擴(kuò)展無(wú)疑將會(huì)是本次大會(huì)的亮點(diǎn)之一,
    2016-03-16
  • 主流瀏覽器css兼容問(wèn)題匯總

    這篇文章主要幫助大家梳理主流瀏覽器css兼容的相關(guān)問(wèn)題,對(duì)主流瀏覽器css兼容問(wèn)題進(jìn)行匯總,感興趣的小伙伴們可以參考一下
    2016-03-15
  • 淺談JavaScript中瀏覽器兼容的問(wèn)題

    下面小編就為大家?guī)?lái)一篇淺談JavaScript中瀏覽器兼容的問(wèn)題。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2016-05-31

最新評(píng)論