Solved

H2 element with background image, need to indent text without moving background

Posted on 2009-07-14
4
380 Views
Last Modified: 2012-08-14
Here is my heading:

<h2 class="navheading"><span class="white">Health Management</span></h2>

CSS is attached. I need to move the text to the right (indent), but if I add padding, then padding is added around the background image. How can I move the text without moving the background or changing the specified width and height? Want to keep it within 192x30, with the background image, just indent the text. Thanks.
h2 {

		font-family: Trebuchet MS, Trebuchet, Helvetica, Arial, sans-serif;

		font-size: 15px;

		line-height: 17px;

		color: #153c77;

		margin: 0px;

		padding: 0px;

		font-weight: bold;

	}

h2.navheading {

		background: #2344a5 url("http://secure.bbdesign.com/lifespanfitness2/art/gr_navheading.png") no-repeat top right;

		width: 192px;

		height: 30px;

	}

Open in new window

0
Comment
Question by:bbdesign
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
ryangiglio earned 500 total points
Comment Utility
Have you tried putting padding-left on the span instead of the h2?  That shouldn't cause the h2 background image to move over.
0
 

Author Comment

by:bbdesign
Comment Utility
Yes, that works, thanks!

I actually found that by adding padding, but reducing the width and height accordingly, that works too.
0
 
LVL 8

Expert Comment

by:lharrispv
Comment Utility
that or change the margin of the span.

h2 span{position-absolute; margin-left:10px}


0
 

Author Comment

by:bbdesign
Comment Utility
What I missed is that I also needed to add some space above the text, and I wasn't able to do that with padding on a SPAN element. I guess you can only go left-to-right within a SPAN.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

CSS3 Custom checkboxes This article shows how to style the checkbox form element using only CSS. Works in: Chrome, FF, Safari, Opera, IE9+ Uses modernizr.js to check for :checked pseudo class, falling back to plain old checkboxes (IE8 and bel…
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…
In this Micro Tutorial users will learn how to embed custom fonts into websites using @font-face in CSS Select a font: Ensure the EULA allows you to use @font-face: Download the font: Get the browser-compatible files you need: Edit your CSS       - Name …
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…

771 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

12 Experts available now in Live!

Get 1:1 Help Now