Text Color and Alignment
Text Color and Alignment అంటే ఏమిటి?
CSSలో text యొక్క రంగును మార్చడానికి color propertyని ఉపయోగిస్తాము. Text ఎటువైపు కనిపించాలో నిర్ణయించడానికి text-align propertyని ఉపయోగిస్తాము.
color property
color property text colorను మార్చుతుంది. దీనికి color name, hexadecimal value లేదా RGB value ఇవ్వవచ్చు.
color: navy;— color namecolor: #2563eb;— hexadecimal colorcolor: rgb(37, 99, 235);— RGB color
text-align property
text-align property textను horizontal directionలో align చేస్తుంది.
text-align: left;— ఎడమ వైపుtext-align: center;— మధ్యలోtext-align: right;— కుడి వైపు
ఈ propertiesను HTML elementsకి selector ద్వారా apply చేస్తాము. Browser HTML textను చదివి, CSS rules ప్రకారం దాని రంగు మరియు స్థానాన్ని మార్చుతుంది.
Runnable Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Text Color and Alignment</title>
<style>
body {
font-family: Arial, sans-serif;
}
h1 {
color: #1d4ed8;
text-align: center;
}
p {
color: #374151;
text-align: right;
}
</style>
</head>
<body>
<h1>Welcome to CSS</h1>
<p>CSS makes text clear and attractive.</p>
</body>
</html>
ఈ exampleను HTML-capable browser editorలో paste చేసి run చేయండి. CSSలో color values లేదా text-align values మార్చి browser resultను గమనించండి.
Simple Explanation
color text ఏ రంగులో కనిపించాలో నిర్ణయిస్తుంది. text-align text ఎడమ, మధ్య లేదా కుడి వైపు కనిపించాలో నిర్ణయిస్తుంది.
ఉదాహరణకు, headingను నీలం రంగులో మధ్యలో ఉంచడానికి ఇలా రాయవచ్చు:
h1 {
color: blue;
text-align: center;
}
ఒకే CSS ruleలో రెండు లేదా అంతకంటే ఎక్కువ declarations రాయవచ్చు. ప్రతి declaration చివర semicolon పెట్టడం మంచి పద్ధతి.
Real-Life Example
ఒక school notice boardను ఊహించండి. Notice headingను నీలం రంగులో మధ్యలో ఉంచితే అది వెంటనే కనిపిస్తుంది. Detailsను ముదురు బూడిద రంగులో కుడివైపు ఉంచవచ్చు. Web pageలో color మరియు text-align properties ఇదే విధంగా text presentationను మెరుగుపరుస్తాయి.
Code Examples
Heading Color మరియు Paragraph Alignment
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Text Color and Alignment</title>
<style>
body {
font-family: Arial, sans-serif;
}
h1 {
color: #1d4ed8;
text-align: center;
}
p {
color: #374151;
text-align: right;
}
</style>
</head>
<body>
<h1>Welcome to CSS</h1>
<p>CSS makes text clear and attractive.</p>
</body>
</html>
h1 selector headingకు నీలం రంగును ఇచ్చి, దాన్ని మధ్యలో ఉంచుతుంది. p selector paragraphకు ముదురు బూడిద రంగును ఇచ్చి, కుడివైపు align చేస్తుంది. #1d4ed8 మరియు #374151 hexadecimal color values.
The heading “Welcome to CSS” appears in blue at the center. The paragraph appears in dark gray aligned to the right.
Line-by-Line Explanation
ఇది HTML documentలో CSS రాయడానికి ఉపయోగించే style element ప్రారంభం.
ఇది మొత్తం pageలోని body elementను select చేస్తుంది.
Text కోసం Arial fontను ఉపయోగిస్తుంది. ఇది ఈ lesson యొక్క ప్రధాన property కాదు, కానీ text సులభంగా చదవడానికి సహాయపడుతుంది.
ఇది అన్ని h1 headingsకు CSS rulesను ప్రారంభిస్తుంది.
h1 textకు #1d4ed8 అనే నీలం hexadecimal colorను ఇస్తుంది.
h1 textను దాని అందుబాటులో ఉన్న horizontal space మధ్యలో ఉంచుతుంది.
ఇది paragraph elementsకు CSS rulesను ప్రారంభిస్తుంది.
Paragraph textకు ముదురు బూడిద రంగును ఇస్తుంది.
Paragraph textను కుడి వైపు align చేస్తుంది.
ఈ headingపై h1 selectorలోని color మరియు text-align rules apply అవుతాయి.
ఈ paragraphపై p selectorలోని color మరియు text-align rules apply అవుతాయి.
Try It
Try this CSS code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Try Text Styling</title>
<style>
h1 {
color: darkgreen;
text-align: center;
}
p {
color: #444444;
text-align: left;
}
</style>
</head>
<body>
<h1>My Web Page</h1>
<p>I am learning text styling with CSS.</p>
</body>
</html>
Practice
Practice: పై practice_codeలో h2 headingను purple రంగులో centerకి మార్చండి. Paragraphను #374151 రంగులో rightకి align చేయండి.
Hint: h2 selectorలో colorను purple మరియు text-alignను centerగా మార్చండి. p selectorలో colorకు #374151, text-alignకు right ఇవ్వండి.
Common Mistakes
text-color అని రాస్తాడు.Text రంగు మార్చడానికి సరైన property
color. ఉదాహరణ: color: blue;.
align-text అని రాస్తాడు.Text alignment కోసం సరైన property
text-align. ఉదాహరణ: text-align: center;.
text-align: middle; అని రాస్తాడు.Horizontal text alignment కోసం
center value ఉపయోగించాలి: text-align: center;.
ప్రతి declarationను
property: value; రూపంలో రాయండి. ఉదాహరణ: color: navy;.
Headingకు h1 లేదా h2 selectorను, paragraphకు p selectorను ఉపయోగించండి. Selector HTML elementతో సరిపోవాలి.
Interview Questions
CSSలో text రంగును మార్చడానికి ఏ property ఉపయోగిస్తారు?
Answer: Text రంగును మార్చడానికి color property ఉపయోగిస్తారు. ఉదాహరణ: color: blue;.
text-align property ఏం చేస్తుంది?
Answer: ఇది elementలోని textను left, center లేదా right వంటి horizontal positionsలో align చేస్తుంది.
CSSలో color valueను ఎలా రాయవచ్చు?
Answer: Color name, hexadecimal value లేదా RGB valueగా రాయవచ్చు. ఉదాహరణలు: red, #ff0000, rgb(255, 0, 0).
ఒకే selectorలో color మరియు text-align రెండింటినీ ఉపయోగించవచ్చా?
Answer: అవును. ఒకే CSS ruleలో ప్రతి declarationను కొత్త lineలో రాసి semicolonతో ముగించవచ్చు.
Exam Questions
Text రంగును blueగా మార్చే CSS declaration రాయండి.
Answer:
color: blue;
Paragraph textను మధ్యలో ఉంచే CSS declaration రాయండి.
Answer:
text-align: center;
Hexadecimal color value అంటే ఏమిటి?
Answer:
Colorను hexadecimal సంఖ్యా రూపంలో సూచించే value. ఉదాహరణ: #1d4ed8.
h1 headingను ఎరుపు రంగులో కుడివైపు align చేయడానికి CSS rule రాయండి.
Answer:
h1 { color: red; text-align: right; }
Quick Revision
colorproperty text రంగును మార్చుతుంది.text-alignproperty textను left, center లేదా rightకి align చేస్తుంది.- Colorను name, hexadecimal లేదా RGB valueగా రాయవచ్చు.
- ప్రతి CSS declarationను సాధారణంగా semicolonతో ముగించాలి.
- CSS selector సరైన HTML elementతో match అవ్వాలి.
