\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":6835540,"title":"↩️ Undo better","slug":"undo-better","status":"published","readingTime":2,"campaignCompletedAt":"2024-10-04T19:40:26.000Z","publishedAt":"2024-10-04T19:40:26.000Z","orderByDate":"2024-10-04T19:40:26.000Z","timeAgo":"2 days","thumbnailUrl":"https://pbs.twimg.com/media/GZC11ZyXAAA7tGs.jpg","thumbnailAlt":"photo","path":"posts/undo-better","url":"https://slater.ck.page/posts/undo-better","isPaid":null,"introContent":"Do you get confused when undoing (cmd + z) in Slater? We auto-format your code on save. The auto-formatting updates your code, and those updates get pushed into the undo stack. You can now improve your workflow by formatting the code when you choose—not just on save. To gain more control over when your code formats: Turn off auto-format code in the Code Editor Settings Use cmd + shift + f to format your code We added a handful of other improvements: Console logs and debuggers are now...","campaignId":16777130,"publicationId":13318151},{"id":6697092,"title":"👩🏼‍🎨 Smart Script CSS","slug":"smart-script-css","status":"published","readingTime":1,"campaignCompletedAt":"2024-09-20T22:45:41.000Z","publishedAt":"2024-09-20T22:45:41.000Z","orderByDate":"2024-09-20T22:45:41.000Z","timeAgo":"16 days","thumbnailUrl":"https://functions-js.convertkit.com/playbutton?play=%23324C85&accent=%23ffffff&thumbnailof=https%3A%2F%2Fvimeo.com%2F1011475301%2F2a39ba068c%3Fshare%3Dcopy&width=480&height=270","thumbnailAlt":"video preview","path":"posts/smart-script-css","url":"https://slater.ck.page/posts/smart-script-css","isPaid":null,"introContent":"Last week, we announced that CSS updates were on the way—and now they're here! You can now generate CSS files just as quickly and easily as JS files. In the video below, we give a quick demo of the new functionality. If you have a Smart Script loaded in your project, you can instantly add CSS. In the demo, we also show how to add CSS in the Webflow designer. Give it a try and let us know what you're building! Community Library 🖍️ Text Highlight ColorCSS code for custom text selection. 🅰...","campaignId":16611058,"publicationId":13149844},{"id":6563182,"title":"👀 Project Access Controls","slug":"project-access-controls","status":"published","readingTime":2,"campaignCompletedAt":"2024-09-06T17:49:19.000Z","publishedAt":"2024-09-06T17:49:19.000Z","orderByDate":"2024-09-06T17:49:19.000Z","timeAgo":"about 1 month","thumbnailUrl":"https://pbs.twimg.com/ext_tw_video_thumb/1828456258979913728/pu/img/qlUwb6XebiOaDUPX.jpg","thumbnailAlt":"video","path":"posts/project-access-controls","url":"https://slater.ck.page/posts/project-access-controls","isPaid":null,"introContent":"You may recall that the original Slater had access controls for projects and files. We didn't want just anyone going in there and rewriting our Javascript. However, managing access for teammates became cumbersome (I even added a \"god mode\" to give myself access to any project or file). Since we generally trusted each other and never had issues, we decided to leave it out of the latest version of Slater. That said, we understand that some teams work differently, and maintaining control can be...","campaignId":16448819,"publicationId":12986765}],"newsletter":{"formId":4967504,"productId":null,"productUrl":null,"featuredPostId":null,"subscribersOnly":false},"isPaidSubscriber":false,"isSubscriber":false,"originUrl":"https://slater.ck.page/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!
photo

Do you get confused when undoing (cmd + z) in Slater? We auto-format your code on save. The auto-formatting updates your code, and those updates get pushed into the undo stack. You can now improve your workflow by formatting the code when you choose—not just on save. To gain more control over when your code formats: Turn off auto-format code in the Code Editor Settings Use cmd + shift + f to format your code We added a handful of other improvements: Console logs and debuggers are now...

video preview

Last week, we announced that CSS updates were on the way—and now they're here! You can now generate CSS files just as quickly and easily as JS files. In the video below, we give a quick demo of the new functionality. If you have a Smart Script loaded in your project, you can instantly add CSS. In the demo, we also show how to add CSS in the Webflow designer. Give it a try and let us know what you're building! Community Library 🖍️ Text Highlight ColorCSS code for custom text selection. 🅰...

video

You may recall that the original Slater had access controls for projects and files. We didn't want just anyone going in there and rewriting our Javascript. However, managing access for teammates became cumbersome (I even added a "god mode" to give myself access to any project or file). Since we generally trusted each other and never had issues, we decided to leave it out of the latest version of Slater. That said, we understand that some teams work differently, and maintaining control can be...