2013-06-08 3 views
10

div를 센터링하려고합니다. HTML5/JavaScript의 Windows 8 앱용 Microsoft pubCenter AdControl입니다.DIV를 페이지 중앙에 가로로 놓습니다.

<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를 수평 가운데에 배치하면 페이지 중간에 어떻게 배치 할 수 있습니까? 당신이 CSS를 사용할 수 있습니다

+1

이 [질문]를보고 할 수 있습니다 (http://stackoverflow.com/questions/16670025/css-to-centralise-a-html5-div를 -at-the-the-screen-of-the-screen/16674978 # 16674978) – Sushil

답변

5

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

점은 style="" 태그에 DIV 폭

+0

감사합니다. – ReignOfComputer

+11

또는 'margin : 0 auto'를 사용하십시오 ... 훨씬 더 간단합니다. –

17

의 절반 추가 margin:auto로 왼쪽 여백을 설정하는 것입니다, 그 트릭을 할해야합니다. align=center

-5

당신이 <div> 태그에 align='center'을 사용할 수 있습니다

다른 가능성

+1

이것은 html5에서 지원되지 않습니다. –

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

다른에서 발견 HTML5, C# 및 VS2015 용 사이트 #wrapper { width: 600px;margin: auto;}과 함께 콘텐츠를 포장 : CSS에 추가
<form id="form1"> <div id="wrapper"> Content </div> </form>

관련 문제