Contenido del Curso
CSS Fundamentals
CSS Fundamentals
Connecting HTML and CSS
Unveiling the Three Paths of CSS
The visual appearance of a webpage relies on the synergy between HTML and CSS. These technologies work in three distinct ways to style content: inline styles, embedded style sheets, and external style sheets. Let's explore each approach, highlighting their strengths and limitations.
Inline Styles
Inline styles allow applying CSS directly to an HTML element using the style
attribute. This method is simple and useful for quick, dynamic changes. However, the drawback is their limited scope; they can't be easily extended or reused across different elements.
index.html
In this example, the color: blueviolet
style is applied directly to the <p>
element, making the text appear in blueviolet. This style affects only this specific <p>
tag.
Embedded Style Sheet
The embedded style sheet resides within an HTML document's <head>
, encapsulated within <style>
tags. This method allows us to tailor styles specifically to a single page. However, it lacks the versatility needed to be shared across multiple pages.
index.html
Here, the <style>
tag in the <head>
section defines styles for all <p>
elements. The text color is set to blueviolet, and the font size is increased to 36px. These styles are applied consistently across all document's <p>
elements.
External Style Sheet
The external style sheet is the gold standard for CSS management in larger projects. It involves linking an external .css
file to your HTML document using the <link>
tag in the <head>
. This method promotes scalability, maintainability, and reusability, making it ideal for multi-page projects.
index.html
index.css
The external .css
file contains reusable styles for the entire project. Here, all <p>
elements in the HTML document are styled using the rules defined in the index.css
file. The rel="stylesheet"
attribute in the <link>
tag specifies the relationship between the HTML and the CSS file.
Note
- Inline Styles are suitable for single-element styling but lack reusability;
- Embedded Style Sheet is great for styling a single page;
- External Style Sheets excel in managing styles across multiple pages, streamlining your design process.
¡Gracias por tus comentarios!