My 5th Day of Learning Advanced CSS: Diving into Selectors, Box Models, Backgrounds, Borders, Text Directions, and Overflow Handling

Ashfak PrAshfak Pr
3 min read

Today marks the fifth day of my journey into the world of frontend development, and it's been an exciting adventure so far! Each day brings new challenges and insights, and today was no different. I delved into some fundamental yet intricate aspects of CSS: selectors and combinators, box models, backgrounds, borders, text directions, and overflow handling. Here's a detailed look at what I learned and experienced.

Selectors and Combinators

Selectors are the backbone of CSS. They allow you to target HTML elements and apply styles to them. Today, I explored different types of selectors:

  • Type Selectors: These target elements by their tag name. For example, p selects all <p> elements.

  • Class Selectors: Using a dot notation, class selectors target elements with a specific class. For instance, .my-class targets all elements with the class "my-class".

  • ID Selectors: These are similar to class selectors but use a hash notation and are unique to a single element. For example, #my-id.

  • Attribute Selectors: These allow you to target elements based on their attributes, such as input[type="text"].

I also learned about combinators, which combine multiple selectors to target elements based on their relationship with other elements:

  • Descendant Combinator: div p targets all <p> elements inside <div> elements.

  • Child Combinator: ul > li targets all <li> elements that are direct children of <ul> elements.

  • Adjacent Sibling Combinator: h1 + p targets the first <p> element immediately following an <h1>.

  • General Sibling Combinator: h1 ~ p targets all <p> elements that are siblings of an <h1>.

Box Models

Understanding the CSS box model is crucial for controlling layout and design. The box model consists of:

  • Content: The actual content of the box, such as text or images.

  • Padding: Space between the content and the border.

  • Border: The border surrounding the padding (if any).

  • Margin: Space outside the border, separating the element from others.

I experimented with adjusting the padding, border, and margin properties to see how they affect the layout and spacing of elements. Learning about the box-sizing property was particularly useful, as setting it to border-box makes it easier to manage dimensions by including padding and border in the element's total width and height.

Backgrounds and Borders

Adding backgrounds and borders can greatly enhance the visual appeal of a webpage. I learned to:

  • Set Background Colors and Images: Using the background-color and background-image properties.

  • Control Background Position and Size: Properties like background-position, background-size, and background-repeat help fine-tune the background appearance.

  • Apply Borders: The border property allows you to set the width, style, and color of borders. I experimented with different styles such as solid, dashed, and dotted.

Text Directions

Working with different text directions is essential, especially for internationalization. I learned about the direction property, which can be set to ltr (left-to-right) or rtl (right-to-left), and the text-align property to align text horizontally. This knowledge is invaluable for creating websites that support multiple languages and cultures.

Overflow Handling

Handling overflow is vital for maintaining a clean layout, especially when content exceeds its container's dimensions. The overflow property can be set to:

  • visible: The overflow is not clipped and will be visible outside the element's box.

  • hidden: The overflow is clipped, and the rest of the content is invisible.

  • scroll: Adds a scrollbar to the element to allow scrolling through the overflow content.

  • auto: Adds a scrollbar only when necessary.

Conclusion

Today was packed with learning and experimentation. Understanding these core CSS concepts has given me a deeper appreciation of how powerful and flexible CSS can be. Each new topic I master makes me more confident in my ability to create beautiful, functional websites. I'm excited to continue this journey and see where it takes me next!

0
Subscribe to my newsletter

Read articles from Ashfak Pr directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ashfak Pr
Ashfak Pr