\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":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":"12 days","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},{"id":6498899,"title":"🤖 ask.edgarallan.com","slug":"ask-edgarallan-com","status":"published","readingTime":2,"campaignCompletedAt":"2024-08-30T19:47:49.000Z","publishedAt":"2024-08-30T19:47:49.000Z","orderByDate":"2024-08-30T19:47:49.000Z","timeAgo":"19 days","thumbnailUrl":"https://pbs.twimg.com/ext_tw_video_thumb/1829158263570452480/pu/img/OrOTJDnM9rcnX96X.jpg","thumbnailAlt":"video","path":"posts/ask-edgarallan-com","url":"https://slater.ck.page/posts/ask-edgarallan-com","isPaid":null,"introContent":"We're going to take a brief break from the regular newsletter format to celebrate the release of ask.edgarallan.com. Today, let's hear from Mason Poe, the Founder of Edgar Allan and Slater. I'm thrilled to announce the launch of ask.edgarallan.com and the start of a new conversation. We can all feel it: the web is changing in ways that seem both dramatic and, in a weird way, imperceptible. At times, it’s hard to know where to start exploring what could be next. Sometimes, when you think...","campaignId":16332540,"publicationId":12869796},{"id":6435341,"title":"👀 File importing","slug":"file-importing","status":"published","readingTime":1,"campaignCompletedAt":"2024-08-23T20:54:08.000Z","publishedAt":"2024-08-23T20:54:08.000Z","orderByDate":"2024-08-23T20:54:08.000Z","timeAgo":"26 days","thumbnailUrl":"https://embed.filekitcdn.com/e/f2wTcXHNz6CCWc9a5vGTv3/4Jgg7HWJrCbQqWw4TfER7M/email","thumbnailAlt":"","path":"posts/file-importing","url":"https://slater.ck.page/posts/file-importing","isPaid":null,"introContent":"Our new Edgar Allan website, which we're launching next week 🤫, uses over 3,000 lines of code. It’s a bit unwieldy! To better support the new EA website and similar JavaScript-heavy projects, we’ve added slater_import. This feature allows you to write a function once and then reuse it across all the files in your project. You can see how to use it here. ⬇️ Not ready to watch the video? No problem. To import a file, simply start typing the name of the file you want to import and click on the...","campaignId":16293531,"publicationId":12830351}],"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!
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...

video

We're going to take a brief break from the regular newsletter format to celebrate the release of ask.edgarallan.com. Today, let's hear from Mason Poe, the Founder of Edgar Allan and Slater. I'm thrilled to announce the launch of ask.edgarallan.com and the start of a new conversation. We can all feel it: the web is changing in ways that seem both dramatic and, in a weird way, imperceptible. At times, it’s hard to know where to start exploring what could be next. Sometimes, when you think...

Our new Edgar Allan website, which we're launching next week 🤫, uses over 3,000 lines of code. It’s a bit unwieldy! To better support the new EA website and similar JavaScript-heavy projects, we’ve added slater_import. This feature allows you to write a function once and then reuse it across all the files in your project. You can see how to use it here. ⬇️ Not ready to watch the video? No problem. To import a file, simply start typing the name of the file you want to import and click on the...