2010-05-12 10 views
15

मुझे लेआउट के साथ कोई समस्या है - यह कहीं भी ऑनलाइन नहीं है, केवल स्थानीय है, लेकिन यदि आप नीचे दिए गए कोड को एक HTML पृष्ठ में कॉपी और पेस्ट करते हैं और इसे स्थानीय रूप से चलाते हैं तो आप देखेंगे एक ही पृष्ठ मैं करता हूँ।फिक्स्ड फ़ूटर और एम्बेडेड Google मानचित्र के साथ 100% ऊंचाई

यह लगभग बहुत करीब है। जो मैं प्राप्त करने की कोशिश कर रहा हूं वह एक पृष्ठ है जिसमें सभी उपलब्ध ऊर्ध्वाधर स्थान का उपयोग करके कोई स्क्रॉलबार नहीं है। हां, मैं कंटेनर घोषणा पर "ओवरफ्लो: छुपा" सेट कर सकता हूं और इससे मदद मिलती है, लेकिन यह बिल्कुल सही नहीं है। मैं वास्तव में 1em सीमा से घिरा हुआ Google मानचित्र चाहता हूं। मेरे पास यह 3 पक्षों पर है लेकिन सामग्री div पर 100% ऊंचाई घोषणा नीचे सीमा को दुर्घटनाग्रस्त कर देती है। यदि आप प्रतिशत आकार के Google मानचित्र div के प्रभावों का एहसास नहीं करते हैं, तो माता-पिता को काम करने के लिए घोषित ऊंचाई की आवश्यकता होती है। चूंकि पाद लेख पूर्ण और प्रवाह के बाहर है, वहां काम करने के लिए कोई "नीचे" सीमा नहीं है और लेआउट बस काम नहीं करता है। प्रतीत होता है कि सामग्री div 100% ऊंचाई मूल रूप से व्यूपोर्ट से अपना आकार लेती है, जिसमें युक्त 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><title>Google map test</title> 
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
<style type="text/css"> 
html,body { 
margin:0; 
padding:0; 
height:100%; /* needed for container min-height */ 
background:fff; 

font-family:arial,sans-serif; 
font-size:small; 
color:#666; 
} 

h1 { 
font:1.5em georgia,serif; 
margin:0.5em 0; 
} 

h2 { 
font:1.25em georgia,serif; 
margin:0 0 0.5em; 
} 

div#container { 
position:relative; /* needed for footer positioning*/ 
margin:0 auto; /* center, not in IE5 */ 
width:960px; 
background:#fff; 
border-left:1px solid #ccc; 
border-right:1px solid #ccc; 

/*height:auto !important; real browsers */ 
height:100%; /* IE6: treaded as min-height*/ 

min-height:100%; /* real browsers */ 
} 

div#header { 
border-bottom:1px solid #ccc; 
border-left:1em solid #ccc; 
height:108px; 
position:relative; 
} 
div#header h1 
{ 
    position:absolute; 
    bottom: 0; 
    left:0.5em; 
} 
div#header2 
{ 
border-bottom:1px solid #ccc; 
border-left:1em solid #999; 
    height: 40px; 
    position: relative; 
} 
div#header2 p 
{ 
    position:absolute; 
    bottom: 0; 
    left:0.5em; 
} 
div#headerInternal 
{ 
border-bottom:1px solid #ccc; 
border-left:1em solid #cc3300; 
    height: 40px; 
    position: relative; 
} 
div#headerInternal p 
{ 
    position:absolute; 
    bottom: 0; 
    left:0.5em; 
} 

div#headerInternal2 
{ 
    height: 40px; 
    position: relative; 
} 
div#headerInternal2 p 
{ 
    position:absolute; 
    bottom: 0; 
    left:0.5em; 
} 


div#rightCol 
{ 
    float:right; 
    width:29%; 
padding-bottom:5em; /* bottom padding for footer */ 
} 

div#content 
{ 
float:left; 
    width:70%; 
    height:100%; /* fill that hole! */ 
border-right:1px solid #ccc; 
} 
div#content p { 
} 

div#footer { 
    position:absolute; 
clear:both; 
width:100%; 
height:40px; 
bottom:0; /* stick to bottom */ 
background:#fff; 
border-top:1px solid #ccc; 
} 
div#footer p { 
    padding:1em; 
    margin:0; 
} 

.paddedContent 
{ 
    height:100%; 
    margin: 1em; 
} 
</style> 

