<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>CSS on MXI</title><link>https://mxii.eu.org/tags/css/</link><description>Recent content in CSS on MXI</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Thu, 07 Sep 2017 21:28:11 +0300</lastBuildDate><atom:link href="https://mxii.eu.org/tags/css/index.xml" rel="self" type="application/rss+xml"/><item><title>JavaScript spoiler with a twist (collapsing up or down)</title><link>https://mxii.eu.org/2017/09/07/javascript-spoiler-with-a-twist-collapsing-up-or-down/</link><pubDate>Thu, 07 Sep 2017 21:28:11 +0300</pubDate><guid>https://mxii.eu.org/2017/09/07/javascript-spoiler-with-a-twist-collapsing-up-or-down/</guid><description>&lt;p>I thought that I will eventually need to use spoilers in this blog to hide long and optional blocks of text. And at the same time I&amp;rsquo;m often unhappy with collapsible block implementations across the Internet.&lt;/p>
&lt;p>So I decided to design my own spoiler with one useful feature: it can be collapsed not only from the top edge but also from the bottom edge &amp;mdash; you will not lose the line you were reading and you don&amp;rsquo;t have to scroll all the way to the beginning of the spoiler.&lt;/p>
&lt;p>Examples:&lt;/p>
&lt;div class="spoiler">
&lt;div class="spoiler-btn spoiler-btn-top">&lt;i class="fa-solid fa-chevron-down">&lt;/i> click to &lt;span class="show">show&lt;/span>&lt;span class="hide">hide&lt;/span>&lt;/div>
&lt;div class="spoiler-body">
&lt;p>This spoiler can be expanded up and down. And your mouse is left right over the button you just pressed whenever it is possible (on top and bottom of a page there may be not enough stuff to keep it so, obviously).&lt;/p>
&lt;p>&lt;img src="https://picsum.photos/410/410?random=1" alt="" />&lt;/p>
&lt;/div>
&lt;div class="spoiler-btn spoiler-btn-bottom">click to &lt;span class="show">show&lt;/span>&lt;span class="hide">hide&lt;/span> &lt;i class="fa-solid fa-chevron-up">&lt;/i>&lt;/div>
&lt;/div>
&lt;div class="spoiler simple">
&lt;div class="spoiler-btn spoiler-btn-top">&lt;i class="fa-solid fa-chevron-down">&lt;/i> click to &lt;span class="show">show&lt;/span>&lt;span class="hide">hide&lt;/span>&lt;/div>
&lt;div class="spoiler-body">
&lt;p>This spoiler can be expanded in one direction only. Collapsing behavior is still the same. The difference is just a few lines in CSS.&lt;/p>
&lt;p>&lt;img src="https://picsum.photos/410/410?random=2" alt="" />&lt;/p>
&lt;/div>
&lt;div class="spoiler-btn spoiler-btn-bottom">click to &lt;span class="show">show&lt;/span>&lt;span class="hide">hide&lt;/span> &lt;i class="fa-solid fa-chevron-up">&lt;/i>&lt;/div>
&lt;/div>
&lt;p>Keep reading to see how it is done.&lt;/p></description></item><item><title>HTML aspect ratio box using Custom Element</title><link>https://mxii.eu.org/2016/12/04/html-aspect-ratio-box-using-custom-element/</link><pubDate>Sun, 04 Dec 2016 23:45:23 +0300</pubDate><guid>https://mxii.eu.org/2016/12/04/html-aspect-ratio-box-using-custom-element/</guid><description>&lt;p>There is a standard trick to make HTML block with given proportions:&lt;/p>
&lt;pre>&lt;code>&amp;lt;div id=&amp;quot;containingBlock&amp;quot;&amp;gt;
&amp;lt;div id=&amp;quot;wrapper&amp;quot; style=&amp;quot;position:relative; width:100%; height:0px; padding-bottom:56.25%;&amp;quot;&amp;gt;
&amp;lt;div id=&amp;quot;content&amp;quot; style=&amp;quot;position:absolute; left:0; top:0; width:100%; height:100%&amp;quot;&amp;gt;
...
&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code>&lt;/pre>
&lt;p>Since padding is computed according to containing element width, it&amp;rsquo;s possible to use it along with width to get required proportions (16:9 in this example, 56.25% = 100% * 9 / 16). And content block is positioned absolutely to use the space taken by padding.&lt;/p>
&lt;p>After learning about &lt;a href="https://developers.google.com/web/fundamentals/getting-started/primers/customelements">Custom Elements&lt;/a> I decided to see if I can abstract the trick and turn it into something clean and reusable. So it could be used just like this:&lt;/p>
&lt;pre>&lt;code>&amp;lt;ratio-box ratio=&amp;quot;16:9&amp;quot;&amp;gt;
...
&amp;lt;/ratio-box&amp;gt;
&lt;/code>&lt;/pre>
&lt;p>Custom Elements is &lt;a href="http://caniuse.com/#search=custom%20element">quite recent&lt;/a> feature in HTML, with version 0 available only in Chrome and version 1 just coming into play. It also requires JavaScript to work. So it is not practical to use yet, but still an interesting experiment.&lt;/p>
&lt;p>See the code and demo below. In addition, there is also a slightly improved HTML+CSS version.&lt;/p></description></item></channel></rss>