Give Me Layout! Please!
Setting hasLayout to true, or in other words giving layout, is relatively easy as opposed to setting it to false.
The following properties/values give an element layout:
-
position: absolute
-
float: left or right
-
display: inline-block
-
width: any value other than auto
-
height: any value other than auto
-
zoom: any value other than normal
-
writing-mode: tb-rl
As of IE7, overflow also sets hasLayout to true.
-
overflow: hidden or scroll or auto
-
overflow-x: hidden or scroll or auto
-
overflow-y: hidden or scroll or auto
You may be not familiar with zoom and writing-mode properties. Both are MicroSoft's proprietary extentions. They work only in IE and will not validate, therefore, I strongly advise you to put those into condcoms.
Zoom obviously zooms an element. Zoom: 2; will render the element twice its size, zoom: 1; will render the element with normal dimentions, and that is why I personally think this is the best property to use for giving an element layout since it has no other effects on the element.
Writing-mode property is a proposed addition to CSS that determines how the text should be written. The tb-rl value stands for "top to bottom, right to left" a typography style used in East Asia. Western typography is depicted "left to right, top to bottom", which would be lr-tb value for writing-mode property.
Properties overflow-x and overflow-y are not well supported at the moment.
Setting contenteditable attribute also gives an element layout.
<p contenteditable="true">so lame</p>
You should never use this one for setting hasLayout, it is shown here only for informational purpouses. Not only contenteditable is a proprietary MS attribute (thus it works only in IE and will not validate) but also allows the user to edit the content of the element, which in best case will confuse the user.
The hasLayout "property" is read-only, you cannot set it directly with JavaScript for example.