<script type="text/javascript"> 
function initialize() { 
    var latlng = new google.maps.LatLng(52.397, 1.644); 
    var myOptions = { 
     zoom: 8, 
     center: latlng, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 
} 

</script> 
</head> 

<body onload="initialize()"> 
    <div id="container"> 
    <div id="header"> 
     <h1>Title here...</h1> 
    </div> 
    <div id="header2"> 
     <p>Secondary menu...</p> 
    </div> 

    <div id="rightCol"> 
     <div id="headerInternal2"> 
      <p>Right Header</p> 
     </div> 
     <p class="paddedContent">This is the right column</p> 
    </div> 
    <div id="content"> 
     <div id="headerInternal"> 
      <p>Page Context Menu</p> 
     </div> 
     <div class="paddedContent"> 
      <div id="map_canvas" style="width: 100%; height: 100%;"></div> 
     </div> 
     <div id="footer"> 
      <p>This footer is absolutely positioned</p> 
     </div> 
    </div> 
</div> 
</body> 
</html> 
+0

वास्तव में मुश्किल ... मैंने कुछ समय के लिए इसके साथ झगड़ा करने की कोशिश की। मुझे लगता है कि समस्या की जड़ div # कंटेनर {ऊंचाई: 100%} – Kasturi

+0

चार साल बाद, यह [सीएसएस फ्लेक्स बॉक्स मॉडल] (http://stackoverflow.com/a/26558073/1269037 का उपयोग करके अधिक आसानी से किया जाता है)। अन्य सभी समाधान घबराए हुए हैं। –

उत्तर

17

ओह, मैं यह काम कर रहा है। निम्नलिखित परिवर्तन करें।

1) चूंकि पाद लेख प्रवाह से बाहर है, इसलिए इसे ouside div # सामग्री लाएं और इसके बाद इसे डालें।

2) के रूप में इस प्रकार है

div#content{ 

border-right:1px solid #CCCCCC; 
bottom:0; 
float:left; 
overflow:hidden; 
padding-bottom:108px; 
margin-top:148px; 
position:absolute; 
top:0; 
width:70%; 

} 

नोट div # सामग्री के सीएसएस बदलने के लिए: गद्दी ऊपर और के रूप में अपने शीर्षलेख और पादलेख ऊंचाई तय कर दी है गद्दी नीचे तय की जाएगी। यह असफल हो जाएगा यदि उनके पास प्रतिशत मान भी हैं!

3) बदलें div # कंटेनर

div#container{  
background:none repeat scroll 0 0 #FFFFFF; 
border-left:1px solid #CCCCCC; 
border-right:1px solid #CCCCCC; 
height:100%; 
margin:0 auto; 
min-height:100%; 
overflow:hidden; 
position:relative; 
width:960px; 
} 

केवल अतिप्रवाह की सीएसएस: छिपा जोड़ा जाता है।

यहाँ पूरे पृष्ठ है: -

<!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><title>Google map test</title> 
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
<style type="text/css"> 
html,body { 
margin:0; 
padding:0; 
height:100%; /* needed for container min-height */ 
background:fff; 

font-family:arial,sans-serif; 
font-size:small; 
color:#666; 
} 

h1 { 
font:1.5em georgia,serif; 
margin:0.5em 0; 
} 

h2 { 
font:1.25em georgia,serif; 
margin:0 0 0.5em; 
} 

div#container { 
background:none repeat scroll 0 0 #FFFFFF; 
border-left:1px solid #CCCCCC; 
border-right:1px solid #CCCCCC; 
height:100%; 
margin:0 auto; 
min-height:100%; 
overflow:hidden; 
position:relative; 
width:960px; 

/*height:auto !important; real browsers */ 
height:100%; /* IE6: treaded as min-height*/ 

min-height:100%; /* real browsers */ 
} 


div#header { 
border-bottom:1px solid #ccc; 
border-left:1em solid #ccc; 
height:108px; 
position:relative; 
} 
div#header h1 
{ 
    position:absolute; 
    bottom: 0; 
    left:0.5em; 
} 
div#header2 
{ 
border-bottom:1px solid #ccc; 
border-left:1em solid #999; 
    height: 40px; 
    position: relative; 
} 
div#header2 p 
{ 
    position:absolute; 
    bottom: 0; 
    left:0.5em; 
} 
div#headerInternal 
{ 
border-bottom:1px solid #ccc; 
border-left:1em solid #cc3300; 
    height: 40px; 
    position: relative; 
} 
div#headerInternal p 
{ 
    position:absolute; 
    bottom: 0; 
    left:0.5em; 
} 

div#headerInternal2 
{ 
    height: 40px; 
    position: relative; 
} 
div#headerInternal2 p 
{ 
    position:absolute; 
    bottom: 0; 
    left:0.5em; 
} 


div#rightCol 
{ 
    float:right; 
    width:29%; 
padding-bottom:5em; /* bottom padding for footer */ 
} 

div#content{ 

border-right:1px solid #CCCCCC; 
bottom:0; 
float:left; 
overflow:hidden; 
padding-bottom:108px; 
margin-top:148px; 
position:absolute; 
top:0; 
width:70%; 

} 
div#content p { 
} 

