2013-06-08 3 views
10

में क्षैतिज रूप से एक डीआईवी केंद्र केंद्र मैं एक div को केंद्र में रखने की कोशिश कर रहा हूं, जो HTML5/जावास्क्रिप्ट में विंडोज 8 ऐप्स के लिए माइक्रोसॉफ्ट पबसेन्टर एडकंट्रोल है।पृष्ठ

<div id="myAd" style="; top: 0%; width: 292px; height: 60px; z-index: 1" 
     data-win-control="MicrosoftNSJS.Advertising.AdControl" 
     data-win-options="{applicationId: 'exampleAdId', adUnitId: 'exampleAdUnit'}"> 
    </div> 

मैं कैसे एक div क्षैतिज केंद्र हैं इसलिए यह एक पृष्ठ के बीच में हमेशा होता है?

+1

पर इस [सवाल] देखने के लिए चाहते हो सकता है http://stackoverflow.com/questions/16670025/css-to-centralise-a-html5-div -ट-द-डाउन-द-स्क्रीन/16674 9 78 # 16674 9 78) – Sushil

उत्तर

5

आप सीएसएस का उपयोग कर सकते केवल

left:50%;margin-left:-146px; 

बिंदु अपने style="" टैग में मार्जिन div चौड़ाई

+0

ऐसा हुआ, धन्यवाद! – ReignOfComputer

+11

या 'मार्जिन: 0 ऑटो' का उपयोग करें ... बहुत आसान है। –

17

के आधे जोड़े margin:auto रूप में छोड़ दिया सेट करने के लिए है और वह चाल करना चाहिए।

अन्य संभावना, align=center

-5

आप align='center'<div> टैग में उपयोग कर सकते हैं

+1

यह एचटीएमएल 5 द्वारा समर्थित नहीं है –

2

आप निरपेक्ष केंद्र के लिए बस इस वर्ग का उपयोग कर सकते

.ab_center 
{ 
    height:300px; 
    width:300px; 
    background-color:#27f305; 
    position:absolute; 
    margin:auto; 
    top:0; 
    left:0; 
    right:0; 
    bottom:0; 
} 

उदाहरण बेला: http://jsfiddle.net/devesh_dc/dzyvmt0o/

0

अन्य पर मिला एचटीएमएल 5, सी # और वीएस2015 के लिए साइट। सीएसएस में जोड़ें: #wrapper { width: 600px;margin: auto;} और अपनी सामग्री लपेट के साथ: (
<form id="form1"> <div id="wrapper"> Content </div> </form>