Style Object
Style Object
Technologies
Style object
How to Apply
Dynamic Styles.
Dynamic Content.
Dynamic Styles
Font Styles
Text Styles
Background Images
Opacity
Font Styles
border-width:width
CSS and DOM Reference. Values
object.style.borderWidth="width"
Sets the width of a border surrounding a page
element.
border-top-width:width
object.style.borderTopWidth="width"
The width can be applied to all borders (border-
width, borderWidth) or to selected borders.
border-right-width:width
Widths can be
object.style.borderRightWidth="width"
thin
medium
border-bottom-width:width
thick
object.style.borderBottomWidth="width"
npx
border-left-width:width
object.style.borderLeftWidth="width"
Borders, Padding, and Margins (Cont.)
border-color:color
borderColor
border-top-color:color
borderTopColor
Sets the color of a border surrounding a page element.
border-right-color:color
The color can be applied to all borders (border-color,
borderRightColor
borderColor) or to selected borders. The color is specified as
a color name, hexadecimal value, or RGB value.
border-bottom-color:color
borderBottomColor
border-left-color:color
borderLeftColor
Borders, Padding, and Margins (Cont.)
Sets the location of the left and top edges of the background
image with a pair of values separated by a space. Values are
There are four different syntaxes you can use with this
property: the keyword syntax ("auto", "cover" and
background-size
"contain"), the one-value syntax (sets the width of the image
object.backgroundSize=“”
(height becomes "auto"), the two-value syntax (first value:
width of the image, second value: height), and the multiple
background syntax (separated with comma).
https://www.w3schools.com/cssref/css3_pr_background-
size.asp
CSS Format:
DHTML Format:
object.style.opacity=“0.4”;
object.style.filter=‘alpha(opacity=40)’; /* For IE8 and earlier */
How to Apply
Dynamic Styles
Dynamic Content
Positioning Page Elements
Attributes used:
o Positioning Styles
o Dynamic position
o Dynamic sizing
o float
o overflow
o z-index
o Visibility
o display
o clip
Positioning styles
The CSS positioning properties allow you to position an
element.
CSS syntax:
position: static|absolute|fixed|relative|initial|inherit;
DHTML Syntax
object.style.position=“static|absolute|fixed|relative|initial|inherit”
Positioning styles (cont.)
o Fixed Positioning
• An element with fixed position is positioned relative to the browser window.
• It will not move even if the window is scrolled.
o Sticky Positioning
• A sticky element toggles between relative and fixed, depending on the scroll
position. It is positioned relative until a given offset position is met in the
viewport - then it "sticks" in place (like position:fixed).
• https://www.w3schools.com/howto/howto_css_sticky_element.asp
Positioning styles (cont.)
o Absolute Positioning
• An absolute position element is positioned relative to the first
parent element that has a position other than static.
• Absolutely positioned elements are removed from the normal
flow. The document and other elements behave like the
absolutely positioned element does not exist.
• Absolutely positioned elements can overlap other elements.
position:relative
<p style="font-size:18pt">
<span>Here</span>
<span style="position:relative; left:20px; top:10px">are</span>
<span style="position:relative; left:50px; top:20px">four</span>
<span style="position:relative; left:100px; top:-10px">words.</span>
</p>
position:absolute
<p style="font-size:18pt">
<span>Here</span>
<span style="position: absolute; left:20px; top:10px">are</span>
<span style="position: absolute; left:50px; top:20px">four</span>
<span style="position: absolute; left:100px; top:-10px">words.</span>
</p>
Positioning Page Elements (cont.)
Attributes used:
o Positioning Styles
o Dynamic position
o Dynamic sizing
o float
o overflow
o z-index
o Visibility
o display
o clip
Dynamic Position
Instead of using pixelLeft and pixelTop, you can use left, top as
following:
//To get its value:
var x=parseInt(object.style.left)+100;
//To set its value:
Object.style.left = x + "px“;
Positioning Page Elements (cont.)
Attributes used:
o Positioning Styles
o Dynamic position
o Dynamic sizing
o float
o overflow
o z-index
o Visibility
o display
o clip
Dynamic sizing
Attributes used:
o Positioning Styles
o Dynamic position
o Dynamic sizing
o float
o overflow
o z-index
o Visibility
o display
o clip
float
DHTML object.style.clear=“left|right|both|none|inherit|initial”
Positioning Page Elements (cont.)
Attributes used:
o Positioning Styles
o Dynamic position
o Dynamic sizing
o float
o overflow
o z-index
o Visibility
o display
o clip
overflow
CSS syntax
overflow: visible|hidden|scroll|auto|initial|inherit;
DHTML syntax
object.style.overflow="visible|hidden|scroll|auto|initial|inherit"
Overflow (cont.)
Property values:
Value Description
The overflow is not clipped. It renders outside the element's box.
visible
This is default
The overflow is clipped, and the rest of the content will be
hidden
invisible
The overflow is clipped, but a scroll-bar is added to see the rest of
scroll
the content
If overflow is clipped, a scroll-bar should be added to see the rest
auto
of the content
Attributes used:
o Positioning Styles
o Dynamic position
o Dynamic sizing
o float
o overflow
o z-index
o Visibility
o display
o clip
z-index
DHTML syntax
object.style.zIndex=n
Positioning Page Elements (cont.)
Attributes used:
o Positioning Styles
o Dynamic position
o Dynamic sizing
o float
o overflow
o z-index
o Visibility
o display
o clip
Visibility
DHTML syntax
object.style.visibility="hidden|visible|collapse”
Collapse: Only for table elements. collapse removes a row or column, but it
does not affect the table layout. The space taken up by the row or column will
be available for other content.
Attributes used:
o Positioning Styles
o Dynamic position
o Dynamic sizing
o float
o overflow
o z-index
o Visibility
o display
o clip
display
CSS syntax
display:block|inline|none ...
DHTML syntax
object.style.display=":block|inline|none …”
Display (cont.)
Display values:
Value Description
Default value. Displays an element as an inline element (like
inline
<span>)
block Displays an element as a block element (like <p>)
none The element will not be displayed at all (has no effect on layout)
list-item Let the element behave like a <li> element
table Let the element behave like a <table> element
table-cell Let the element behave like a <td> element
table-column Let the element behave like a <col> element
table-row Let the element behave like a <tr> element
More properties:
http://www.w3schools.com/cssref/pr_class_display.asp
http://www.w3schools.com/jsref/prop_style_display.asp
Display (cont.)
More:
https://www.w3schools.com/css/css_inline-block.asp
https://stackoverflow.com/questions/9189810/css-display-inline-vs-inline-block
http://dustwell.com/div-span-inline-block.html
https://alligator.io/css/display-inline-vs-inline-block
http://learnlayout.com/inline-block.html
Positioning Page Elements (cont.)
Attributes used:
o Positioning Styles
o Dynamic position
o Dynamic sizing
o float
o overflow
o z-index
o Visibility
o display
o clip
clip
DHTML syntax
object.style.clip=(top,right,bottom,left)
Clip(Cont.)
clip:rect(top,right,bottom,left)
How to Apply
Dynamic Styles
Dynamic Content
Dynamic Content
<script>document.writeln(“Thank
You!”)</script>