Solved

Horizontally Centering an image

Posted on 2012-04-03
1
158 Views
Last Modified: 2012-04-03
Hello Experts,

Example

I want to horizontally center the red image within the yellow rectangle.
Is it possible to do this just by editing the basket-title class?

Thanks
0
Comment
Question by:jagku
1 Comment
 
LVL 30

Accepted Solution

by:
LZ1 earned 500 total points
ID: 37802539
Yes, but you would need to have margin:15px auto;.  To center a block level element like that, you need to have your left and right margins be auto and a fixed width also.

Make sense?  But since you have things overriding the margin-left & margin-right declarations in the basket-title class, you would need to add !important to the CSS.

Like so:

.basket-title {
    background: url("myimage.png") no-repeat scroll 0 0 transparent;
    margin-left: auto !important;
    margin-right: auto !important;
    width: 50%;
}

Open in new window

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When applying CSS to your HTML, there are many different ways to select which element(s) the CSS applies to.  Some of these selectors are more commonly known and used than others - Here are the more common ones: #X - Matches an ID of X .X - Matche…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
In this Micro Tutorial viewers will learn how to create a CSS image sprite (In a later tutorial, viewers will learn how to use CSS and HTML to create a navigation menu using this sprite) Open a new Photoshop document with a width of (Icon width)x(N…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now