Safari Doesn't Understand Simple CSS

Safari doesn't seem to understand simple background images (or even background colors, for that matter) in the body tag in CSS.

Here's my code:

body {
margin: 0px;
padding: 10px 0px;
background: #000000 url(../images/background.gif) no-repeat center top;
}

Everything is in order, it SHOULD work. It works in Firefox, Internet Explorer 6 and 7, but not in Safari. Usually I don't care how my sites look in Safari, because only about 5% of the world uses it, but when you've got a client dumb enough to use Safari exclusively, then it's a problem.

I Build My Own PCs, Windows Vista, Intel Core 2 Quad Extreme 3.0GHz 1333MHz FSB, ASUS P5E3 Deluxe/WiFi-AP Motherbo

Posted on Feb 21, 2008 8:23 AM

Reply
23 replies

Feb 21, 2008 12:37 PM in response to mkimitch

Is your CSS in the page or linked from a separate file? Check those relative paths...

Is the position and no-repeat hiding it somewhere? Try allowing it to repeat and see if it fills your element. Then maybe you can figure out if it's being positioned incorrectly.

Also try using the element inspector (google "safari inspector" to enable it) to see what effective styles your element has. There you can find the url for the background-image and right-click on it to see if it's correct.

Still strange that it would work in Firefox, but not Safari though.

Feb 22, 2008 6:31 AM in response to heath28m

Wow... so because I had some comments before @charset "utf-8"; it doesn't display the background image?

That's pretty crazy, but oh well, now I know.

Thanks for the suggestions, I don't know why I didn't think to validate my code sooner!

I'm not going to worry about the warnings about same background colors on multiple elements... that seems to be a more semantical/cleaning-up-the-code issue and that's not my biggest concern at the moment.

Message was edited by: broomstick3

Feb 22, 2008 8:48 AM in response to mkimitch

Well, in my opinion.. I think it could be the few missing closing tags maybe.. in the XHTML code which is there in the page.. With the character encoding issue it defaults back to UTF-8 anyway..

Its weird like I mentioned at the end of that post... I had half of a section that wasn't even separated by any code, disappear.. it would not display part of it .. I just know Safari hates unclosed tags.. Starts turning its nose up at the page and wont load everything.. LOL..

Message was edited by: heath28m because something stupid seems to be going on with the forum..:(

Message was edited by: heath28m

Feb 21, 2008 11:55 AM in response to Andrew Vit

Thanks for your input, and I tried it out, however it still didn't work.

A few months ago I read an article about how attribute order is important, especially when coding for Safari. I had always followed the

background: color url() repeat x-axis y-axis;

rule of thumb. However, I just tried challenging this on another site I'm working on, and it looks like even Safari is a little more forgiving than I had once thought.

http://www.adphi-mn.org/sandbox/alphadeltaphi/

In this example, I have the following for my body tag:

body {
margin: 0px;
padding: 0px;
background: #000000 url(../images/bg.jpg) no-repeat top center;
font-family: "Trebuchet MS", "Lucida Grande", LucidaGrande, Lucida, Helvetica, Arial, Sans-serif;
}

And it works! no only does the repeat come before the x- and y-axis, but the order of the axis' are even reversed.

Now I'm beginning to think this may be more than a browser issue, and perhaps a server issue. Especially considering I've been having quite a bit of trouble with the server for the KBS/Medifast Web site.

Feb 21, 2008 9:10 AM in response to mkimitch

Sorry for the negativity. I'm usually not so negative, it's just irritating that all of these browser makers can't just come together and decide on one unified method for rendering code... but there's no money in that.

This is the Web site I'm having this issue on:

http://www.kbsmedifast.com/

I'm currently using this for my body tag:

body {
margin: 0px;
padding: 10px 0px;
background: #000000 url( http://www.kbsmedifast.com/images/background.gif) no-repeat center top;
}

I'm not using a relative path, and it still doesn't work in Safari. I'm using version 3.0.4(523.15). If I go directly to that image path in Safari, I can biew the image, so it's not that. I'm stumped.

Feb 21, 2008 9:52 AM in response to closecloseclose

Yes, in my first post I used a relative path. In my second I tried it without a relative path, but it still didn't work.

Everything on my site is one directory above the index. In fact, the initial index file (kbsmedifast.com/index.php) gives a 301 redirect to kbsmedifast.com/kelly medifast_procycling/index.php. This way everything is on the same plane and everything refers to everything else by going back one directory and then into the directory being requested.

So it doesn't seem to be an issue with my file structure, nor does it seem to be an issue with any relative path.

Again, this works correctly in every other major browser. Safari is the only browser that is having this problem.

I'm looking to figure out why Safari is having a problem with this, so I can find a work around.

Feb 21, 2008 5:02 PM in response to mkimitch

The problem here isn't Safari or the other browsers.

The problem is CSS. What a pain CSS is. There is a way around it's stupidity at rendering in different browsers.

Use .NET for your graphics. This will allow .NET to deal with browser discrepancies.

It works ten times better to let the system handle remembering what browser wants a 1-pixel difference here, or a table moved up there, etc, etc.

Feb 22, 2008 7:07 AM in response to Hax Or

Yeah, there are a ton of different browsers out there, but if you look at your site statistics (I use Google Analytics), there really are only 3 major browsers that most people use: IE, Firefox and Safari. At least, this is what my experience has taught me.

It's like search engine optimization. You really only have to focus on the top 3 search engines: Google, MSN and Yahoo. Most every other search engine either gets a large number of their search engines results from one of the big 3, or their search result coverage just isn't all that extensive.

Feb 22, 2008 8:31 AM in response to Hax Or

And of those, most people use IE 6 or 7. I wouldn't even worry about the people who use IE 5 or even IE 4, because they're few and far between and most likely if they're using such old browsers, they have no idea what they're doing much less would know how to do much on the Internets.

And even IE 6 and 7 aren't that difficult to code for. Yeah, throw in a _width hack in there, maybe a couple other hacks, but it's not much, nor is it that difficult.

In my opinion, build a CSS-driven, tabless design is a lot easier, cleaner and faster (the same goes for redesigning as well) than building a Web site with bulky and inflexible tables.

Feb 23, 2008 9:36 AM in response to heath28m

Oh I see. I use validators, but I don't find that the hardest part with CSS.

Say I create a design for a webpage with Illustrator. All of the layers are ready to go. I save out the background layers and then the transparent GIF layers above it.

Then I have to calculate the positions of everything... takes forever. Check Illustrator for coordinates in the image of a keypoint in the element, type it into CSS code, check it in the browser, make fixes for different browsers.

I've heard that Macromedia (Adobe) Fireworks was better at this type of work, but Version 8 didn't seem to offer anything over the way I'm doing it now.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Safari Doesn't Understand Simple CSS

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.