Layout is broken after uploading to web server - html

I developed a small site (100% css layout). I have tested it on IE, Firefox and it looks fine.
After I upload it on my hosting company web server layout is broken only on internet explorer. I mean css is loaded properly but some elements are not at their places. I checked several times the css files on my local pc and the webserver and they have same content.
For example
#main{
position: relative;
width: 960px;
margin: 0 auto;
}
The code above puts #main div at the center of the screen. On my pc it work fine on IE, Firefox etc. But on web server that div floats to left on IE
What could be wrong ?

Internet Explorer has a number of things it uses to determine document rendering mode. The document being local or on the Internet is one of them.
Add
<meta http-equiv="X-UA-Compatible" content="IE=edge">
And then check the documents are consistent (either broken in both or working in both). If so, that confirms what the problem is and you just need to fix the CSS to work with IE in its best standards mode.
Microsoft provide more details.
Also make sure you aren't using the Compatibility button on the toolbar to force compatibility with older, buggier versions of IE.

For earlier versions of IE, you needed to add an extra bit of CSS to get things centered, i.e.:
body {text-align: center};
Then you'd also need to add text-align:left; to the first child div so the text isn't centered:
#main{
position: relative;
width: 960px;
margin: 0 auto;
text-align: left;
}
If the browser is behaving as an earlier version I reckon this could be the issue, so try adding this to your code.

Related

margin-left, margin-right does not work in Android Browser

Consider this code below:
<!doctype html>
<html>
<body>
<div style="background-color: yellow; width: 100vw; height: 100vh; text-align: center;">
<button style="display: block; margin-left: auto; margin-right: auto;">This is a button</button>
</div>
</body>
</html>
I tried to run it in Chrome and Mozilla, it produces the output below:
However, when I tried to run it in android browser, the button is in the LEFT side, seems like margin-left and margin-right doesnt work on the android browser. Any idea why?
You need to refresh your browser a few times, it must've cached the css. It looks the way you expect on android 4.4.
To Clear cache on chrome for android:
Touch Chrome menu > Settings.
Touch (Advanced) Privacy.
Touch Clear browsing data.
If it still does not work with my demo then let me know what version and browser you're using on android.
UPDATE: (for those wondering)
This was solved by adding a width to the element that is being centered. In order for margin:auto; to work on some old browsers, in this case we added width:auto;
Demo to test http://jsfiddle.net/Lw543yys/.
<>
<>
I would recommend using "reset.css" (or) "normalize.css"
I used one https://code.google.com/p/reset5/
which will fix browser issues across multiple browsers
You can also use http://necolas.github.io/normalize.css/
then your CSS will behave properly in all browsers

broken css on internet explorer

