5: ഫോണ്ടുകളും ടെക്സ്റ്റ് സ്റ്റൈലിംഗും
Chapter 4-ൽ നമ്മൾ CSS ഉപയോഗിച്ച് നിറങ്ങളും background-ഉം മാറ്റുന്നത് പഠിച്ചു. ഇനി ഒരു webpage-ലെ text എങ്ങനെ കൂടുതൽ readable-ഉം മനോഹരവുമാക്കാം എന്ന് പഠിക്കാം. ഇതിനായി CSS-ലെ font, text properties ഉപയോഗിക്കുന്നു.
ഒരു webpage-ന്റെ design-ൽ typography-ക്ക് വളരെ പ്രധാനപ്പെട്ട സ്ഥാനമുണ്ട്. ശരിയായ font, size, spacing, alignment എന്നിവ ഉപയോഗിച്ചാൽ content വായിക്കാൻ കൂടുതൽ എളുപ്പമാകും.
1. font-family
ഒരു text ഏത് font-ൽ കാണിക്കണം എന്ന് തീരുമാനിക്കാൻ font-family property ഉപയോഗിക്കുന്നു.
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: Arial;
}
</style>
</head>
<body>
<h1>My Website</h1>
<p>Welcome to my webpage.</p>
</body>
</html>ഒരു font കമ്പ്യൂട്ടറിൽ ലഭ്യമല്ലെങ്കിൽ മറ്റൊരു fallback font നൽകാൻ കഴിയും. അതിനാൽ സാധാരണയായി ഒന്നിലധികം font names എഴുതുന്നതാണ് നല്ല practice.
body {
font-family: Arial, Helvetica, sans-serif;
}ഇവിടെ browser ആദ്യം Arial ഉപയോഗിക്കാൻ ശ്രമിക്കും. അത് ലഭ്യമല്ലെങ്കിൽ Helvetica പരീക്ഷിക്കും. രണ്ടും ലഭ്യമല്ലെങ്കിൽ sans-serif എന്ന generic font family ഉപയോഗിക്കും.
2. Generic Font Families
CSS-ൽ ചില പൊതുവായ generic font families ഉണ്ട്. ഇവ ഉപയോഗിച്ചാൽ browser-ന് അനുയോജ്യമായ ഒരു font തിരഞ്ഞെടുക്കാൻ കഴിയും.
| Generic Family | സാധാരണ ഉപയോഗം |
|---|---|
| serif | അക്ഷരങ്ങളുടെ അറ്റത്ത് ചെറിയ strokes ഉള്ള fonts |
| sans-serif | ലളിതമായ modern fonts |
| monospace | എല്ലാ characters-നും ഏകദേശം ഒരേ വീതി |
| cursive | കൈയെഴുത്ത് പോലുള്ള style |
| fantasy | അലങ്കാരപരമായ fonts |
.serif {
font-family: Georgia, serif;
}
.sans {
font-family: Arial, sans-serif;
}
.code {
font-family: Consolas, monospace;
}3. font-size
Text-ന്റെ വലുപ്പം മാറ്റാൻ font-size property ഉപയോഗിക്കുന്നു.
h1 {
font-size: 36px;
}
p {
font-size: 18px;
}ഇവിടെ px എന്ന unit ആണ് ഉപയോഗിച്ചിരിക്കുന്നത്. CSS units അടുത്ത chapter-ൽ വിശദമായി പഠിക്കും.
4. font-weight
Text എത്ര കട്ടിയോടെ കാണിക്കണം എന്ന് font-weight ഉപയോഗിച്ച് നിയന്ത്രിക്കാം.
.normal {
font-weight: normal;
}
.bold {
font-weight: bold;
}
.heavy {
font-weight: 700;
}സാധാരണയായി 400 normal-നും 700 bold-നും ഉപയോഗിക്കാറുണ്ട്. ലഭ്യമായ font അനുസരിച്ച് മറ്റു weight values-ും ഉപയോഗിക്കാം.
5. font-style
Text italic ആക്കാൻ font-style property ഉപയോഗിക്കാം.
p {
font-style: italic;
}പ്രധാനമായ values normal, italic, oblique എന്നിവയാണ്. സാധാരണ text emphasis-ന് italic ആണ് കൂടുതൽ ഉപയോഗിക്കുന്നത്.
6. text-align
Text ഇടത്തോട്ടോ വലത്തോട്ടോ നടുവിലോട്ടോ align ചെയ്യാൻ text-align property ഉപയോഗിക്കുന്നു.
h1 {
text-align: center;
}
.left {
text-align: left;
}
.right {
text-align: right;
}center ഉപയോഗിച്ച് heading അല്ലെങ്കിൽ ചെറിയ section heading നടുവിൽ കാണിക്കാം. സാധാരണ paragraphs-ന് left alignment ആണ് കൂടുതൽ readable.
7. text-decoration
Text-ന് underline, overline, line-through തുടങ്ങിയ decoration നൽകാൻ text-decoration ഉപയോഗിക്കാം.
.underline {
text-decoration: underline;
}
.deleted {
text-decoration: line-through;
}Links-ൽ underline കാണുന്നത് സാധാരണമാണ്. എന്നാൽ സാധാരണ text-ൽ decoration അമിതമായി ഉപയോഗിച്ചാൽ readability കുറയാം.
8. text-transform
HTML text മാറ്റാതെ തന്നെ അതിന്റെ letter case presentation മാറ്റാൻ text-transform ഉപയോഗിക്കാം.
.uppercase {
text-transform: uppercase;
}
.lowercase {
text-transform: lowercase;
}
.capitalize {
text-transform: capitalize;
}uppercase ഉപയോഗിച്ചാൽ എല്ലാ letters-ഉം capital letters ആയി കാണിക്കും. lowercase എല്ലാ letters-ഉം small letters ആക്കും. capitalize ഓരോ word-ന്റെയും ആദ്യ letter capital ആയി കാണിക്കും.
9. line-height
ഒരു paragraph-ലെ ഓരോ വരിക്കും ഇടയിലുള്ള vertical space നിയന്ത്രിക്കാൻ line-height ഉപയോഗിക്കുന്നു. നീളമുള്ള text വായിക്കാൻ ഇത് വളരെ സഹായകരമാണ്.
p {
font-size: 18px;
line-height: 1.6;
}line-height: 1.6 എന്നത് font-size-ന്റെ അനുപാതത്തിൽ line spacing നൽകുന്നു. Body text-ന് 1.4 മുതൽ 1.8 വരെ values പല സാഹചര്യങ്ങളിലും ഉപയോഗിക്കാം.
10. letter-spacing
Letters തമ്മിലുള്ള horizontal spacing നിയന്ത്രിക്കാൻ letter-spacing ഉപയോഗിക്കുന്നു.
h1 {
letter-spacing: 2px;
}Heading-ുകളിൽ ചെറിയ letter spacing ഉപയോഗിക്കുന്നത് ചില designs-ൽ നല്ല visual effect നൽകും. വളരെ കൂടുതലായി ഉപയോഗിച്ചാൽ text വായിക്കാൻ ബുദ്ധിമുട്ടാകാം.
11. word-spacing
Words തമ്മിലുള്ള horizontal space നിയന്ത്രിക്കാൻ word-spacing ഉപയോഗിക്കുന്നു.
p {
word-spacing: 8px;
}ഇത് സാധാരണ paragraph text-ൽ വളരെ ചെറിയ അളവിൽ മാത്രം ഉപയോഗിക്കുന്നതാണ് നല്ലത്.
12. text-indent
ഒരു paragraph-ന്റെ ആദ്യ വരി കുറച്ച് അകത്തേക്ക് മാറ്റാൻ text-indent ഉപയോഗിക്കാം.
p {
text-indent: 30px;
}Print-style articles അല്ലെങ്കിൽ ചില പ്രത്യേക text layouts-ൽ text-indent ഉപയോഗപ്രദമാണ്.
13. text-shadow
Text-ന് shadow effect നൽകാൻ text-shadow ഉപയോഗിക്കാം.
h1 {
text-shadow: 2px 2px 4px gray;
}ആദ്യത്തെ value horizontal offset, രണ്ടാമത്തെ value vertical offset, മൂന്നാമത്തെ value blur amount എന്നിവയെ സൂചിപ്പിക്കുന്നു.
14. Typography Properties ഒരുമിച്ച് ഉപയോഗിക്കുക
ഒരു നല്ല webpage-ൽ ഓരോ property-യും പ്രത്യേകം ഉപയോഗിക്കുന്നതിനേക്കാൾ font, size, weight, alignment, line-height എന്നിവ ആവശ്യത്തിന് ചേർത്ത് ഉപയോഗിക്കുകയാണ് സാധാരണ.
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: Arial, sans-serif;
font-size: 18px;
line-height: 1.6;
}
h1 {
font-size: 36px;
font-weight: 700;
text-align: center;
letter-spacing: 1px;
}
p {
text-align: left;
}
</style>
</head>
<body>
<h1>Learning CSS</h1>
<p>
CSS helps us create readable and attractive webpages.
</p>
</body>
</html>15. Typography-യിലെ Readability
Text styling-ന്റെ പ്രധാന ലക്ഷ്യം decoration മാത്രമല്ല. User-ന് content എളുപ്പത്തിൽ വായിക്കാനും മനസ്സിലാക്കാനും കഴിയണം.
- Body text-ന് വളരെ ചെറിയ font-size ഒഴിവാക്കുക.
- Paragraph-ുകൾക്ക് മതിയായ line-height നൽകുക.
- വളരെ അധികം font families ഒരേ page-ൽ ഉപയോഗിക്കാതിരിക്കുക.
- Text-നും background-നും മതിയായ contrast നൽകുക.
- Heading-ുകളും body text-ും തമ്മിൽ വ്യക്തമായ size difference നൽകുക.
- Letter spacing, word spacing എന്നിവ അമിതമായി ഉപയോഗിക്കരുത്.
16. Inheritance
CSS-ൽ ചില text properties parent element-ൽ നിന്ന് child elements-ലേക്ക് സ്വാഭാവികമായി inherit ചെയ്യാം. ഉദാഹരണത്തിന് body-ക്ക് font-family നൽകിയാൽ അതിന്റെ ഉള്ളിലുള്ള പല elements-ക്കും അതേ font ലഭിക്കും.
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: Arial, sans-serif;
}
</style>
</head>
<body>
<h1>My Website</h1>
<p>This paragraph uses the body font.</p>
<button>Click Me</button>
</body>
</html>ആവശ്യമുള്ളപ്പോൾ ഒരു specific element-ന് സ്വന്തം font-family അല്ലെങ്കിൽ മറ്റൊരു text property നൽകി inherited value മാറ്റാം.
17. ഒരു ചെറിയ Article Example
ഇപ്പോൾ പഠിച്ച properties ഉപയോഗിച്ച് ഒരു ചെറിയ article section തയ്യാറാക്കാം.
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
}
article {
max-width: 700px;
margin: auto;
}
h1 {
font-size: 36px;
text-align: center;
font-weight: 700;
}
h2 {
font-size: 24px;
text-transform: capitalize;
}
p {
font-size: 18px;
}
.highlight {
font-weight: bold;
text-decoration: underline;
}
</style>
</head>
<body>
<article>
<h1>Learning Web Development</h1>
<h2>Why learn CSS?</h2>
<p>
CSS helps us control the appearance and layout of a webpage.
It makes content easier to read and more attractive.
</p>
<p class="highlight">
Practice is the best way to learn CSS.
</p>
</article>
</body>
</html>സാധാരണ Beginner Mistakes
- font-family-ൽ fallback font നൽകാതിരിക്കുക.
- വളരെ ചെറിയ font-size ഉപയോഗിച്ച് body text എഴുതുക.
- Paragraph-ുകൾക്ക് വളരെ കുറവ് line-height നൽകുക.
- ഒരു page-ൽ അനാവശ്യമായി നിരവധി font families ഉപയോഗിക്കുക.
- text-align: center ഉപയോഗിച്ച് മുഴുവൻ paragraph content center ചെയ്യുക.
- text-shadow, letter-spacing തുടങ്ങിയ effects അമിതമായി ഉപയോഗിക്കുക.
- Readability-നെക്കാൾ decoration-ന് പ്രാധാന്യം നൽകുക.
Practice Exercises
- ഒരു heading-ന്റെ font-size 40px ആക്കി നോക്കുക.
- ഒരു paragraph-ന് Arial, sans-serif font stack നൽകുക.
- ഒരു heading bold ആക്കി center align ചെയ്യുക.
- ഒരു paragraph-ന്റെ line-height 1.8 ആക്കി നോക്കുക.
- ഒരു heading-ന് letter-spacing 2px നൽകുക.
- ഒരു text-നെ uppercase ആക്കി നോക്കുക.
- ഒരു ചെറിയ article page ഉണ്ടാക്കി font-family, font-size, font-weight, line-height, text-align എന്നിവ ഒരുമിച്ച് ഉപയോഗിക്കുക.
Chapter Summary
- font-family ഉപയോഗിച്ച് font തിരഞ്ഞെടുക്കാം.
- font-size ഉപയോഗിച്ച് text-ന്റെ വലുപ്പം മാറ്റാം.
- font-weight ഉപയോഗിച്ച് text-ന്റെ thickness നിയന്ത്രിക്കാം.
- font-style ഉപയോഗിച്ച് italic പോലുള്ള styles നൽകാം.
- text-align ഉപയോഗിച്ച് text alignment മാറ്റാം.
- text-decoration ഉപയോഗിച്ച് underline, line-through തുടങ്ങിയ decoration നൽകാം.
- text-transform ഉപയോഗിച്ച് text case presentation മാറ്റാം.
- line-height ഉപയോഗിച്ച് വരികൾക്കിടയിലെ spacing നിയന്ത്രിക്കാം.
- letter-spacing, word-spacing എന്നിവ ഉപയോഗിച്ച് text spacing നിയന്ത്രിക്കാം.
- text-indent ഉപയോഗിച്ച് paragraph-ന്റെ ആദ്യ വരി അകത്തേക്ക് മാറ്റാം.
- text-shadow ഉപയോഗിച്ച് text-ന് shadow effect നൽകാം.
- നല്ല typography-യുടെ പ്രധാന ലക്ഷ്യം readability ആണ്.
Quick Quiz
Quiz & Self Assessment
അടുത്ത അധ്യായത്തിൽ CSS-ൽ ഉപയോഗിക്കുന്ന വിവിധ Units — px, %, em, rem, vw, vh തുടങ്ങിയവ — എങ്ങനെ പ്രവർത്തിക്കുന്നു എന്ന് പഠിക്കാം.