CSS3's auto property for margin

This is a snippet of my HTML and CSS code that I'm working on:

<header id="main">
    <a href="#" id="exit"></a>
    <a href="http://www.reddit.com/" id="reddit"></a>
    <a href="http://www.stackoverflow.com/" id="stackoverflow"></a>
    <a href="http://www.facebook.com/" id="facebook"></a>
    <a href="#" id="title"></a> 
</header>

And here is the corresponding CSS to style this section:

#main{
    height: 220px;
    width: auto;
    border: 2px #000000 solid;
}

#title{
    float: left;
    background: url(title.jpg) no-repeat;
    padding: 90px 145px;
    margin: 20px auto;
    border: 2px #000000 solid;
}

I added borders to both ID elements for clarity. However, I am puzzled as to why the title image is not centered as intended. Here's how it looks based on the code provided above:

If you'd like to check out the live example, you can view it on JSFiddle: http://jsfiddle.net/5nWag/2/

Answer №1

The alignment of the title image appears off-center due to the use of float: left;. It seems that this is being applied to id="exit". To correct this, consider placing Facebook, Stack, and Red within a div with position: absolute;, followed by applying the same style to exit.

Additionally, ensure that these styles are applied to your main image:

background: url(title.jpg) no-repeat;
padding: 90px 145px;
margin: 0 auto;
margin-bottom: 20px;
margin-top: 20px;
border: 2px #000000 solid;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Enhancing user experience with dynamically resized Jumbotron images based on screen sizes in HTML

I am experiencing an issue with the jumbotron images on my website where they become increasingly zoomed in as the screen size decreases, and are extremely zoomed in on mobile devices. Is this a normal behavior of jumbotrons? I do understand that the image ...

Stop a form field from being visible on the screen

I'm working on a project where I would like to hide the user field in the form. models.py class Questions(models.Model): user=models.ForeignKey(User) category=models.ForeignKey(Categories) question=models.TextField(max_length=500) cr ...

Text Embedded in Object HTML

Feeling stuck and need some guidance. My goal is to insert text inside hexagon shapes, but I'm having trouble making it work. I can change the background-color of the hexagons, add URLs, etc., but adding text seems to be a challenge. Check out the co ...

Javascript and iframes may encounter compatibility issues with browsers other than Internet Explorer

My HTML file includes an iframe and JavaScript that function correctly in IE Browser, but they do not work in other browsers such as Safari and Firefox. When using Safari, only the iframe box is displayed without showing the content inside it. I am curio ...

Implementing a redirect following the notification

I'm facing an issue with a function that sends form data to Google Sheets. How can I make the redirect button work after displaying an alert message? I attempted using window.location.href='', but it redirects without submitting the data. & ...

Attempting to conceal image previews while incorporating pagination in Jquery

I'm working on implementing pagination at the bottom of a gallery page, allowing users to navigate between groups of thumbnail images. On this page, users can click on thumbnails on the left to view corresponding slideshows on the right. HTML <di ...

Parsing of CSS and Javascript is disabled within iframes

Within my node.js application, I have configured an endpoint where I can load some parsed HTML code. This is achieved through the following code: app.get('/code', function (req, res) { res.setHeader('Content-Type', 'text/html& ...

A guide on extracting a div element without a class using Html Agility Pack

Can you help me extract the text 'Galatasaray.' from the HTML code below? I'm not sure how to specify it properly. <div class="dRib1"> <h2>Information</h2> </div> <div>Galatasaray.</div> ...

Off-center alignment in left margin with Bootstrap 3

When using bootstrap 3, I have noticed that the left margin starts to indent gradually with each row. Here is a screenshot demonstrating the issue: please see here The code for the first two rows in the image looks like this: <div class="row"> ...

The significance of the "$=" or "?=" symbols in lit-element illustrations

I'm struggling to comprehend the purpose of ?= or $= in these two instances: First Example: Lit-Element README <div id="box" class$="${this.uppercase ? 'uppercase' : ''}"> <slot>Hello World</slot> </div> ...

Is it possible that JavaScript isn't functioning properly?

My current issue involves echoing JavaScript from a PHP file to an HTML page using AJAX. Strangely, the JavaScript does not run when dynamically echoed, even though it appears in the Inspect Element tool. On the other hand, purely textual content echoes su ...

How to customize text within an HTML <option> tag within a <select> element

Customizing the appearance of items in an option list can be easily achieved by using CSS: <select> <option>Option 1</option> <option style="color: #F00; font-weight: bold; padding-left:2em;">Option 2</option> <opt ...

Separate the paragraph within an HTML string and eliminate any paragraph that is empty

I need help splitting a string of HTML into an array list, with the condition that the paragraphs should not be empty. Each paragraph should contain some normal text, and if it only contains HTML text without any normal text like: <htmltag>&nbsp; ...

Version 3 of Source Maps and CSS compilation/compression

Is there a tool available that can compress, minify, and combine CSS files while generating a valid v3 SourceMap compatible with Chrome? Ideally, I am looking for a NodeJS tool. From my research, some Node compressors like clean-css, csso, css-condense (w ...

Acquiring the `=` symbol within email HTML

Here is the HTML that I send from my ASP.NET application: <HTML> <BODY> <img src='http://10.1.1.42:8090/EmailLogo/8aaebe52-3758-485f-8c52-7782707a4c66.jpg' /> <br/> <div style='font-family:Arial, Tah ...

The alignment of an inline unordered list is off-center

My website at this link features a sticky navigation bar. However, the list items are slightly misaligned to the left and I'm struggling to pinpoint the cause. Despite adjusting margins and padding extensively, the issue persists. It's important ...

Conceal the content in order to determine the height of images displayed next to each

I am working on a layout where there are rows with images in the left column and text in the right column. The images have a ratio of 16:9. In case the text becomes too long, I would like to show only a portion of it with a gradient mask and provide a "Rea ...

Implement a context path in Angular 2 for enhanced functionality

Is there a way to change the base URL for my app from http://localhost:4200 to http://localhost:4200/pilot/? I attempted to modify the base href in index.html, but encountered an Uncaught SyntaxError: Unexpected token < This is the code snippet from m ...

Position the div to float on the right side and then have it drop below on smaller screens

I'm currently working on implementing a design effect similar to the one shown below: on my website (), but I'm struggling with getting the HTML and CSS just right. When I move the map to float up on the right side, it doesn't drop below th ...

Tips for retrieving the value when a button is clicked in AngularJS

Looking for assistance on retrieving the selected value in AngularJS when a button is clicked. Below is the code I am currently using: <div class="form-inline"> <div class="form-group"> <select class="form-control" data-n ...