\n

```
Here, clicking the button changes the background color of the div. This method works for directly applying or modifying individual CSS properties.

\n

\n

2. Manipulating CSS Classes
Rather than directly manipulating individual CSS properties, a more maintainable approach is to add, remove, or toggle CSS classes using JavaScript. This way, you keep all your styles in a CSS file and simply tell JavaScript to apply or remove those classes.

\n

```

\n

\n

\n

```
Here, we use classList.toggle to switch between light and dark mode. This method is more scalable and easier to maintain because your styles are kept in CSS files.

\n

\n

3. Responsive Design
CSS variables (–custom-property) allow you to define dynamic values that can be updated through JavaScript, making it an effective way to handle themes and responsive styles.

\n

```





\n

```

\n

In this example, we use JavaScript to update a CSS variable (–box-color) that controls the background color of the box. This approach is excellent for creating theme-able and responsive designs.

\n

\n

By combining CSS and JavaScript, you can build interactive user interfaces that react to user input and adapt to changing conditions. Remember to choose the right approach based on your use case. For simple changes, inline styles might suffice. For more scalable, maintainable code, manipulating CSS classes is the way to go. And if you need complete control, modifying CSS variables can offer flexibility.

\n

Happy coding!

\n

\n

🤙 the Slater Team

\n

\n

\n

If Slater helps you create better websites, please support the team behind it.

\n
Become a Pro Slater User
\n\n\n\n","recentPosts":[{"id":7606258,"title":"🎅 Merry Christmas and a happy New Year","slug":"merry-christmas-and-a-happy-new-year","status":"published","readingTime":1,"campaignCompletedAt":"2024-12-23T17:30:16.000Z","publishedAt":"2024-12-23T17:30:16.000Z","orderByDate":"2024-12-23T17:30:16.000Z","timeAgo":"3 days","thumbnailUrl":"https://embed.filekitcdn.com/e/f2wTcXHNz6CCWc9a5vGTv3/8ZxHHAV3Z2NzLd9MJGAnuw/email","thumbnailAlt":"","path":"posts/merry-christmas-and-a-happy-new-year","url":"https://slater.kit.com/posts/merry-christmas-and-a-happy-new-year","isPaid":null,"introContent":"The team behind Slater would like to wish you a Merry Christmas and a happy New Year! 🎄🎅🎁 Get the Santa ASCII art: https://slater.app/projects/11431/pages/27608 Happy coding! 🤙 the Slater Team If Slater helps you create better websites, please support the team behind it. Become a Pro Slater User","campaignId":17709207,"publicationId":14255672,"metaDescription":""},{"id":7537398,"title":"🗂️ Files","slug":"files","status":"published","readingTime":2,"campaignCompletedAt":"2024-12-13T18:14:13.000Z","publishedAt":"2024-12-13T18:14:13.000Z","orderByDate":"2024-12-13T18:14:13.000Z","timeAgo":"13 days","thumbnailUrl":"https://embed.filekitcdn.com/e/f2wTcXHNz6CCWc9a5vGTv3/4FZpgpss7uN1AgRNMpqRiS/email","thumbnailAlt":"","path":"posts/files","url":"https://slater.kit.com/posts/files","isPaid":null,"introContent":"Earlier this year, we built figdam.com. It is currently used by several of our clients to host files and watermark PDFs. We’d like to bring this file hosting functionality to Slater users. With that in mind, where do you currently store files that Webflow doesn’t support? Would this feature be useful to you? What file hosting features do you need? Let us know. JS 101: File types File storage? Javascript? Let's consider all of the different file types that you could host and then retrieve and...","campaignId":17627169,"publicationId":14173259,"metaDescription":""},{"id":7528614,"title":"👋 EA Office Hours this Friday, 3 PM EST","slug":"ea-office-hours-this-friday-3-pm-est","status":"published","readingTime":1,"campaignCompletedAt":"2024-12-12T21:55:16.000Z","publishedAt":"2024-12-12T21:55:16.000Z","orderByDate":"2024-12-12T21:55:16.000Z","timeAgo":"14 days","thumbnailUrl":"https://embed.filekitcdn.com/e/f2wTcXHNz6CCWc9a5vGTv3/k23TtrHKgV6qYT84ZW7Bqr/email","thumbnailAlt":"","path":"posts/ea-office-hours-this-friday-3-pm-est","url":"https://slater.kit.com/posts/ea-office-hours-this-friday-3-pm-est","isPaid":null,"introContent":"Hi, Just a reminder that Kendra and Mason will be hosting an EA Office Hours Zoom this Friday, the 13th (spooky…) to chat about topics relating to Chapter 1: Sales for Creative Types. Sign up if you can make it, and bring your questions. Let’s get past any lingering sales ick together. Register to join us this Friday, 12/13 here. Also, if you can’t make it this week, we’re thinking about doing it again next Friday, 12/20 as well, if anyone is game? To ring in the holiday break, we’ll chat...","campaignId":17617126,"publicationId":14163203,"metaDescription":""}],"newsletter":{"formId":4967504,"productId":null,"productUrl":null,"featuredPostId":null,"subscribersOnly":false},"isPaidSubscriber":false,"isSubscriber":false,"originUrl":"https://slater.kit.com/posts/slater-css","creatorProfileName":"Welcome To Slater!","creatorProfileId":1135261}👩🏼‍🎨 Slater & CSS

👩🏼‍🎨 Slater & CSS


Do you use Slater for CSS? CSS support in Slater has always been somewhat of an afterthought—JavaScript is our love language! But sometimes, you need a simple way to add CSS to your project. Maybe you want to write a complex grid or use a CSS property that Webflow doesn't support. That's why we've decided to make CSS a first-class citizen.

We considered launching the new CSS functionality today, but we want to test it a bit more. Expect it early next week.

To prepare for the launch, let's highlight 3 CSS solutions found in the Community Library:

Community Library

🫵 Pointer events
​CSS classes to control pointer events: .pointer-events-off disables interactions, .pointer-events-on enables interactions.

Ellipsis text
CSS class to truncate text with ellipsis when it overflows the container width.

📜 Hide scrollbars
CSS class to hide scrollbars

Have you added a useful script to your library? Share it with us!

--

Javascript 101: CSS & JS

Let's stay on the subject of CSS. Combining CSS and JavaScript is a important way to create dynamic websites. In many cases, you’ll want to modify styles using JavaScript, either in response to user input or to create smooth animations. Let's look at some examples of how you can do this.

1. Inline Styles
The easiest way to manipulate CSS with JavaScript is by modifying the inline styles of an element directly using the style property.

```
<button id="colorBtn">Change Background</button>
<div id="box" style="width: 100px; height: 100px; background-color: lightblue;"></div>

