3. สารบัญ
เรือง
่
หน้า
Introduction
Syntax
Unit
Color
Insert styluses
Selector: HTML tag, class, id
Contextual selectors
Font
Text
Background
Border
Margin, padding
Link
Table
Classification
Positioning
21. <a href="http://www.enjoyday.net/webtutorial/xhtml/
index.html">XHTML</a><br />
<a
href="http://www.enjoyday.net/webtutorial/javascript
/index.html">JavaScript</a> </div>
</body>
</html>
Output HTML CSS XHTML JavaScript
Font คือ การกำาหนดลักษณะให้ตวอักษร ใน HTML เราจะใช้ tag
ั
<font face="ชนิดตัวอักษร" size="number"
color="สี">ข้อความ</font> น่าจะพอจำากันได้อยู่ แต่ในเอกสาร
HTML/XHTML แบบ strict จะถือว่า tag <font> เป็น tag ที่ล้า
สมัยแล้ว ไม่สามารถนำามาใช้งานได้ ให้เราใช้ CSS แทนค่ะ เราก็
สามารถใช้ CSS กำาหนดลักษณะให้ตวอักษรได้ โดยกำาหนดรูปแบบ
ั
font ผ่าน Property ต่างๆ ให้กับ HTML element เช่น
<p>,<div>,<span>,<h1> และอื่นๆ
Property Description Values
font-family ใช้กำาหนดชนิด font ที่ต้องการจะ เช่น Arial,
ให้แสดงผล โดยที่ font นั้นจะต้อง Helvetica,
มีอยู่ในเครื่องของผู้ใช้งานด้วย sans-serif
font-size ใช้กำาหนดขนาดของตัวอักษร ที่จะ xx-small
ให้แสดงผล /td> x-small
small
medium
large
x-large
xx-large
smaller
larger
18px
22. 70%
150%
font-style ใช้กำาหนดรูปแบบของตัวอักษรใน normal
ลักษณะต่างๆ italic
oblique
เอียง 45
องศา
font-variant ใช้แปลงตัวอักษรที่เป็นตัวพิมพ์เล็ก normal
ให้เป็นพิมพ์ใหญ่ Small-Caps
โดยที่ขนาดตัวอักษรยังคงเท่าตัว
พิมพ์เล็ก
font-weight ใช้กำาหนดความหนาของตัวอักษร normal
bold
bolder
lighter
100
200
300
400
500
600
color ใช้กำาหนดสีให้ตัวอักษร red
#000099
font เราสามารถกำาหนด property ให้ font-style
กับ font ได้ในคำาสั่งประกาศเดียว font-
variant
font-
weight
font-size
font-family
Example
<p style="font-family: AngsanaUPC; font-size:16pt;
color: green">
CSS ย่อมาจาก Cascading Style Sheet เป็นภาษาทีมีรูปแบบ
่
การเขียน Syntax ที่เฉพาะ และถูกกำาหนดมาตรฐานโดย W3C
23. (World Wide Web Consortium) เช่นเดียวกับ HTML และ XH
TML ใช้สำาหรับตกแต่งเอกสาร HTML/ XHTM ให้มีหน้าตา สีสัน
ตัวอักษร เส้นขอบ พื้นหลัง ระยะห่าง ฯลฯ อย่างทีเราต้องการ ด้วย
่
การกำาหนดคุณสมบัติให้กับ Element ต่างๆ ของ HTML </p>
OutputCSS ย่อมาจาก Cascading Style Sheet เป็นภาษาทีมีรูป ่
แบบการเขียน Syntax ที่เฉพาะ และถูกกำาหนดมาตรฐานโดย
W3C (World Wide Web Consortium) เช่นเดียวกับ HTML และ
XHTML ใช้สำาหรับตกแต่งเอกสาร HTML/ XHTM ให้มีหน้าตา
สีสัน ตัวอักษร เส้นขอบ พื้นหลัง ระยะห่าง ฯลฯ อย่างที่เราต้องการ
ด้วยการกำาหนดคุณสมบัติให้กับ Element ต่างๆ ของ HTML
Example
<p style="font-weight: bold">Love me Love my
dog</p>
<p style="font-family: sans-serif, Arial; font-size:16px;
font-style: normal; font-variant: small-caps; font-weight:
bold; color:#FF0033">Love me Love my dog</p>
<! -- เขียนอย่างย่อได้เป็น -->
<p style="font: normal small-caps bold 16px sans-serif,
Arial; color:#FF0033">Love me Love my dog</p>
Output
Love me Love my dog
Love me Love my dog
Love me Love my dog
Form
เรื่องของ CSS ที่เกี่ยวกับ Form มี 2 ส่วนที่อยากจะพูดถึงค่ะ ส่วน
แรก คือ การตกแต่ง Form Elements ด้วย style sheet และส่วน
ที่สอง คือ การทำา Form โดยไม่ใช้ Table หรือเรียกว่า Table less
Form Form Elements เราสามารถตกแต่ง ส่วนประกอบของ
31. <html>
<head>
<style type="text/css">
.cssform p{width: 300px;clear: left;margin: 0;padding:
5px 0 8px 0;padding-left: 155px; /*width of left column
containing the label elements*/border-top: 1px dashed
gray;height: 1%;}
.cssform label{font-weight: bold;float: left;margin-left:
-155px; /*width of left column*/
width: 150px; /*width of labels. Should be smaller than
left column (155px) to create some right margin*/}
.cssform input[type="text"]{ /*width of text boxes. IE6
does not understand this attribute*/
width: 180px;}
.cssform textarea{width: 250px;height: 150px;}
/*.threepxfix class below:
Targets IE6- ONLY. Adds 3 pixel indent for multi-line
form contents.to account for 3 pixel bug:
http://www.positioniseverything.net/explorer/threepxt
est.html
*/ html .threepxfix{margin-left: 3px;}
</style>
</head>
<body>
<form id="myform" class="cssform" action="">
<p>
<label for="user">Name</label>
<input type="text" id="user" value="" />
</p>
34. /* ----------- My Form ----------- */
.myform{margin:0 auto;width:400px;padding:14px;}
/* ----------- stylized ----------- */
#stylized{border:solid 2px
#b7ddf2;background:#ebf4fb;}
#stylized h1 {font-size:14px;font-weight:bold;margin-
bottom:8px;}
#stylized p{font-size:11px;color:#666666;margin-
bottom:20px;border-bottom:solid 1px #b7ddf2;padding-
bottom:10px;}
#stylized label{display:block;font-weight:bold;text-
align:right;width:140px;float:left;}
#stylized .small{color:#666666;display:block;font-
size:11px;font-weight:normal;text-
align:right;width:140px;}
#stylized input{float:left;font-size:12px;padding:4px
2px;border:solid 1px #aacfe4;
width:200px;margin:2px 0 20px 10px;}
#stylized button{clear:both;margin-
left:150px;width:125px;height:31px;background:#6666
66 url(img/button.png) no-repeat;text-align:center;line-
height:31px;color:#FFFFFF;font-size:11px;font-
weight:bold;}
</style>
</head>
<body>
<div id="stylized" class="myform">
<form id="form" name="form" method="post"
action="index.html">
<h1>Sign-up form</h1>
<p>This is the basic look of my form without table</p>
35. <label>Name
<span class="small">Add your name</span>
</label>
<input type="text" name="name" id="name" />
<Label>Email
<span class="small">Add a valid address</span>
</label>
<input type="text" name="email" id="email" />
<Label>Password
<span class="small">Min. size 6 chars</span>
</label>
<input type="text" name="password" id="password" /
>
<button type="submit">Sign-up</button>
<div class="spacer"></div>
</form>
</div>
</body>
</html>
Output
Sign-up form
This is the basic look of my form without table
Name Add your name Email Add a valid address
Password Min. size 6 chars Sign-up
Background
เราสามารถกำาหนดลักษณะพื้นหลังของ Element ต่างๆ เช่น
<body>, <table>, <p>, <h1>, <h2>, <div> เป็นต้น
Propert Description Values
36. y
backgr ใช้กำาหนดว่าต้องการ fixed fix อยู่กับที่
ound- ให้ภาพพื้นหลังนั้นอยู่ scroll เลื่อนตาม Scroll
attach กับที่ หรือว่าเลื่อนไป Bar
ment ตาม Scroll Bar
backgr ใช้กำาหนดทั้งสี พืน ้
color-rgb รหัสสี
ound- หลังของเว็บเพจ หรือ color-hex
color ตาราง color- ชื่อสี
name
transpare
nt
backgr ใช้กำาหนดรูปภาพ ให้ url ของรูป เช่น
ound- พื้นหลังของเว็บเพจ url(images/bg.
image หรือตาราง jpg)
backgr ใช้กำาหนดตำาแหน่ง top left
ound- การจัดวางรูปภาพพื้น top center
positio หลัง top right
n center left
center
center
center
right
bottom
left
bottom
center
bottom
right
x% y%
xpos ypos
backgr กำาหนดรูปภาพพื้น repeat ไม่ให้มีการวางต่อ
ound- หลังว่าต้องการให้มี repeat-x รูปภาพ
repeat การเรียงต่อรูปภาพ repeat-y วางต่อรูปภาพ
หรือไม่ no-repeat แนวนอน
วางต่อรูปภาพ
แนวตั้ง
61. value description
none ไม่แสดงวัตถุนั้น
block แสดงเป็น block โดยขึ้นบรรทัด
ใหม่ก่อน
inline เป็นค่า Default โดย element
จะ่ี ่ ่ แสดงแบบ inline ไม่มีการ
ขึนบรรทัดใหม่
้
list-item แสดงเป็นลิสต์รายการ
run-in The element will be displayed
as block-level or inline
element depending on
context
compact The element will be displayed
as block-level or inline
element depending on
context
marker
table The element will be displayed
as a block table (like
<table>), with a line break
before and after the table
inline-table The element will be displayed
as an inline table (like
<table>), with no line break
before or after the table
table-row- The element will be displayed
group as a group of one or more
rows (like <tbody>)
table- The element will be displayed