تحويل وتزيين النصوص في CSS: اجعل نصوصك أكثر جاذبية!
في هذا الدرس سنتعلم كيفية التحكم بشكل النصوص وتحسين مظهرها باستخدام Properties CSS القوية. هذه الـ Properties تمنحك القدرة على تنسيق النصوص بصرياً دون الحاجة لتعديل المحتوى الأصلي في HTML، مما يجعل موقعك أكثر احترافية وسهولة في القراءة.
ما هي Property text-transform؟
تستخدم Property text-transform للتحكم في حالة الأحرف (Capitalization) في اللغات التي تدعم ذلك (مثل الإنجليزية). تكمن قوتها في أنها تغير المظهر البصري فقط؛ أي أن النص يظل كما هو في الكود المصدري، وهو أمر ضروري لتحسين تجربة المستخدم (UX) وتوحيد التصميم.
/* Basic example of text-transform */
.heading {
text-transform: uppercase; /* Converts all letters to uppercase */
}
.subtitle {
text-transform: lowercase; /* Converts all letters to lowercase */
}
.name {
text-transform: capitalize; /* Capitalizes the first letter of each word */
}
قيم Property text-transform الشائعة
توجد أربع قيم أساسية يمكنك الاعتماد عليها لتنسيق النصوص:
none: القيمة الافتراضية، يظهر النص تماماً كما كُتب في ملف HTML.uppercase: تحويل جميع الأحرف إلى كبيرة (مثال: hello → HELLO). تُستخدم غالباً في العناوين الرئيسية أو أزرار التنبيه.lowercase: تحويل جميع الأحرف إلى صغيرة (مثال: WORLD → world). مفيدة في بعض التصاميم العصرية أو عناوين الروابط (URLs).capitalize: تحويل الحرف الأول من كل كلمة إلى حرف كبير (مثال: john doe → John Doe). مثالية لأسماء الأشخاص والعناوين الفرعية.
/* Practical example showing the difference */
p.normal {
text-transform: none; /* Result: Hello World */
}
p.upper {
text-transform: uppercase; /* Result: HELLO WORLD */
}
p.lower {
text-transform: lowercase; /* Result: hello world */
}
p.cap {
text-transform: capitalize; /* Result: Hello World */
}
ما هي Property text-decoration؟
تُستخدم Property text-decoration لإضافة خطوط زخرفية للنص. الاستخدام الأكثر شيوعاً لها هو إزالة الخط التحتي الافتراضي الذي تضعه المتصفحات تحت الروابط <a> لجعل التصميم يبدو أنظف.
/* Remove underline from links to make them look like buttons or plain text */
a {
text-decoration: none;
}
Properties text-decoration المفصلة
في الإصدارات الحديثة من CSS، تم تقسيم text-decoration إلى Properties فرعية تمنحك تحكماً دقيقاً في شكل الخط ولونه وسمكه:
-
text-decoration-line: تحدد مكان الخط.underline: خط أسفل النص.overline: خط أعلى النص.line-through: خط يقطع النص (يُستخدم عادةً للإشارة إلى السلع المنتهية أو الأسعار القديمة).
-
text-decoration-color: تتيح لك اختيار أي لون للخط باستخدام (Hex, RGB, أو أسماء الألوان). -
text-decoration-style: تحدد شكل الخط.solid: خط مستمر (الافتراضي).double: خط مزدوج.dotted: خط منقط.dashed: خط متقطع.wavy: خط متموج.
-
text-decoration-thickness: تحدد سمك الخط (مثلاً2pxأو0.1em).
/* Examples of text-decoration-line */
.underline {
text-decoration-line: underline;
}
.overline {
text-decoration-line: overline;
}
.line-through {
text-decoration-line: line-through;
}
/* Combining multiple lines at once */
.under-over {
text-decoration-line: underline overline;
}
/* Examples of text-decoration-style */
.solid-line {
text-decoration-line: underline;
text-decoration-style: solid;
}
.dotted-line {
text-decoration-line: underline;
text-decoration-style: dotted;
}
.wavy-line {
text-decoration-line: underline;
text-decoration-style: wavy;
}
مثال شامل يجمع بين الـ Properties
لنطبق كل ما سبق في مثال عملي لإنشاء عناصر نصية ذات مظهر احترافي.
<!-- HTML -->
<p class="fancy-heading">Welcome to Codex Academy</p>
<a href="#" class="nice-link">Explore Courses</a>
/* CSS */
.fancy-heading {
font-family: Arial, sans-serif;
text-transform: uppercase; /* Convert text to uppercase */
text-decoration-line: overline underline; /* Line above and below */
text-decoration-color: #3498db; /* Blue color */
text-decoration-style: wavy; /* Wavy style */
text-decoration-thickness: 3px; /* Clear thickness */
text-align: center;
}
.nice-link {
text-decoration: none; /* Remove default underline */
color: #e74c3c; /* Red color */
font-weight: bold;
transition: 0.3s;
}
.nice-link:hover {
text-decoration: underline; /* Show underline on hover only */
text-decoration-style: dashed;
}
في هذا المثال، جعلنا العنوان يظهر بأحرف كبيرة مع خطوط متموجة زرقاء تزيد من جاذبيته. أما الرابط، فقد أزلنا خطه الافتراضي وأضفنا تأثير hover ليظهر خط متقطع عند تمرير الماوس، مما يحسن من تفاعل المستخدم.
ملخص سريع
text-transform: تتحكم في حالة الأحرف (كبيرةuppercase/ صغيرةlowercase/ بداية الكلماتcapitalize).text-decoration-line: تحدد موقع الخط (تحتunderline/ فوقoverline/ شطبline-through).text-decoration-style: تحدد شكل الخط (صلبsolid/ منقطdotted/ متموجwavy).text-decoration: هي الـ Property المختصرة (Shorthand) التي تجمع اللون والنمط والموقع في سطر واحد.
اختبر معلوماتك
أسئلة قصيرة تتأكد بها من فهمك للدرس قبل أن تنتقل.
التعليقات
شاركنا رأيك أو أسئلتك حول هذا المحتوى