दो पहलुओं आप को संबोधित करने की आवश्यकता है। पहला पहलू क्षैतिज संरेखण है। यह मार्जिन के साथ आसानी से प्राप्त किया जा सकता है: स्वतः छवि के आस-पास div तत्व पर स्वतः लागू होता है। डीआईवी को छवि आकार में चौड़ाई और ऊंचाई सेट करने की आवश्यकता है (अन्यथा यह काम नहीं करेगा)। लंबवत केंद्र संरेखण प्राप्त करने के लिए आपको HTML पर कुछ जावास्क्रिप्ट जोड़ने की आवश्यकता है। ऐसा इसलिए है क्योंकि HTML ऊंचाई का आकार पृष्ठ के स्टार्टअप पर ज्ञात नहीं है और बाद में बदल सकता है। सबसे अच्छा समाधान jQuery का उपयोग करना और निम्न स्क्रिप्ट लिखना है: $ (विंडो)।तैयार (फ़ंक्शन() {/ * विंडो तैयार ईवेंट को सुनें - पेज के बाद ट्रिगर किया जा रहा है */ repositionCenteredImage(); });
$(window).resize(function() { /* listen to page resize event - in case window size changes*/
repositionCenteredImage();
});
function repositionCenteredImage() { /* reposition our image to the center of the window*/
pageHeight = $(window).height(); /*get current page height*/
/*
* calculate top and bottom margin based on the page height
* and image height which is 300px in my case.
* We use half of it on both sides.
* Margin for the horizontal alignment is left untouched since it is working out of the box.
*/
$("#pageContainer").css({"margin": (pageHeight/2 - 150) + "px auto"});
}
HTML पृष्ठ जो छवि दिखा रहा है इस तरह दिखता है:
#html, body {
margin: 0;
padding: 0;
background-color: #000;
}
#pageContainer { /*css for the whole page*/
margin: auto auto; /*center the whole page*/
width: 300px;
height: 300px;
}
#logoImage { /*css for the logo image*/
width: 300px;
height: 300px;
}
आप हमारी कंपनी से पूरे समाधान डाउनलोड कर सकते हैं:
<body>
<div id="pageContainer">
<div id="image container">
<img src="brumenlabLogo.png" id="logoImage"/>
</div>
</div>
</body>
सीएसएस तत्वों से जुड़ी इस तरह दिखता है निम्नलिखित यूआरएल पर होमपेज:
http://brumenlab.com
स्रोत
2015-04-10 13:58:45
आपको 2 के बजाय 4 टैग का उपयोग कर रहे हैं करने के लिए accourding
.client_logo
का आकार सेट कर सकते हैं? काम करना चाहिए। – Vivien
मैं div के नीचे छवि देखता हूं, एक्स कुछ प्रस्तुत करता है या मुझे इसे कुछ मान निर्धारित करना है? – CeccoCQ
एक्स आपके लिए कुछ भी अच्छा हो सकता है: "5%", "10px, 0" ... आप मुख्य div – Vivien