Showing posts with label CSS. Show all posts
Showing posts with label CSS. Show all posts

Tuesday, July 19, 2011

CSS style word-break:break-all

CSS style
word-break:break-all
table-layout:fixed


Tuesday, November 10, 2009

IE6 png fix

Javascript method (modified from source: http://homepage.ntlworld.com/bobosola)

function pngfix() {
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

if ((version >= 5.5) && (version < 7.0) && (document.body.filters)) {
for (var i = 0; i < document.images.length; i++) {
var img = document.images[i]
var imgName = img.src.toUpperCase()
if (imgName.substring(imgName.length - 3, imgName.length) == "PNG") {
var imgID = (img.id) ? "id='" + img.id + "' " : ""
var imgClass = (img.className) ? "class='" + img.className + "' " : ""
var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
var imgStyle = "display:inline-block;" + img.style.cssText
if (img.align == "left") imgStyle = "float:left;" + imgStyle
if (img.align == "right") imgStyle = "float:right;" + imgStyle
if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
var strNewHTML = " + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
+ "(src=\'" + img.src + "\', sizingMethod='scale');\">
"
img.outerHTML = strNewHTML
i = i - 1
}
}
}
}

function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof (window.onload) != 'function') { window.onload = func; }
else { window.onload = function() { oldonload(); func(); } }
}

addLoadEvent(pngfix);


2. CSS method:
#template
{
_background-image: none;
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../../images/guide2.png', sizingMethod='scale');
}

Friday, November 7, 2008

Make use of CSS Rule Objects

Typically, we define CSS in an external stylesheet and then use it.

In previous project, I am required to change the rules defined in CSS dynamically. We normally add or remove rules most of the time and seldom change them. In this case, we should use CSS Rule to deal with it.

CSS Rule Object provide the ability to access and modify rules defined in CSS.

Since IE and Firefox have different implementation, we first look at how to use it:

BrowserUsage
Internet Explorerdocument.styleSheets[0].rules[0]
Firefoxdocument.styleSheets[0].cssRules[0]

Let's modify a CSS Rule to see how powerful it is.
For example, we have one stylesheet imported and the content is shown below:

p{
font-size:10px;
}

You want to change this rule so that content inside tag will be in font-size:12px. Here's the code:

var cssSheet=document.styleSheets[0];
var rule=cssSheet.cssRules? mysheet.cssRules[0]: cssSheet.rules[0]; // check compatibility between IE and Firefox
rule.style.fontSize="12px"; //remember in javascript we have to use fontSize instead

This is all the code and it is very simple. We still have a better solution in this case. It is the use of Javascript Framework. I personally recommend you to use JQuery.

Here is where you can find JQuery:
http://jquery.com/

I'll talk about it later.

Reference:

http://www.javascriptkit.com/dhtmltutors/externalcss3.shtml