Search code examples
google-mapscenter

How to center an embedded Google map on a page?


I understand that this is quite a simple procedure, but I search for an answer every time I try to finish designing this page and none of the solutions I've found here and on Google did the trick for me.

I also understand that forcing an element to be centered is not exactly ideal, especially when there are so many different devices accessing the Internet these days, but I just want to get this done so I can focus on other issues.

Here's the code:

    <!DOCTYPE html>

<html>

<head>

<title>Como chegar</title>

<style>

#container {

    width: 800px;
    height: 600px;
    margin: 100px auto;

}

#content {

    width: 800px;
    height: 500px;
    background-color: white;

}

.strips {

    width: 800px;
    height: 50px;
    background-image: url(spritepimentarosa.png);
    background-repeat: no-repeat;
    float: left;

}

.navBar {

    width: 250px;
    height: 50px;
    background-image: url(spritepimentarosa.png);
    background-repeat: no-repeat;
    float: left;

}

.nb1 {

    background-position: 0px -450px;
    margin-left: 25px;

}

.nb2 {

    background-position: -250px -450px;

}

.nb3 {

    background-position: -500px -500px;
    margin-right: 25px;

}

.nb1:hover {

    background-position: 0px -500px;
    margin-left: 25px;

}

.nb2:hover {

    background-position: -250px -500px;

}

.nb3:hover {

    background-position: -500px -450px;
    margin-right: 25px;

}

.logo {

    background-position: 0px -200px;

}

.footer {

    background-position: 0px -400px;

}

</style>

</head>

<body bgcolor="#D63B77">

    <div id="container"><!-- beginning of container -->

    <div class="navBar nb1"></div>
    <div class="navBar nb2"></div>
    <div class="navBar nb3"></div>

    <div id="content"><!-- beginning of content -->


        <iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.ie/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=Avenida+S%C3%A3o+Camilo,+980,+Cotia+-+S%C3%A3o+Paulo,+Brazil&amp;aq=0&amp;oq=980,+avenida+sao+camilo&amp;sll=-23.583184,-46.836844&amp;sspn=92.879748,186.152344&amp;t=m&amp;ie=UTF8&amp;hq=&amp;hnear=Av.+S%C3%A3o+Camilo,+980+-+Cotia+-+S%C3%A3o+Paulo,+06709-150,+Brazil&amp;ll=-23.583025,-46.83712&amp;spn=0.037758,0.054932&amp;z=14&amp;iwloc=A&amp;output=embed"></iframe><br /><small><a href="http://maps.google.ie/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=Avenida+S%C3%A3o+Camilo,+980,+Cotia+-+S%C3%A3o+Paulo,+Brazil&amp;aq=0&amp;oq=980,+avenida+sao+camilo&amp;sll=-23.583184,-46.836844&amp;sspn=92.879748,186.152344&amp;t=m&amp;ie=UTF8&amp;hq=&amp;hnear=Av.+S%C3%A3o+Camilo,+980+-+Cotia+-+S%C3%A3o+Paulo,+06709-150,+Brazil&amp;ll=-23.583025,-46.83712&amp;spn=0.037758,0.054932&amp;z=14&amp;iwloc=A" style="color:#D63B77;text-align:center;font-size:180%">Ver mapa ampliado</a></small>


    </div><!-- end of content -->

    <div class="strips logo"></div>

    <div class="strips footer"></div>

    </div><!-- end of container -->

</body>

</html>

If anyone can help me with this, it'd be much appreciated.

Thank you.


Solution

  • normally you simply add:

    #content {
      text-align: center;
    }
    

    another trick would be setting the width of the div and then auto margin your div:

    #content {
      width: 800px;
      margin-left: auto;
      margin-right: auto;
    }