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

CSS : Implement with JavaScript

Change CSS style with JavaScript
JavaScript can control CSS with "style" attribute and set "ID" to HTML element that you want to change. One thing that use should know is CSS syntax may not the same JavaScript. For Example:" background-color: Red;" to control them with JavaScript you must to change to "backgroundColor = Red;"


Syntax JavaScript
document.getElementById("tagID").style.cssattribute = cssvalue;


Example (Change BGColor)

<script language="JavaScript">
     function ChangeBgColor(color) {
document.getElementById('testbody').style.backgroundColor = color;  } 
</script>
<body id="testbody"> <center><br><br> 
     <input type="button" value="Red" onclick="ChangeBgColor('Red');">
     <input type="button" value="Green" onclick="ChangeBgColor('Green');"> 
     </center>
</body>
Figure 1: Example Result


Example (Change Visibility and Display)


<script language="JavaScript">
function removeElement()
  document.getElementById("D1").style.display="none";
}
function changeVisibility()
  document.getElementById("D2").style.visibility="hidden";
}
function resetElement() {
  document.getElementById("D1").style.display="block";
  document.getElementById("D2").style.visibility="visible"; 
</script>


<div id="D1">Box 1<br /> <img src="test1.jpg" width="100" height="80"><br/>
<input type="button" onclick="removeElement()" value="Remove" /></div>
<div id="D2">Box 2<br /> <img src="test2.jpg" width="100" height="80"><br/>
<input class="box"  type="button" onclick="changeVisibility()" value="Hide" /></div>
<div>Box 3<br /> <img src="test.jpg" width="100" height="80"><br/>
<input type="button" onclick="resetElement()" value="Reset All" />



Figure 2: Example Result


CSS : Position << Previous Chapter


CSS : Position

CSS Position
The position attribute specifies position that used for an element.

position : fixed || static || absolute || relative;
  - fixed can make the elements always show on a web page (following the document flow).
  - static is default position.
  - absolute can make an elements in any position on a web page. If absolute position overlapped the other element, the high level position will on the top.
  - relative is a normal position but add 20 pixel to the left element.

z-index : auto || number ;
  - specify level of an elements (High level will on the top).

Example Position

figure 1: Example Position
top : auto || pixels || cm || point ;
right : auto || pixels || cm || point ;
left : auto || pixels || cm || point ;
bottom : auto || pixels || cm || point ;
  - set an element's distance between edge and elements.

overflow : auto || visible || hidden || scroll ;
overflow-x : auto || visible || hidden || scroll ;
overflow-y : auto || visible || hidden || scroll ;
  - set scroll bar on the x, y or both.

Example (Fixed Header)
.divHead { 
   position: fixed; 
   top: 0px; left: 0px; 
   width: 100%; height: 50px; 
   padding: 5px 5px 5px 5px; 
   text-indent: 50px; 
   color: lightblue;
}

Example (Fixed Footer)
.divFoot { 
   position: fixed; 
   bottom: 0px; left: 0px; 
   width: 100%; height: 50px;
   padding: 5px 5px 5px 5px; 
   text-align: center; 
   color: gold;
}


CSS : Basic Attribute << Previous Chapter || Next Chapter >> CSS : Implement with JavaScrpt

CSS : Selector

CSS Selector
CSS allow to specify selector HTML element, "ID" and "Class"
- Selector HTML element is used to specify all of the HTML element (one write, all effected)
- Selector ID is used to specify a unique ID of the HTML element (one webpage, one id)
- Selector Class is used to specify group of the HTML element that select a specify Class (one write, use anywhere)


Example Selector ID
figure 1: CSS Implementation (Test Selector ID)

Example Selector Class
figure 2: CSS Implementation (Test Selector Class)

Group Selector
If an element has the same style, it can grouped selectors separate by ,

Example Group Selector
div, p { color: green; }

Introduction << Previous Chapter  ||  Next Chapter >> Basic Attribute

CSS : Basic Attribute

Basic CSS Attribute
CSS can do anything like an HTML Attribute but CSS is more powerful. CSS can specify Background position with non-repeatable and CSS Background can insert image on any tag like <p>, <div>, <fieldset> and etc.


CSS Background
background-color: colorname || #hex;
background-image: url('foldername/filename');
background-repeat: no-repeat || repeat-x || repeat-y;
background-position: HorizontalPosition VerticalPosition;


Example 
div { 
   background-color: Red; 
   background-image: url('Images/mypic.gif');
   background-repeat: no-repeat; 
   background-position: 
   Center Top; height: 500px; 
}
figure 1: Example 
CSS Text and Font

color: colorname || #hex;
text-align: left || right || center || justify;
vertical-align: middle || top || bottom;
text-indent: pixels;
text-decoration: underline || none;
font-size: pixels;
font-style: italic || none;


Example
p { 
   color: #FF0000;
   text-align: center;
   font-size: 30px; 
   padding: 5px 5px 5px 5px;
}

CSS Box (Table, div, p)
border: topstyle rightstyle bottomstyle leftstyle;


figure 2: Border Style

border-color: colorname || #hex;
border-width: toppixels rightpixels bottompixels leftpixels;
margin: toppixels rightpixels bottompixels leftpixels;
padding: toppixels rightpixels bottompixels leftpixels;
height: pixels, percentage;
width: pixels, percentage;


Example
table {
   border:outset outset outset outset; 
   border-color: gold;
   border-width: 5px; 
   padding: 5px 5px 5px 5px; 
}
figure 3: Example Box

CSS : Selector << Previous Chapter || Next Chapter >> CSS : Position

CSS : Introduction

What is CSS ?
CSS used to define how to display HTML elements and to solve a design problem on HTML. CSS is more powerful design and working like a HTML Attribute.

Snytax
  selector { attribute : value ;  attribute : value }
  *Selector is a HTML element, HTML id or Style Class that you want to change style.
  *Use : between Attribute and Value
  *Use ; between each Attribute
  *User /* css command */ to comment CSS

How to use CSS?
1. Inline Style (Using with tag, like HTML attribute)
    Syntax <HTMLelement style="attribute value ;  attribute value">
    Example <div style="font-size: 30px; color: gray;"> ... <div>

2. Internal Style Sheet (Embedded like JavaScript)
    Syntax                                                 Example
    <style type="text/CSS">                       <style type="text/CSS"> 
        selector {                                              div {
               attribute value                                    font-size: 30px;
               attribute value                                    color: red;
      }                                                              }
    </style>                                                    </style>   


3. External Style Sheet (Link CSS file)
    HTML Syntax <link rel="stylesheet" type="text/css" href="/stylesheetname.css"/>
    HTML Example <link rel="stylesheet" type="text/css" href="/Style/MyStyle.css"/>


4. Import Style (Import CSS file and allowed add new style)
    HTML Syntax 
    <style>                                                           <style>
      @import url("/stylesheetname.css");            @import url("/MyStyle.css"); 
               selector {                                              div {
                   attribute value                                        background-color: black;
                   attribute value                                        color: white;
      }                                                                     }
    </style>                                                        </style>   

Next  Chapter >> CSS : Selector

Related Posts Plugin for WordPress, Blogger...