0

I want to center an ad on my website. I tried using a div (Code Below). It centers properly on big screens, but when it comes to mobile devices, half of the ad is pushed out of the screen. Apologies if this has been asked before.

<div style="text-align: center;">
<div style="width: 640px; margin-top: 20px;">
 AD CODE COMES HERE</div>
</div>

Thanks in Advance

Jerold Vaz
  • 11
  • 3
  • Try adding a max-width: 100% on the element so it never exceeds 100% of the width of the page. – Tim Sheehan Oct 13 '15 at 03:22
  • Possible duplicate of [Horizontally center a div in a div](http://stackoverflow.com/questions/114543/horizontally-center-a-div-in-a-div) – Rob Oct 13 '15 at 04:04

2 Answers2

0

Because you set fixed width of your AD div. Try set it in percentage like width:60%.

AndyHu
  • 1,338
  • 2
  • 11
  • 19
0

Add max-width to the ad elemnt

<div style="text-align: center;">
<div style="width: 640px; margin-top: 20px;max-width:100%;">
 AD CODE COMES HERE</div>
</div>
Alex
  • 8,461
  • 6
  • 37
  • 49