2011-12-05 4 views
4

현재 웹 사이트 템플릿을 디자인하고 있는데 문제는 그 안에있는 내용을 자동으로 확장하도록 콘텐츠 div를 가져올 수 없다는 것입니다.CSS 내용 만들기 DIV 내용 뒤에 자동 크기

수동으로 CSS 높이를 설정할 필요가 없도록 자동 크기 조정을 원했습니다.

내가 만든 CSS 코드 :

#Container { 
    position: relative; 
    width: 800px; 
    height: 100%; 
    margin: 0px auto 0 auto; 
    text-align: left; 
    padding-left: 1px; 
    cursor: de; 
    border-left: 1px solid #000001; 
    border-right: 1px solid #000001; 
    border-top: 1px solid #000001; 
    border-bottom: 1px solid #000001; 
    background-color: #C1E9FF; 
} 
#LogoContainer { 
    background-image: url('/media/Logo.png'); 
    border-right-width: 1px; 
    border-bottom-width: 1px; 
    border-right-color: rgb(0,0,1); 
    border-bottom-color: rgb(0,0,1); 
    border-right-style: solid; 
    border-bottom-style: solid; 
    width: 400px; 
    height: 50px; 
    position: absolute; 
    z-index: 1; 
} 
#LikeBar { 
    border-bottom-width: 1px; 
    border-bottom-color: rgb(0,0,1); 
    border-bottom-style: solid; 
    width: 400px; 
    height: 50px; 
    position: absolute; 
    left: 400px; 
    z-index: 1; 
} 
#ButtonHome { 
    background-image: url('/media/Bt.png'); 
    width: 100px; 
    height: 30px; 
    position: absolute; 
    top: 50px; 
    z-index: 1; 
} 
#ButtonVideo { 
    background-image: url('/media/Bt.png'); 
    width: 100px; 
    height: 30px; 
    position: absolute; 
    left: 105; 
    top: 50px; 
    z-index: 1; 
} 
#Footer { 
    border-top-width: 1px; 
    border-top-color: rgb(0,0,1); 
    border-top-style: solid; 
    width: 800px; 
    position: absolute; 
    bottom: 0; 
    z-index: 1; 
    text-align: center; 
} 
#Content { 
    position: absolute; 
    top: 90px; 
    width: 800px; 
    height: 95%; 
    border-top: 1px solid #000001; 
} 
#YouTubeBox { 
    position: absolute; 
    background-image: url('/media/Box.png'); 
    width: 100px; 
    height: 30; 
    left: 10px; 
    text-align: center; 
} 
#TwitterBox { 
    position: absolute; 
    background-image: url('/media/Box.png'); 
    width: 100px; 
    height: 30; 
    left: 110px; 
    text-align: center; 
} 
#FaceBookBox { 
    position: absolute; 
    background-image: url('/media/Box.png'); 
    width: 100px; 
    height: 30; 
    left: 210px; 
    text-align: center; 
} 
.DivT { line-height: 1px } 

HTML 코드 DIV

<!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 name="generator" content= 
    "HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org" /> 

    <title>HTML CODE</title> 
    <meta name="description" content="Null" /> 
    <meta name="keywords" content="Null" /> 
    <link href="ThemeV1.css" rel="stylesheet" type="text/css" /> 
</head> 

<body background="/media/Background.png"> 
    <div id="Container"> 
    <!-- Start Container --> 

    <div id="LogoContainer"></div> 

    <div id="LikeBar"></div><!-- Menu Controls --> 

    <div id="ButtonHome"></div><!-- WEBSITE CONTENT --> 

    <div id="Content"> 
     <p class="DivT">We're upgrading the website with a new design and hopefully it will 
     be faster, so check back later.</p> 
    </div><!-- END WEBSITE CONTENT --> 
    <!-- Footer --> 

    <div id="Footer"></div><!-- End Footer --> 
    </div><!-- End Container --> 
</body> 
</html> 

그래서, 무슨이다와? 나는 수동으로 높이를 설정하지 않는 시간을 절약하고 싶습니다.

#Content { 
... 
    height: 95%; 

height를 제거하고 높이가 (비 떴다) 내용을 유지하는 것이 필요하다 무엇 이건 될 것입니다 : 당신이 수동으로 콘텐츠 높이의 높이를 설정해야 처럼

+10

게시자가 게시 한 CSS를 검토하고 읽는 사람이 있습니까? 질문을 게시 할 때 독자를 고려하십시오. 도움말은 [여기] (http://jsbeautifier.org/), [여기] (http://procssor.com/process) 및 [여기] (http://infohound.net/tidy/)입니다. – Bojangles

+1

높이 변경 시도 : 최소 높이 95 % : 95 % – ptriek

+1

및 [여기] (http://jsfiddle.net)! – MCSI

답변

8

div#Content은 절대적으로 div#Container 내에 위치하고 있으므로 컨테이너는 자체 크기를 결정할 때 콘텐츠의 높이와 너비를 무시합니다. div#Contentposition 값을 relative으로 지정하십시오. 그런 다음 위의 설명에서 설명한대로 height 속성을 min-height으로 전환합니다. 절대 위치를 고수하면서 내용에 영향을받는 높이를 원하면 콘텐츠 div의 높이가 변경 될 때 자바 스크립트를 사용하여 포함 된 div의 style.height을 조정해야합니다.

+0

이것은 나에게 완전히 맞지 않는 것처럼 보입니다 - 절대적으로 배치 된 요소가 해당 콘텐츠의 높이/높이를 무시하지 않는다는 것을 알고있는 한. – ptriek

+0

당신은 실제로 맞습니다.그러나 위치 지정이있는 블록 요소는 절대 위치에있는 자식의 너비/높이를 무시합니다. 따라서 콘텐츠 div가 콘텐츠에 맞게 펼쳐지더라도 콘텐츠를 둘러싼 컨테이너 div는 그렇지 않습니다. – Aaron

3

는 것 같습니다.

0

크기를 조정하려면 높이 특성이없는 div를 자동으로 크기를 조정하여 div에 포함 된 콘텐츠의 높이에 맞 춥니 다. 크기가 적어도 XXXpx 이상이거나 화면을 특정 방식으로 맞추려면 min-height 속성을 사용하십시오. 이렇게하면 높이가 고정되어 텍스트가 너무 작 으면 원하는 영역에 표시되고 텍스트가 최소 설정보다 클 경우 확장됩니다.

당신은 너무 많은 높이 나는 그들 모두에 들어갈 않을거야 그 여기에 설명이 있지만 최소한 다음을 조정합니다 :

#Container { min-heigh: 100%;} 
#Content { min-height: 95%; } 

* 주 - 분 - 높이와있는 분 폭 IE6에서 지원하지 않습니다.

또한 요소의 위치는 데이터 흐름의 표준 흐름에서 요소를 가져올 수 있으므로 높이에 많은 문제가 발생할 수 있습니다. 필요하지 않으면 레이아웃을 올바르게 설정하면 실제로 필요하지 않습니다. Z- 색인을 설정하거나 사이트와 함께 스크롤되는 고정 된 배경을 원하는 것과 같이 특이합니다.