Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

umbilical

macrumors 65816
Original poster
May 3, 2008
1,329
362
FL, USA
hi I need insert a style background inside the html on a li with a class, but I cant! I need inside the HTML not outsite .css

<li class="first" style='background: url(../img/image.jpg) no-repeat;'><a href="#">Text Text Text</a></li>

whats wrong in my code? help please, thanks
 
hi I need insert a style background inside the html on a li with a class, but I cant! I need inside the HTML not outsite .css

<li class="first" style='background: url(../img/image.jpg) no-repeat;'><a href="#">Text Text Text</a></li>

whats wrong in my code? help please, thanks

instead of using double quotes for the css styles, use single quotes and use the double quotes to contain the css instead of single quotes.
 
Your code works fine for me in safari. You probably have the location of the image wrong.

What tominated means is this

<li class='first' style="background: url(../img/image.jpg) no-repeat;"><a href="#">Text Text Text</a></li>
 
The syntax is fine.

When doing inline styling, that overrides any settings set in a class or ID. However, if it turns out the path is right, we'd need to see what properties are being set in the "first" class, i.e. sometimes people forget to set width and height properly and the background image won't show as the space is too small. Or countless other causes.

-jim
 
hi I need insert a style background inside the html on a li with a class, but I cant! I need inside the HTML not outsite .css

<li class="first" style='background: url(../img/image.jpg) no-repeat;'><a href="#">Text Text Text</a></li>

whats wrong in my code? help please, thanks

Inline styles are bad practice as CSS should be styling and separated from the content. Also as SrWebDeveloper stated, if you have other properties for the class "first" then that may be conflicting with the code.

Code:
<DOCTYPE ....
<html>
<head>
<style type="text/css">
.first {
   background: url("image.jpg") no-repeat;
}
</style>
</head>
<body>
...
<li class="first><a href="#">Blah blah</a></li>
...
</body>
</html>
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.