I have a web project that just breaks when I run it on Internet Explorer. Here it is, working as I want it to, on jsfiddle.
On IE, the display_area goes up and mixes with the toolbar up top. Also, the posts mixes into the side_display_area instead of them being confined to main_display_area, as is on the jsfiddle.
The problem I had was because IE, by default, uses 'Quirky' mode for its CSS rendering for the sake of compatibility with older code that was written ad hoc for IE. Although IE currently has different standard compliant modes(I can't attest to how compliant, however), it still defaults to this compatibility mode.
The solution is to override, or explicitly set, the rendering mode of IE via the X-UA-Compatible header. You can do this through html tags with:
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
</head>
more info
I think this may help http://css-tricks.com/the-css-overflow-property/
Consider adding some div to you horizontal menu and put some height on that
div.hmenu {
margin-left:auto;
margin-right:auto;
height: 20px;
min-width:1000px;
max-width:90%;
overflow:auto;
}

Css not working in chrome?

In chrome my website is cramped at the bottom.
I have used a clear float to clear it and it works in Firefox but in Chrome, the bottom is all cramped? (I'll not mention IE because haven't tested yet but can fix for IE just don't know how to for Chrome)
http://justbedroomdesigns.com/
Try to change css to this,
.post-block {
width: 370px;
height: auto;
float: left;
clear: none;
padding: 5px 2px 2px 2px;
}​
Perhaps you should correct the errors in your HTML first. For instance, decide if it should be HTML or XHTML, never reuse ID values, etc. If the problems still occur, ask again.
Take a look at this short post:
http://www.minitek.gr/tutorials/css-tutorials/item/12-how-to-fix-google-chrome-css?.html
More about Chrome rendering can be found here http://www.html5rocks.com/en/tutorials/internals/howbrowserswork/
One problem that I had with Chrome CSS is that when page is loaded locally (using XAMPP) it looks different
than when it's loaded from server.

Position: fixed Background DIV with images makes scrolling slow: How to make conditional CSS rules for browser-compatibility?

A known old known problem is that various old browsers both IE 7 (perhaps also IE 8) and FireFox 3.0 ~ 3.6, are the experiencing of very SLOW scrolling down through a webpage whenever a background image img or div with an image has the position: fixed; property.
Having built a site with this feature I noticed that in IE 7 (maybe 8 too) that had a terribly sluggish scrolling experience ruing the good enjoyment of the entire website. All other JQuery effects were also not smooth anymore. Now, as soon as I commented the position: fixed; property of the background image div:img, everything becomes good again.
<html><head>
img#bg {
/* position:fixed;*/
top:0;
left:0;
height:auto;
min-height:100%; /* proportionally fit height (eg panorama images) */
width: 100%;
z-index:-2;
}
</head>
<body><img src="background.jpg" id="bg"/></body>
</html>
Q1: How to make that line conditional? Users with IE7 or IE8 /*position:fixed;*/ and users with IE9 or FF4 position:fixed
Q2: Could anything in my css have triggered the bug except position: fixed? for example should img#bg be written differently?
Some links: MozzilaZine, StackOverflow, LinDesk
Thanks very much for your suggestions and ideas on this browserbug. Much appreciated!
Q1: How to make that line conditional?
For IE older than version 9 there's always a conditional comment override:
<!--[if lt IE 9]>
<style>img#bg { position: absolute; }</style>
<![endif]-->
For Firefox, one way would be to find some hack that distinguishes version 4 from its predecessors, which I can't really think of right now.
Q2: Could anything in my css have triggered the bug except position: fixed?
That and the fact that it's an image. But mostly the fixed positioning. This also happens if you used a background image with background-attachment: fixed, and is a well-known performance issue on those browsers.
Q1: How to make that line conditional?
If you'd rather not to use conditional comments (per BoltClock's reply), a summary of browser-specific CSS hacks can be found on Paul Irish's site.
Q2: Could anything in my css have triggered the bug except position: fixed?
Short answer: Yes, but probably none as much as position: fixed. If removing it fixes your issue, it's your biggest problem.
Slightly longer answer: box-shadow has been shown to cause performance issues. So will IE's proprietary filters. Inefficient selectors are sometimes mentioned, but it's debatable whether they have a large effect.
To profile your code, use the CSS Stress Test bookmarklet to drill down on exactly which selectors are causing your browser trouble. It's great!

why does the page display differently in IE than google chrome?

Certain pages display terribly in IE generally, what is the best approach to solving these issues?
You forgot to add a doctype, so your page is in Quirks Mode.
Add this (the HTML5 doctype) as the very first line:
<!DOCTYPE html>
and it should look better.
Although, changing the Document Mode manually (using Developer Tools; hit F12), it still doesn't look right. There are evidently other problems with the page.
The most pertinent problem (after escaping Quirks Mode) is this:
<body style="margin: 0; padding; 0;background-color: 4DA2CA;">
Internet Explorer is not showing any background colour because you forgot the # before the colour. (And you have padding; 0, with a ; instead of :)
This will work:
<body style="margin: 0; padding: 0; background-color: #4DA2CA">
But you shouldn't be using inline styles in the first place..
This would be better:
<body>
with CSS in your stylesheet:
body {
margin: 0;
padding: 0;
background-color: #4DA2CA
}
you mean that in IE the Div's are smaller.Thats because in IE css border,margin are included in the width declared.So, if you have given a div width of 100px and a margin of 10px both sides then in IE the actual visible width of this div will be 100-10-10=80px.To solve the problem you can use child css decleration.
Considering our example if you want to show this div 100px width in both the browsers do the following
.mydiv{ /*This deceleration will be understood by all the browsers*/
margin:10px;
width:120px;
}
html>body .mydiv{ /*This deceleration will not be understood by IE browsers so other will override the width*/
width:100px;
}
Using this you can uniform the width of your Divs across both IE and non-ie browsers
Instead of pointing out the reason for each element's different way of rendering in IE, I would strongly recommend not re-inventing the wheel each time you create a new page element.
Even in modern standards-complaint browsers, CSS can be very unpredictable, so it's better to use bullet-proof snippets of code from trusted sources such as
CSS the Missing Manual
CSS the Definitive Guide
CSS Cookbook
Start out with working blocks of HTML/CSS and modify them to your liking and test cross-browser from there. The whole process will be much less frustrating.