DEV Community

Cover image for Here are 20 CSS tricks...
AppCode ⚡
AppCode ⚡

Posted on • Originally published at typeoverflow.com

Here are 20 CSS tricks...

Here are 20 CSS tricks that you can use to enhance your web development projects:

  1. Centering Elements Horizontally: Use margin: 0 auto; on a block-level element to center it horizontally.

  2. Centering Elements Vertically: Utilize display: flex; and align-items: center; on the parent container to center its child vertically.

  3. Creating Responsive Layouts: Apply media queries with @media to adjust the layout based on different screen sizes.

  4. Creating Equal-Height Columns: Use the CSS display: flex; and flex-grow: 1; properties on column containers to make them equal in height.

  5. Creating a Sticky Footer: Set the min-height of the content container to 100vh and give the footer a fixed position at the bottom using position: fixed;.

  6. Creating Animated Hover Effects: Utilize the transition property to add smooth transitions on hover.

  7. Creating a Gradient Background: Use the background-image property with the linear-gradient function to create gradient backgrounds.

  8. Styling Links: Apply text-decoration: none; to remove the default underline on links and use :hover and :visited pseudo-classes to style link states.

  9. Creating a Drop Cap Effect: Use the ::first-letter pseudo-element to style the first letter of a block of text.

  10. Creating Responsive Images: Use the max-width: 100%; property on images to ensure they scale down properly on smaller screens.

  11. Creating a Modal Box: Use the display: none; property along with the :target pseudo-class to create a modal box that opens when a specific anchor link is clicked.

  12. Creating a Responsive Navigation Menu: Utilize the CSS flexbox or grid layout to create a responsive navigation menu.

  13. Creating a Slideshow: Use the animation property and @keyframes to create a slideshow with CSS animations.

  14. Creating a Fixed Sidebar: Set position: fixed; on the sidebar container to make it stay fixed while scrolling.

  15. Creating a Custom Checkbox/Radio Button: Use the label element along with the input[type="checkbox"] or input[type="radio"] and style them with CSS.

  16. Creating Tooltips: Utilize the ::before or ::after pseudo-elements to create tooltips that appear when hovering over an element.

  17. Creating a Scroll Progress Indicator: Use JavaScript to calculate the scroll position and update the progress indicator's width or height accordingly.

  18. Creating a Parallax Effect: Apply background-attachment: fixed; to a background image to create a parallax scrolling effect.

  19. Creating a Flip Card Effect: Use CSS transform and transition properties to create a card that flips on hover.

  20. Creating a Responsive Video Embed: Wrap the video element in a container and use the padding-top property to maintain its aspect ratio.


Want to see more?

Here are 20 more tricks!

Top comments (1)

Collapse
 
appcode profile image
AppCode ⚡ • Edited

Image description

Try out some of these examples in the PenEditor... appcode.app/editor