<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Manon Heine on Medium]]></title>
        <description><![CDATA[Stories by Manon Heine on Medium]]></description>
        <link>https://medium.com/@manon.heine?source=rss-121e5b3b5530------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*zoDpHgpEBLq0dZT8UoJCYw.jpeg</url>
            <title>Stories by Manon Heine on Medium</title>
            <link>https://medium.com/@manon.heine?source=rss-121e5b3b5530------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 22:57:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@manon.heine/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to style the previous element in a list on (e.g.) hover]]></title>
            <link>https://medium.com/@manon.heine/how-to-style-the-previous-element-in-a-list-on-e-g-hover-bdf9033b4a79?source=rss-121e5b3b5530------2</link>
            <guid isPermaLink="false">https://medium.com/p/bdf9033b4a79</guid>
            <category><![CDATA[scss]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[tips-and-tricks]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[css3]]></category>
            <dc:creator><![CDATA[Manon Heine]]></dc:creator>
            <pubDate>Mon, 26 Aug 2024 11:05:32 GMT</pubDate>
            <atom:updated>2024-08-26T11:05:32.435Z</atom:updated>
            <content:encoded><![CDATA[<p>For a long time, this was not possible as CSS goes from top to bottom, so going back was a big no-no. Luckily, we now have the .has() selector now, and with a bit of creative thinking, we can now go back up the chain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zlQxyNMdZhx7_woT" /><figcaption>Photo by <a href="https://unsplash.com/@florianolv?utm_source=medium&amp;utm_medium=referral">Florian Olivo</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In my case, I had an input with a button next to it that had to act as being one and the same element. So when hovering over the input or the button, both had to react and change their border colour.</p><p>For simplicity’s sake, we will use a list as an example, but know that you can apply this concept to any HTML element.</p><p>Our list:</p><pre>&lt;ul&gt;<br>  &lt;li class=&quot;item-1&quot;&gt;Item 1&lt;/li&gt;<br>  &lt;li class=&quot;item-2&quot;&gt;Item 2&lt;/li&gt;<br>&lt;/ul&gt;</pre><p>And our basic on-hover SCSS, let’s change the color of the text to red:</p><pre>.item-1, .item-2 {<br>  &amp;:hover {<br>    color: red;<br>  }<br>}</pre><p>Now, when we want to also change the next element down the chain, when hovering over the previous element, we can use the + combinator:</p><pre>.item-1:hover + .item-2 {<br>  color: red;<br>}</pre><p>What that combinator does, is it will select the next element that corresponds to the class ‘item-2’ in this case. We could also make this more generic if we don’t want to select a specific element but simply the next one in line:</p><pre>.item-1, .item-2 {<br>  &amp;:hover {<br>    color: red;<br><br>    &amp; + li {<br>      color: red;<br>    }<br>  }<br>}</pre><p>This will select the next list item after the one hovered.</p><p>We now understand how to select the next item. Let’s see how we can use this in order to select the previous element. For this we’ll need to use the .has() selector:</p><pre>.item-1, .item-2 {<br>  &amp;:hover {<br>    color: red;<br><br>    &amp; + li {<br>      color: red;<br>    }<br>  }<br><br>  &amp;:has(+ li:hover) {<br>    color: red;<br>  }<br>}</pre><p>What we are doing here, is we’re saying “if an element with a class name of ‘item-1’ or ‘item-2’ has a subsequent item of type ‘list’, and that is being hovered, then change the color (of the original element) to red”.</p><p>You can also specify this for a specific item of course, or use other combinators to create a similar result. We used the next-sibling combinator here (+), but you could also use the subsequent sibling combinator (~) to color every other item in the list but the one hovered, or even the child combinator (&gt;) to only select those item followed by an element with a child.</p><p>If this was useful to you, don’t forget to ❤ or let me know in a comment :-)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bdf9033b4a79" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to style the first few words of a string differently than the rest of the text]]></title>
            <link>https://medium.com/@manon.heine/how-to-style-the-first-few-words-of-a-string-differently-than-the-rest-of-the-text-630f7be90906?source=rss-121e5b3b5530------2</link>
            <guid isPermaLink="false">https://medium.com/p/630f7be90906</guid>
            <category><![CDATA[typescript-tips]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Manon Heine]]></dc:creator>
            <pubDate>Fri, 29 Dec 2023 11:25:57 GMT</pubDate>
            <atom:updated>2023-12-29T11:25:57.770Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fFGmnMyOaPT8JAS7uWdM5w.png" /></figure><p>If you are writing a blog or styling some text, you might have seen this before: the first few words of a paragraph are styled differently. In the right context, this could elevate your design and give it a fancier look.</p><p>In order to do this, we’ll need a bit of Javascript as CSS doesn’t know what words are (and how would it deal with apostrophes and dashes e.g.?). We’ll have to do a bit of magic to calculate the length of the words we want in order to select them and change their styling.</p><p>There are two ways to do this, the first one I find very readable and is therefore included, but the second is much more efficient. Let’s dive in!</p><h4>The easy way</h4><p>First we need to calculate the length of amount of words we want to style, let’s say we want to have 3. However, we don’t need the length of the first three words, as we can already select the first word with substring() starting from 0 until the first index of a space with indexOf(‘ ‘). This means we need the length of the second and third word.</p><p>Let’s create a function that does just that:</p><pre>lengthOfWordsToStyle(str: string): number {<br>  const words: string[] = str.split(&#39; &#39;);<br>  return words[1].length + words[2].length + 2;<br>}</pre><p>What we’ve done here is creating a function that receives a string (the text to be partially styled) and will return a number. We then create an array with all the words contained in the string by splitting the string at every space. Then, we return the length of the second and third word (position 1 and 2 in the array since the first word is at position 0), plus 2 as we need to include two spaces that aren’t included in the array but are very much present in the text.</p><p>From there, we can call the function and create two variables containing our two bits of string:</p><pre>const l: number = this.lengthOfWordsToStyle(text);<br><br>const firstThreeWords: string = text.substring(0, text.indexOf(&#39; &#39;) + l);<br>const restOfText: string = text.substring(text.indexOf(&#39; &#39;) + l);</pre><p>To get the first three words, we can use substring(), it’s first value being 0 as we start from the first character on, it’s second value being for when it should end. First we check for where the first occurrence of a space with indexOf(&#39; &#39;) to which we add the length of the two words and spaces that follow. <br>For the rest of the text, our starting value is the end value of the above line, without an ending value as we simply want the rest of the text.</p><h4>The better way</h4><p>We might not always want to have hardcoded values in there, and we now create a full array of every word while only using two, that’s a bit of a waste which could impact your loading speed if you have a lot of text to process. So let’s look at a better solution.</p><p>We are going to create a function in which we can pass the string, and how many words (or nth occurrence of a space) we would like to get the length for, and it will return a number as before. Inside the function we’ll use a while() statement to check when we reach the nth occurrence of a space before the end of the text:</p><pre>positionOfNth(str: string, n: number): number {<br>  const l = str.length;<br>  let i = -1;<br>  while (n-- &amp;&amp; i++ &lt; l) {<br>    i = str.indexOf(&#39; &#39;, i);<br>    if (i &lt; 0) break;<br>  }<br>  return i;<br>}</pre><p>We can then define our two bits of string using the above function:</p><pre>const firstThreeWords: string = text.substring(0, this.positionOfNth(text, 3));<br>const restOfText: string = text.substring(this.positionOfNth(text, 3));</pre><p>Et voila! A much neater way of doing the same thing, but without extra arrays and variables defined outside of the function.</p><p>Now that we have split our string, we can include it in our HTML and style it:</p><pre>// in your template <br>&lt;div&gt;<br>  &lt;span class=&quot;special&quot;&gt;{{ firstThreeWords }}&lt;/span&gt;<br>  &lt;span&gt;{{ restOfText }}&lt;/span&gt;<br>&lt;/div&gt;</pre><pre>// in your styles<br>.special {<br>  font-variant: small-caps; // or whatever style you want to give it<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z8mca9sU12GiL5vQpive2Q.png" /></figure><p>If you’d like to style it as per my example above, add a border-left to the outside div, add a bit of padding and separate the text into two columns (I’ve written another article on how to best do that <a href="https://medium.com/@manon.heine/splitting-a-long-string-into-two-parts-without-breaking-up-words-cd5e64e7e038">here</a>).</p><p>Hope this helped you achieve what you were looking for. It would be very much appreciated if you could give this article some claps if you did, and even better if you subscribed :-)</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=630f7be90906" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Splitting a long string into two parts, without breaking up words]]></title>
            <link>https://medium.com/@manon.heine/splitting-a-long-string-into-two-parts-without-breaking-up-words-cd5e64e7e038?source=rss-121e5b3b5530------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd5e64e7e038</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[css-tricks]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <dc:creator><![CDATA[Manon Heine]]></dc:creator>
            <pubDate>Thu, 28 Dec 2023 09:17:00 GMT</pubDate>
            <atom:updated>2023-12-28T09:19:06.784Z</atom:updated>
            <content:encoded><![CDATA[<h4>While building websites, I always try to set things up as efficiently as possible, and so today I had a long string that would have to be shown in two separate columns on desktop.</h4><p>As it turns out, there are several ways of doing this: you could split it in your backend and give your frontend two separate strings, you can split it with Javascript, or you can use a nifty little CSS trick for this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*c7nIUCbqbyq_GxNsNM6Y_Q.png" /><figcaption>Two columns consisting of one string</figcaption></figure><p>We won’t cover the backend here, let’s stay away from the Dark Side for now. Let’s start with the Javascript code for this:</p><pre>const { string1, string2 } = this.splitText(str);<br><br>splitText(str: string) {<br>  const l = str.length;<br>  const string1 = str.substring(0, str.indexOf(&#39; &#39;) + l / 2);<br>  const string2 = str.substring(str.indexOf(&#39; &#39;) + l / 2).trimStart());<br>  return { string1, string2 };<br>}</pre><p>What we do here, is that we use substring() to split the original string in two pieces by checking if we have reached half of the length of the string at a space (that’s what the indexOf(&#39; &#39;) is for. trimStart() is used to remove the space at the start of the second string.</p><p>This works fine if you need these strings in your Javascript code or if you want full control over how much text you want in each column, e.g. if you would want 2/3 of the text in the first column and 1/3 in the second.</p><p>However, there is a faster way to achieve the same result if you just want a simple split, by using CSS:</p><pre>// in your template<br>&lt;div class=&quot;split&quot;&gt;{{ text }}&lt;/div&gt;<br><br>// in your styles<br>.split {<br>  column-count: 2;<br>}</pre><p>column-count is a relatively new feature but very useful if you want to distribute your content in several columns. For more info, check out the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/column-count">MDN docs</a>. You can further style your columns with column-gap, column-rule and column-span.</p><p>Hope this helped you in finding the appropriate solution for splitting your strings or distributing objects across columns. Let me know in a comment or with a clap if this was useful to you.</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd5e64e7e038" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>