Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8836271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:27:25+00:00 2026-06-14T09:27:25+00:00

I have a html document structured with a header, content, and footer divs. I

  • 0

I have a html document structured with a header, content, and footer divs. I am trying to center an image (a logo) inside my header div to display at the top of my webpage in the middle. I can absolute position it into the middle, but when I change the browser size, the img doesn’t move along with it. I want it to be place automatically in the center of the window. I am stumped..?

I have tried , margin-right:auto; margin-left:auto. I have also tried the trick where you make margin-left negative half the width and top 50%, but nothing has worked so far.

html:

    <body>
<div id="container">

<div id="header">
    <img id="logo-img" src="http://f.cl.ly/items/3c0h1b0F3t1D1S1T2J0F/smallersticker.png">
</div>
/*...(body div)
...(footer div)*/
</div> /*container*/

css:

#header {

    background-color:transparent;
    height:260px;
    width:100%
}


#logo-img{
display: block;
    margin-left: auto;
    margin-right: auto;
}

Also, Do I even need a container? Not sure if I need javascript for this, or if it can be accomplished with just html/css? Hope someone can help, thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:27:26+00:00Added an answer on June 14, 2026 at 9:27 am

    What is happening is that you are already correctly centering your image.

    Your problem is that the image is huge. If you notice closely, the image is not centered if your browser window becomes smaller in width than the image.

    Remove the white area from the image and it will center correctly.

    Edit: in IE, you need to add the rule text-align:center to #header

    Another way:

    If you don’t want to change your image, you can use this hack:

        <style>
        #header {
            overflow-y: hidden;
            background-color: transparent;
            height: 260px;
            width: 100%;
            margin-left: 50%;
        }
    
    
        #logo-img{
            display: block;
            position: relative;
            right: 50%;
        }
        </style>
        <body>
        <div id="container">
    
        <div id="header">
            <img id="logo-img" src="http://f.cl.ly/items/3c0h1b0F3t1D1S1T2J0F/smallersticker.png">
        </div>
        /*...(body div)
        ...(footer div)*/
        </div> /*container*/
    

    I learned this hack a while ago here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following structure of my HTML document: <div id=slideshow></div> <div id=content></div> $('#slideshow').css({
I have a HTML document with the below setup: <div class=main-div style=padding: 5px; border:
I have a html document and I want to delete all the divs of
I have a large HTML document which has roughly this structure: <div id=a> <!--
I have following structure of an HTML document: <body> <div class=main> <div class=left></div> <div
I have this HTML structure: <div id=navigation> <div id=accordion> <!-- 1st header and pane
I am trying to email the content of a Div. We have a booking
I have an HTML structure in this format: <div class=wrap> <div class=name></div> <div class=content>
I have this structure in my html document: <p> <em>You</em> began the evening well,
Possible Duplicate: How to parse and process HTML with PHP? I have HTML document

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.