<script>
const button = document.getElementById('colorBtn');
const box = document.getElementById('box');

button.addEventListener('click', () => {
box.style.backgroundColor = 'tomato';
});
</script>

```
Here, clicking the button changes the background color of the div. This method works for directly applying or modifying individual CSS properties.

2. Manipulating CSS Classes
Rather than directly manipulating individual CSS properties, a more maintainable approach is to add, remove, or toggle CSS classes using JavaScript. This way, you keep all your styles in a CSS file and simply tell JavaScript to apply or remove those classes.

```
<button id="toggleBtn">Toggle Dark Mode</button>
<div id="box" class="light-mode"></div>

<style>
.light-mode {
background-color: lightgray;
width: 100px;
height: 100px;
}
.dark-mode {
background-color: black;
color: white;
}
</style>

<script>
const toggleButton = document.getElementById('toggleBtn');
const box = document.getElementById('box');

toggleButton.addEventListener('click', () => {
box.classList.toggle('dark-mode');
});
</script>

```
Here, we use classList.toggle to switch between light and dark mode. This method is more scalable and easier to maintain because your styles are kept in CSS files.

3. Responsive Design
CSS variables (–custom-property) allow you to define dynamic values that can be updated through JavaScript, making it an effective way to handle themes and responsive styles.

```
<style>
:root {
--box-color: pink;
}
.variable-box {
width: 100px;
height: 100px;
background-color: var(--box-color);
}
</style>

<div class="variable-box"></div>
<button id="changeColor">Change Color</button>

<script>
const button = document.getElementById('changeColor');

button.addEventListener('click', () => {
document.documentElement.style.setProperty('--box-color', 'skyblue');
});
</script>

```

In this example, we use JavaScript to update a CSS variable (–box-color) that controls the background color of the box. This approach is excellent for creating theme-able and responsive designs.

By combining CSS and JavaScript, you can build interactive user interfaces that react to user input and adapt to changing conditions. Remember to choose the right approach based on your use case. For simple changes, inline styles might suffice. For more scalable, maintainable code, manipulating CSS classes is the way to go. And if you need complete control, modifying CSS variables can offer flexibility.

Happy coding!

🤙 the Slater Team

If Slater helps you create better websites, please support the team behind it.

Welcome To Slater!

Slater resources, updates and community activity

Read more from Welcome To Slater!

The team behind Slater would like to wish you a Merry Christmas and a happy New Year! 🎄🎅🎁 Get the Santa ASCII art: https://slater.app/projects/11431/pages/27608 Happy coding! 🤙 the Slater Team If Slater helps you create better websites, please support the team behind it. Become a Pro Slater User

Earlier this year, we built figdam.com. It is currently used by several of our clients to host files and watermark PDFs. We’d like to bring this file hosting functionality to Slater users. With that in mind, where do you currently store files that Webflow doesn’t support? Would this feature be useful to you? What file hosting features do you need? Let us know. JS 101: File types File storage? Javascript? Let's consider all of the different file types that you could host and then retrieve and...

Hi, Just a reminder that Kendra and Mason will be hosting an EA Office Hours Zoom this Friday, the 13th (spooky…) to chat about topics relating to Chapter 1: Sales for Creative Types. Sign up if you can make it, and bring your questions. Let’s get past any lingering sales ick together. Register to join us this Friday, 12/13 here. Also, if you can’t make it this week, we’re thinking about doing it again next Friday, 12/20 as well, if anyone is game? To ring in the holiday break, we’ll chat...