U3F1ZWV6ZTMyMDU3NzIxNTY3NTgxX0ZyZWUyMDIyNDc4MjgyMzU4Mw==

100 Lesser Known CSS Tricks — The Ultimate Collection

100-Lesser-Known-CSS-Tricks-The-Ultimate-Collection

Introduction:

CSS (Cascading Style Sheets) is a powerful language for styling web pages. While many developers are familiar with the basics of CSS, there are numerous lesser-known tricks and techniques that can help take your CSS skills to the next level. In this article, we will explore 100 lesser-known CSS tricks that can help you improve the design and functionality of your web pages.

Basic CSS Tricks

  1. Using box-sizing: border-box; to include padding and border in the element's total width and height.
  2. Using :root { --variable-name: value; } to define CSS variables.
  3. Using calc() function to perform calculations in CSS values.
  4. Using :focus-within pseudo-class to apply styles to a parent element when any of its children elements are focused.
  5. Using scroll-behavior: smooth; to add smooth scrolling to anchor links.
  6. Using :not() pseudo-class to apply styles to elements that do not match a specific selector.
  7. Using ::before and ::after pseudo-elements to add content before and after an element.
  8. Using clip-path property to create custom shapes.
  9. Using text-overflow: ellipsis; to truncate text with an ellipsis when it overflows its container.
  10. Using pointer-events: none; to make an element non-clickable.

Advanced CSS Tricks

  1. Using @supports rule to apply styles based on browser support for certain CSS features.
  2. Using backdrop-filter property to apply visual effects to the area behind an element.
  3. Using mix-blend-mode property to blend the colors of an element with its background.
  4. Using object-fit: cover; to scale images while maintaining their aspect ratio and covering their container.
  5. Using shape-outside property to wrap text around a non-rectangular shape.
  6. Using will-change property to inform the browser about the changes that are likely to happen to an element.
  7. Using image-set() function to provide multiple image sources with different resolutions for responsive images.
  8. Using font-variation-settings property to apply variable fonts with custom variations.
  9. Using @keyframes rule to create animations.
  10. Using @media rule to apply styles based on the device's screen size or other media features.

Layout and Flexbox Tricks

  1. Using display: grid; to create grid layouts.
  2. Using grid-template-areas property to define named grid areas.
  3. Using grid-auto-flow property to control the direction in which grid items are placed.
  4. Using justify-self and align-self properties to align individual grid items.
  5. Using display: flex; to create flexible layouts.
  6. Using flex-grow, flex-shrink, and flex-basis properties to control the flex behavior of flex items.
  7. Using order property to change the order of flex items.
  8. Using align-content property to align flex lines within a flex container.
  9. Using gap property to add space between grid or flex items.
  10. Using aspect-ratio property to control the aspect ratio of an element.

Animation and Transition Tricks

  1. Using transition property to add smooth transitions between CSS property changes.
  2. Using animation property to create complex animations with keyframes.
  3. Using @keyframes rule to define the steps of an animation.
  4. Using animation-fill-mode property to control the styles applied to an element before and after an animation.
  5. Using animation-direction property to control the direction of an animation.
  6. Using animation-timing-function property to specify the speed curve of an animation.
  7. Using animation-iteration-count property to control the number of times an animation should repeat.
  8. Using animation-play-state property to pause and resume an animation.
  9. Using transition-timing-function property to specify the speed curve of a transition.
  10. Using @supports rule to apply different animations or transitions based on browser support.

Typography and Text Tricks

  1. Using text-transform property to transform text to uppercase, lowercase, or capitalize.
  2. Using text-decoration property to add or remove decorations such as underline or line-through.
  3. Using word-break property to control how words break when reaching the end of a line.
  4. Using word-wrap property to control whether long words can break and wrap onto the next line.
  5. Using white-space property to control how white space inside an element is handled.
  6. Using letter-spacing property to adjust the spacing between characters.
  7. Using line-height property to control the height of lines of text.
  8. Using font-feature-settings property to enable or disable OpenType features in fonts.
  9. Using text-overflow property to specify how overflowed content should be signaled to the user.
  10. Using direction property to specify the text direction of an element.

Responsive Design Tricks

  1. Using media queries to apply different styles based on the device's screen size.
  2. Using min-width and max-width media queries to target specific device widths.
  3. Using min-height and max-height media queries to target specific device heights.
  4. Using orientation media query to apply styles based on the device's orientation (landscape or portrait).
  5. Using aspect-ratio media query to apply styles based on the aspect ratio of the viewport.
  6. Using resolution media query to apply styles based on the device's resolution.
  7. Using color media query to apply styles based on the device's color capabilities.
  8. Using prefers-reduced-motion media query to apply styles based on the user's preference for reduced motion.
  9. Using hover media query to apply styles when the user hovers over an element.
  10. Using pointer media query to apply styles based on the type of pointing device (mouse or touch).

Accessibility and User Interface Tricks

  1. Using aria-* attributes to improve the accessibility of your web pages.
  2. Using tabindex attribute to control the tab order of elements.
  3. Using :focus-visible pseudo-class to apply styles to elements that are focused using the keyboard.
  4. Using :read-only and :read-write pseudo-classes to style elements based on their read-only or read-write state.
  5. Using :valid and :invalid pseudo-classes to style elements based on their validation state.
  6. Using :required and :optional pseudo-classes to style elements based on their required or optional status.
  7. Using :checked pseudo-class to style checked checkboxes and radio buttons.
  8. Using :indeterminate pseudo-class to style indeterminate checkboxes.
  9. Using `:placeholder-shown
تعديل المشاركة
author-img

Anis

Experienced and dedicated Web Developer with a robust skill set honed over two years in the field. Proficient in a range of languages including HTML, CSS, PHP, jQuery, and JavaScript, ensuring a seamless integration of designs and the creation of responsive, user-oriented websites. Specializing in WordPress development, I bring advanced expertise in performance optimization, WordPress security, and content management.
Comments
No comments
Post a Comment

Post a Comment

NameEmailMessage