div#footer { 
    position:absolute; 
clear:both; 
width:100%; 
height:40px; 
bottom:0; /* stick to bottom */ 
background:#fff; 
border-top:1px solid #ccc; 
} 
div#footer p { 
    padding:1em; 
    margin:0; 
} 

.paddedContent 
{ 
    height:100%; 
    margin: 1em; 
} 
</style> 

<script type="text/javascript"> 
function initialize() { 
    var latlng = new google.maps.LatLng(52.397, 1.644); 
    var myOptions = { 
     zoom: 8, 
     center: latlng, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 
} 

</script> 
</head> 

<body onload="initialize()"> 
    <div id="container"> 
    <div id="header"> 
     <h1>Title here...</h1> 
    </div> 
    <div id="header2"> 
     <p>Secondary menu...</p> 
    </div> 

    <div id="rightCol"> 
     <div id="headerInternal2"> 
      <p>Right Header</p> 
     </div> 
     <p class="paddedContent">This is the right column</p> 
    </div> 
    <div id="content"> 
     <div id="headerInternal"> 
      <p>Page Context Menu</p> 
     </div> 
     <div class="paddedContent"> 
      <div id="map_canvas" style="width: 100%; height: 100%;"></div> 
     </div> 

    </div> 

     <div id="footer"> 
      <p>This footer is absolutely positioned</p> 
     </div> 
</div> 
</body> 
</html> 
+1

ओह आप पूर्ण सुंदरता! क्या प्रतिभा ... सामग्री div को पूरी तरह से स्थिति देने के बावजूद, लेकिन जब आप इसे देखते हैं तो यह इतना आसान है! धन्यवाद x 1 मिलियन। – Carl

+0

:) .. एक समान स्थिति का सामना करना पड़ा ... – Kasturi

+0

आप एक वूडू मास्टर हैं! इस समाधान से प्यार करो। –

5

@Katsuri, अपने समाधान के लिए धन्यवाद, यह काम करता है महान!

लाइव उदाहरण: http://jsfiddle.net/EZbfN/ स्रोत कोड

लेकिन दूसरों को जो एक बाईं तय आकार स्तंभ और एक Gmap div पूरे सही जगह भरने के लिए चाहता है के लिए, यहाँ मेरी कोड Katsuri के से संशोधित किया है :

<!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> 
<title>Google map test</title> 
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
<style type="text/css"> 
html, body { 
    margin:0; 
    padding:0; 
    height:100%; /* needed for container min-height */ 
} 
div#container { 
    height:100%; 
    width:100%; 
    /*height:auto !important; real browsers */ 
    height:100%; /* IE6: treaded as min-height*/ 
    min-height:100%; /* real browsers */ 
    margin:0 auto; 
    min-height:100%; 
    overflow:hidden; 
    position:relative; 
} 
div#header { 
    height:50px; 
    position:relative; 
} 
div#leftCol { 
    left:0; 
    bottom:0; 
    top:0; 
    overflow:hidden; 
    padding-bottom:35px; 
    margin-top:55px; 
    position:absolute; 
    width:300px; 
} 
div#content { 
    right:0; 
    bottom:0; 
    top:0; 
    left: 300px; 
    overflow:hidden; 
    padding-bottom:35px; 
    margin-top:55px; 
    position:absolute; 
} 
div#footer { 
    position:absolute; 
    clear:both; 
    width:100%; 
    height:20px; 
    bottom:0; /* stick to bottom */ 
    background:#fff; 
    border-top:1px solid #ccc; 
} 
.paddedContent { 
    height:100%; 
    margin: 5px; 
    border: solid 1px red; 
} 
</style> 
<script type="text/javascript"> 
function initialize() { 
    var latlng = new google.maps.LatLng(52.397, 1.644); 
    var myOptions = { 
     zoom: 8, 
     center: latlng, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 
} 

</script> 
</head> 

<body onload="initialize()"> 
<div id="container"> 
    <div id="header"> 
    <h1>Title here...</h1> 
    </div> 
    <div id="leftCol"> 
    <div class="paddedContent">This is the left column</div> 
    </div> 
    <div id="content"> 
    <div class="paddedContent"> 
     <div id="map_canvas" style="width: 100%; height: 100%;"></div> 
    </div> 
    </div> 
    <div id="footer"> 
This footer is absolutely positioned 
    </div> 
</div> 
</body> 
</html> 

आनंद लें!

+1

यह आपको सामग्री अनुभाग में स्क्रॉल करने की अनुमति नहीं देता है। – Justin

+0

फिर बस 'ओवरफ्लो: छुपा;' बदलें 'ओवरफ्लो: ऑटो;' –

+0

ग्रेट जॉब। पहेली के लिए धन्यवाद। –

संबंधित मुद्दे