tags:

views:

139

answers:

4

Hello,

I wonder why does this style not work in IE and FF, but in Chrome ONLY

#show{top:10%; position:relative; margin: 0px auto; width:100%;}

[Edit]

If I want to make the same work in IE and FF, what do I have to do

Thanks Jean

A: 

Can you provide the relevant HTML markup too? And which version of IE you are using.

One problem could be additional CSS styling that the element with ID 'show' inherits.

Jon
@Jean - Also, what do you mean by "not working"? Is the positioning wrong, or the width, or what?
latentflip
@latenflip yes the positioning is wrong, its right on top
Jean
@jon <div id=#show>....anything goes here</div>
Jean
A: 

To separate styles between IE and FF, Chrome, etc use Conditional Comments.

<!--[if lt IE 9]>
<link href="path-to-file/IE.css" rel="stylesheet" type="text/css" />
<![endif]-->

This will tell IE to use a different stylesheet than IE, FF and other browsers.

IE is a beast that won't work without some trial and error, so set up that stylesheet and play with it til it does what you want.

To separate styles within your stylesheet, use this; it's a great resource and has helped me a great deal! CSS browser selectors. It's a Javascript plugin that will read any styles that start with .webkit, .ie, etc and apply those styles only to that browser.

Kyle Sevenoaks
Thats one option, is there something that I can write into one CSS file to get both work
Jean
By nature IE and FF and Chrome are all different, I've had to setup four or five different stylesheets to get all the browsers to behave the same. One browser will interpret styles slightly differently (or a lot different in IE's case) from others.
Kyle Sevenoaks
Conditional comments won't help when Jean is having problems between Chrome and Firefox. In the majority of cases you should be able to get Firefox and Chrome to render a page very similarly without having to resort to conditional comments or other hacks. IE may be a different story, but if we can figure out what's going wrong in FF it may just work in IE anyway.
latentflip
Agreed, but there *are* differences between FF and Chrome, and that's why I offered the JS plugin solution too. :)
Kyle Sevenoaks
Oh, sorry I missed that. Although personally I would advise developing with progressive enhancement in mind (http://en.wikipedia.org/wiki/Progressive_enhancement) and use as little browser specific code and JS hacks as possible. This will make your html and css much easier to follow and easier to maintain in the long run. Just my 2 cents.
latentflip
I totally agree with you, but for the things my client wants, this is all I can do.
Kyle Sevenoaks
A: 

Are you trying to position your #show div 10% down from the top of it's containing div? If so try this:

html:

<div id=#your_container>
  <div id=#show>
    Content
  </div>
</div>

css:

#your_container {height: 200px; position: relative}
#show {top: 10%; position: absolute}
latentflip
#show is the parent
Jean
Okay, I think you need to explain a little better what it is you are trying to achieve. I don't quite understand what the problem is. Can you post screenshots of firefox vs chrome to something like http://yfrog.com/ for comparison?
latentflip
A: 

top:10%; position:relative;

10% of what? For a relative-positioned element, percentage dimensions are measured relative to the parent element's size. Does the parent element have a height: applied? If it doesn't, that's why you're getting no movement: you're saying “move the top by 10% of ‘auto’, which is an indeterminate amount”.

If you want 10% of the browser viewport height, you must tell every element between the root html and the element you're positioning to use the full height of its parent. ie.:

html, body { height: 100%; }
bobince
There is no need for the height: 100%; in the body, top:10% means, start from 10% top irrespective of top of window or div parent
Jean
CSS 2.1 s10.5: “If the height of the containing block is not specified explicitly, and this element is not absolutely positioned, the value computes to 'auto'.” So yes, there very much is a need for an explicit height on the parent, and if that explicit height is in `%` then the parent's parent must have an explicit height too, all the way up to `<body>` and `<html>`. (The only time this doesn't happen is in Quirks Mode, but that introduces many other problems.)
bobince
@bobince #show is the parent
Jean
No, it's not. `#show` is the element you are positioning. What is the parent of `#show`, and does it have a `height:` style?
bobince