CSS Secrets: Typing Effects, Character Targeting & Safari Boost!

CSS Secrets: Typing Effects, Character Targeting & Safari Boost!

Hey there, fellow CSS enthusiasts! I'm excited to dive into some lesser-known CSS tricks that can really elevate your web projects. In my 5+ years of crafting websites, I've stumbled upon some fascinating techniques. Today, I'm sharing some CSS secrets focusing on typing effects, character targeting, and a little Safari boost!

You'll discover how to create engaging typing animations, target specific characters with CSS rules, and leverage the latest Safari Technology Preview releases for better performance and bug fixes. Get ready to level up your CSS game!


Creating a Typing Effect with CSS

Trying to get a typing like effect for my personal website in HTML and CSS has been a common request, and I've found some elegant solutions. The key is using @keyframes to animate the width of a container and the steps() timing function to create that distinct typing look.

<h1 class="typing-effect">Hello, I'm a Developer!</h1>

Here’s the CSS:

.typing-effect {
  width: 0;
  overflow: hidden;
  white-space: nowrap;
  border-right: .15em solid orange; /* The typwriter cursor */
  animation: typing 4s steps(40, end) forwards,
             blink-caret .75s step-end infinite;
}

@keyframes typing {
  from { width: 0 }
  to { width: 100% }
}

@keyframes blink-caret {
  from, to { border-color: transparent }
  50% { border-color: orange; }
}

In this code, width: 0; initially hides the text. The typing animation increases the width to 100% over 4 seconds, using steps(40, end) to create the stepped typing effect. The blink-caret animation adds a blinking cursor. I once used this on a portfolio site, and the client loved the interactive feel!


Targeting Specific Characters with CSS

Targetting specific characters with CSS rules is something I didn't know was possible until a few years ago. It's incredibly useful for styling specific parts of text without adding extra <span> elements. You might be surprised to know that you can achieve this with a bit of cleverness using pseudo-elements and the content property.

Here’s a neat trick to highlight the first letter of every paragraph:

p::first-letter {
  font-size: 200%;
  color: red;
  float: left;
}

This will enlarge and color the first letter of each paragraph. I've used this to create a more visually appealing reading experience on blog posts. But what if you want to target, say, the second letter? That’s where it gets trickier, and often requires JavaScript or server-side manipulation for complex scenarios. But for simple cases, you can sometimes achieve the desired effect by carefully structuring your HTML and using adjacent sibling selectors.

Remember that ::first-letter only works on block-level elements.


Safari Boost: Leveraging Technology Previews

Apple Releases Safari Technology Preview 227 With Bug Fixes and Performance Improvements and Apple Releases Safari Technology Preview 228 With Bug Fixes and Performance Improvements, so keeping up with these releases is crucial. These previews often include experimental features and performance enhancements that can significantly improve the user experience. I've found that testing my websites in these previews helps me identify potential issues early on.

For instance, one of the recent previews included better support for contain: paint; which can drastically improve rendering performance on complex layouts. I remember struggling with a website that had performance issues due to excessive re-paints. After enabling contain: paint; on certain elements, the performance improved noticeably.

To take advantage of these previews, download them from the Apple Developer website and regularly test your websites. You might discover new features or bug fixes that can enhance your projects.


Controlling Opacity in CSS

Sometimes, you need to Increase opacity of HTML element to create visual effects or to highlight certain parts of your webpage. CSS provides a straightforward way to control the opacity of any element using the opacity property.

.transparent-element {
  opacity: 0.5; /* 50% opacity */
}

This will make the element semi-transparent. The opacity property accepts values between 0 (fully transparent) and 1 (fully opaque). I often use this to create subtle hover effects or to de-emphasize certain elements on the page.

Be careful when applying opacity to an element with child elements, as it will affect the opacity of all its children as well. If you want to control the opacity of the background only, use rgba() or hsla() color values instead.


Can I use CSS to target the nth character of a string?

Directly targeting the nth character with pure CSS is limited. While ::first-letter is available, more complex targeting often requires JavaScript or server-side processing to wrap the desired character in a <span> for styling. I've found that using JavaScript libraries like "splitting.js" can simplify this process.

How often should I check for Safari Technology Preview updates?

Apple typically releases new Safari Technology Previews every few weeks. I recommend checking for updates at least once a month to stay informed about the latest bug fixes and performance improvements. Subscribing to the Apple Developer newsletter is a great way to stay in the loop.

Are typing effects accessible?

Typing effects can pose accessibility challenges if not implemented carefully. Ensure the content remains accessible to screen readers by providing alternative text or using ARIA attributes. In my experience, providing a static version of the text alongside the typing effect ensures a better user experience for everyone.

Source:
www.siwane.xyz
A special thanks to GEMINI and Jamal El Hizazi.

About the author

Jamal El Hizazi
Hello, I’m a digital content creator (Siwaneˣʸᶻ) with a passion for UI/UX design. I also blog about technology and science—learn more here.
Buy me a coffee ☕

Post a Comment