DIV + CSS adaptive window height, divcss adaptive window

Source: Internet
Author: User

DIV + CSS adaptive window height, divcss adaptive window
Java code 

  1. <Html>
  2. <Head>
  3. <Title> DIV + CSS adaptive window height </title>
  4. <Style type = "text/css">
  5. Body {
  6. Margin: 0;
  7. Padding: 0;
  8. Color: # ffffff;
  9. }
  10. # Header {
  11. Width: 100%;
  12. Height: 100px;
  13. Margin: 0 auto;
  14. Padding: 0px;
  15. Background-color: #000099;
  16. }
  17. # Wrapper {
  18. Width: 100%;
  19. Margin: 0 auto;
  20. Padding: 0px;
  21. Background-color: # ffffff;
  22. }
  23. # Nav {
  24. Float: left;
  25. Width: 120px;
  26. Margin: 10px 10px 10px 5px;
  27. Background-color: #009900;
  28. }
  29. # Content {
  30. Margin: 10px 10px 10px 145px;
  31. Background-color: #990099;
  32. }
  33. # Footer {
  34. Position: absolute;
  35. Width: 100%;
  36. Height: 60px;
  37. Bottom: 0;
  38. Background-color: #990000;
  39. }
  40. </Style>
  41. </Head>
  42. <Body>
  43. <Div id = "header"> Header </div>
  44. <Div id = "wrapper">
  45. <Div id = "nav"> Nav </div>
  46. <Div id = "content"> Content </div>
  47. </Div>
  48. <Div id = "footer"> Footer </div>
  49. </Body>
  50. </Html>


When the height of nav and content is greater than one page, this requirement cannot be met. Therefore, you need to set min values for nav and content.


The code for the page designed by DIV + CSS is as follows:

On the first floor, you can fix it. You are not competent. I didn't ask you to answer anything. In the future, do not know about Baidu. You are insulting all those involved in Baidu.
According to your problem, it is obvious that div cannot automatically apply the height. In general, the outer div cannot contain the inner element.
Let's first explain why this phenomenon occurs?
Because the inner div is fully set to float, that is, the float attribute, once an element floats, it does not occupy the element space. The outer div cannot contain the inner element.
Solution:
Method 1: add an element at the end of the element in the inner layer, and set this element to not float, so that the inner element of the outer element is forcibly wrapped, such as <div style = "clear: both; float: none "> </div>
Method 2: Set overfloat to hidden or auto, zoom to 1, and zoom to be compatible with ie6.
Method 3: Set the height of the outer element to a fixed value (this is not recommended, but this is the perfect solution)
Method 4: Through the content attribute of css, this is a bit complicated and I will not mention it. Few people use this attribute anyway.

Finally, I would like to ask, are you a person on the first floor?

Add clear: both; to all the outer elements that do not participate in the floating, and forcibly clear the floating

DIV + CSS adaptive height

Height: auto! Important;
Height: 200px;/* assume that the minimum height is 200px */
Min-height: 200px;

This setting is compatible with ie6, 7,8, Firefox, and so on...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.