Software Development
Wrestling with the Browser Event Queue Misja Alma 17 May, 2014
div#wrongStyle{{ color : red; font-size:19px; }IE applies above styles to the div but not Firefox. IE can correct such small errors but Firefox wont do that. Separating styles If you want to provide styling based on IE version you can use specify it in the following manner.
Developing styles for DIV based structure In div based structure each element on the web page is placed inside a div and styles will be applied to it. To position those div elements you can use absolute positioning with fixed width or relative positioning. Here the first thing we need to keep in mind is to separate positioning information from styling information. So that common styles like font, colors can be specified in top elements. It helps to maintain the layout without disturbing the styles. While developing these styles ,its a good idea to go in agile manner. i.e after applying each element check the page in all target browsers. This eases fixing the cross browser issues. If you are using absolute positioning you can develop each element in separate html file. These separate files or absolutely positioned div elements can be merged easily to form a complete web page. CSS width, padding problem The box model hack is used to fix a rendering problem in pre-IE 6 browsers, where by the border and padding are included in the width of an element, as opposed to added on. For example, when specifying the dimensions of a container you might use the following CSS rule:
#box { width: 100px; border: 5px; padding: 20px; }This CSS rule would be applied to:
In normal browsers above rule is interpreted as 100px width + two 5px borders + two 20px paddings. So the final width of the element will be 150px. But in pre-IE6 browsers the total width would be just 100px, with the padding and border widths being incorporated into this width. A simple way to solve this is to have one more div inside and specify width for inner one and padding and margin to the outer. The code will look like...This is some dummy division holding a dummy text
#box { width: 150px; } #boxInner { border: 5px; padding: 20px; }And the new HTML would be:
Using the above code will help to show the box width to 150px regardless of the browser. Selecting precise descendants Sometimes CSS selectors also behaves differently in different browsers. To apply styles to a particular element in the page you can use child selector ( " parent > child > child's child " ). In my case, I faced the following problem. I need to apply some style only to the first li under "parent" class ul element and I don't have any control over the html code.This is some dummy division holding dummy text
Now, you can specify the styling in the following way using child selector parent > li { style goes here}. There might be some other way for this. But I found it the above way useful as I can't change the html code. Using Table structure for page The most important thing we need to keep in mind while developing styles for tables is, on the top level element (usually body) specify padding, margin and border to be 0px. After that you can specify these attributes individually by assigning the div id or class where ever required. Also specify "cellpadding", "cellspacing" and "border" values in table tag explicitly, because the default values for these attributes differs from browser to browser. Conclusion You can find many other tips like this on net. Its always better to restructure our css and layout to make styling compatible with different browser rather than using some hacks. If you are using some hack it might work in the browser that you are testing and might not work on end user browser :) . These are the ones that I have found useful during part of my projects development You can also share your experiences ( or pains :) ) here while using CSS.
- Item 1
- Sub Item 1
- Sub Item 1
- Item 2