Solved

Horizontally Centering an image

Posted on 2012-04-03
1
159 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

863 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

24 Experts available now in Live!

Get 1:1 Help Now