nimbuscode.dev/technologies/css
C:\> cat TECHNOLOGIES/CSS.md
Loading CSS documentation...

CSS

Style Sheet Language

1. Introduction

CSS (Cascading Style Sheets) is a style sheet language used for describing the presentation of a document written in HTML or XML. CSS describes how elements should be rendered on screen, on paper, in speech, or on other media.

While HTML provides the structure of a web page, CSS provides the visual styling and layout. CSS is designed to enable the separation of presentation and content, improving accessibility and providing more flexibility in the visual characteristics of the page.

2. Syntax Examples

Basic CSS Syntax
/* Basic selector and declaration block */
selector {
  property: value;
  another-property: value;
}

/* Example with actual values */
h1 {
  color: #333333;
  font-size: 24px;
  font-family: 'Arial', sans-serif;
  margin-bottom: 16px;
}

/* Class selector */
.button {
  background-color: #4CAF50;
  color: white;
  padding: 10px 20px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

/* ID selector */
#header {
  background-color: #f2f2f2;
  padding: 20px;
}
Selectors and Combinators
/* Element selector */
p {
  line-height: 1.6;
}

/* Descendant selector (space) */
article p {
  font-size: 16px;
}

/* Child selector (>) */
nav > ul {
  display: flex;
}

/* Adjacent sibling selector (+) */
h2 + p {
  margin-top: 0;
}

/* Attribute selector */
input[type="text"] {
  border: 1px solid #ccc;
}

/* Pseudo-classes */
a:hover {
  text-decoration: underline;
}

li:nth-child(odd) {
  background-color: #f0f0f0;
}
Modern CSS Features
/* Flexbox */
.container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 20px;
}

/* CSS Grid */
.grid-layout {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-gap: 16px;
}

/* Variables (Custom Properties) */
:root {
  --primary-color: #007bff;
  --secondary-color: #6c757d;
  --font-size-base: 16px;
}

.button {
  background-color: var(--primary-color);
  font-size: var(--font-size-base);
}

/* Media queries */
@media (max-width: 768px) {
  .container {
    flex-direction: column;
  }
}

3. Main Uses

CSS is essential for web development and is used for:

  • Styling web pages and user interfaces
  • Creating responsive layouts for different screen sizes
  • Implementing animations and transitions
  • Customizing the appearance of HTML elements
  • Defining print styles for documents
  • Creating themed components for web applications
  • Ensuring consistent design across multiple pages
  • Improving accessibility with appropriate visual cues

4. Pros and Cons

Advantages

  • Separates content from presentation
  • Reduces code duplication across multiple pages
  • Enables responsive design for different devices
  • Improves page loading times with external stylesheets
  • Modern CSS has powerful layout capabilities
  • Supported by all browsers
  • Wide community support and resources

Limitations

  • Browser inconsistencies can be challenging
  • Specificity and cascade rules can be confusing
  • No native variables in older versions (pre-CSS3)
  • Limited logic capabilities (no conditionals/loops)
  • Can become complex and difficult to maintain at scale
  • Debugging can be challenging
  • Legacy support requires additional code

5. CSS Evolution

CSS has evolved through several major versions:

  • CSS1 (1996) - Basic styling capabilities
  • CSS2 (1998) - Added positioning, z-index, media types
  • CSS2.1 (2011) - Revised specification with fixes
  • CSS3 (2000s onward) - Modular approach with independent modules:
  • CSS3 Selectors (2011)
  • CSS3 Colors (2011)
  • CSS3 Backgrounds and Borders (2014)
  • CSS Flexbox (2017)
  • CSS Grid (2017)
  • CSS Custom Properties for Cascading Variables (2015)

CSS is now developed as modules rather than monolithic versions, with ongoing development by the W3C.

6. Learning Resources

Here are some excellent resources for learning CSS:

7. Related Technologies

Technologies that extend or work alongside CSS:

C:\> cd ../