I have the following css class:
#header h1 {
float:left;
font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
font-size: 2.5em;
margin-top: 8px;
margin-left: 0.8em;
padding-left: 40px;
background: url("h1bkgrnd.png") no-repeat left center;
height: 100px;
}
And this html:
<div id="header">
<h1><br><br> Our Services</h1>
</div>
it works fine, but as you can see, I have a bunch of to push the text to the right. Otherwise, it sits on top of the picture.
Is there a better way to do this?
Thanks.
5 Answers 5
Unsurprisingly, to indent text you should use the text-indent CSS property.
#header h1 {
text-indent: 1em;
/* ... */
}
7 Comments
<p> inside your <h1> is invalid HTML.Add:
#header h1 {
padding-left: 20px; /*Or according with the picture size you have*/
}
Must work.
Comments
You have a few choices, but text-indent seems the most appropriate.
Comments
It depends, what are you trying to indent, are you indenting from another element or from another text.
p {
margin-left: 20px;
}
p {
text-indent: 20px;
}
9 Comments
<p> inside your <h1>, that's not even valid HTML.Separating out the image in an image tag looks like the best option if you do not really want the image to be in the background of the text.
HTML:
<img src="http://placekitten.com/g/50/100"/>
<h1>Our Services</h1>
CSS:
img{
float:left;
width:50px;
height: 50px;
}
h1{
padding-left: 60px;
}
http://cssdeck.com/labs/xixebfxw. In this case, I had to re-size the image by giving appropriate width and height as the text! Also margin-left also can be used alternatively for padding-left.
And if the spacing is not a matter of concern and you just need to place the text to the right and image in the left without removing the image as the the background, you can do: http://cssdeck.com/labs/wml9occf But this may not be the best option.
<img>tag instead of a background image with CSS<br>components in your<h1>. if you want it a distance from the top, use margins or padding appropriately.