<?xml version="1.0"?>
<rss version="2.0"
     xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:dcterms="http://purl.org/dc/terms/"
     xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Tyler Cipriani: pages tagged design</title>
<link>https://tylercipriani.com/tags/design/</link>
<atom:link href="https://tylercipriani.com/tags/design/index.rss" rel="self" type="application/rss+xml"/>

<description>Tyler Cipriani</description>
<generator>ikiwiki</generator>
<pubDate>Tue, 14 Feb 2017 15:11:05 +0000</pubDate>
<item>
	<title>Cross-Browser JavaScript Scrollbar Detection</title>

	<guid isPermaLink="false">https://tylercipriani.com/blog/2014/07/12/crossbrowser-javascript-scrollbar-detection/</guid>

	<link>https://tylercipriani.com/blog/2014/07/12/crossbrowser-javascript-scrollbar-detection/</link>

	<dc:creator>Tyler Cipriani</dc:creator>



	<category>computing</category>

	<category>design</category>

	<category>javascript</category>


	<pubDate>Sat, 12 Jul 2014 00:00:00 +0000</pubDate>
	<dcterms:modified>2017-02-14T15:11:05Z</dcterms:modified>


	<description>&lt;p&gt;I recently contributed a fix to the &lt;a href=&quot;https://github.com/twbs/bootstrap/issues/9855&quot;&gt;bootstrap framework&lt;/a&gt; that detects on-screen scrollbars to determine whether or not the body should be padded when a modal window is opened to prevent shifting of background contents. Detecting on-screen scrollbars turned out to be a bit more involved than I initially anticipated.&lt;/p&gt;
&lt;p&gt;The tl;dr, semi-näive version:&lt;/p&gt;
&lt;div class=&quot;sourceCode&quot; id=&quot;cb1&quot;&gt;&lt;pre class=&quot;sourceCode numberSource javascript numberLines&quot;&gt;&lt;code class=&quot;sourceCode javascript&quot;&gt;&lt;a class=&quot;sourceLine&quot; id=&quot;cb1-1&quot; title=&quot;1&quot;&gt;&lt;span class=&quot;kw&quot;&gt;var&lt;/span&gt; hasScrollbar &lt;span class=&quot;op&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;va&quot;&gt;window&lt;/span&gt;.&lt;span class=&quot;at&quot;&gt;innerWidth&lt;/span&gt; &lt;span class=&quot;op&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;va&quot;&gt;document&lt;/span&gt;.&lt;span class=&quot;va&quot;&gt;documentElement&lt;/span&gt;.&lt;span class=&quot;at&quot;&gt;clientWidth&lt;/span&gt;&lt;/a&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This works for most browsers. Basically it checks to see if the width of the &lt;code&gt;window&lt;/code&gt; element (read: including scrollbars) is greater than the width of the root element of the page (read: without scrollbars). If the width of the page with scrollbars is greater than the width of a page without scrollbars it would stand to reason that the extra width &lt;em&gt;is&lt;/em&gt; a scrollbar.&lt;/p&gt;
&lt;p&gt;This solution behaves correctly when IE10+ has &lt;code&gt;@-ms-viewport { width: device-width; }&lt;/code&gt; set (as it is in the bootstrap framework), which seems to result in scrollbars being auto-hidden. This solution also works for Chrome on the Mac where the scrollbars are automagically hidden.&lt;/p&gt;
&lt;p&gt;This certainly seems to function as expected for IE9+; however, &lt;a href=&quot;http://www.paulirish.com/2011/browser-market-pollution-iex-is-the-new-ie6/&quot;&gt;IE8 is our newest anchor browser&lt;/a&gt; so IE8 should be addressed in any ostensibly “cross-browser” approaches.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;window.innerWidth&lt;/code&gt; doesn’t exist on IE8. Any workarounds you see utilizing &lt;code&gt;document.documentElement&lt;/code&gt; will not include scrollbars in the reported width, so &lt;code&gt;document.docutmentElement&lt;/code&gt; will not be an adequate substitute in &amp;lt; IE9.&lt;/p&gt;
&lt;p&gt;One thing to check is the &lt;code&gt;scrollHeight&lt;/code&gt;. If the &lt;code&gt;scrollHeight&lt;/code&gt; of the root element is greater than the &lt;code&gt;clientHeight&lt;/code&gt; of the root element, then that root element is going to need to scroll to show the overflowing content:&lt;/p&gt;
&lt;div class=&quot;sourceCode&quot; id=&quot;cb2&quot;&gt;&lt;pre class=&quot;sourceCode numberSource javascript numberLines&quot;&gt;&lt;code class=&quot;sourceCode javascript&quot;&gt;&lt;a class=&quot;sourceLine&quot; id=&quot;cb2-1&quot; title=&quot;1&quot;&gt;&lt;span class=&quot;kw&quot;&gt;var&lt;/span&gt; hasScrollbar&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb2-2&quot; title=&quot;2&quot;&gt;&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb2-3&quot; title=&quot;3&quot;&gt;&lt;span class=&quot;cf&quot;&gt;if&lt;/span&gt; (&lt;span class=&quot;kw&quot;&gt;typeof&lt;/span&gt; &lt;span class=&quot;va&quot;&gt;window&lt;/span&gt;.&lt;span class=&quot;at&quot;&gt;innerWidth&lt;/span&gt; &lt;span class=&quot;op&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;#39;number&amp;#39;&lt;/span&gt;)&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb2-4&quot; title=&quot;4&quot;&gt;  hasScrollbar &lt;span class=&quot;op&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;va&quot;&gt;window&lt;/span&gt;.&lt;span class=&quot;at&quot;&gt;innerWidth&lt;/span&gt; &lt;span class=&quot;op&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;va&quot;&gt;document&lt;/span&gt;.&lt;span class=&quot;va&quot;&gt;documentElement&lt;/span&gt;.&lt;span class=&quot;at&quot;&gt;clientWidth&lt;/span&gt;&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb2-5&quot; title=&quot;5&quot;&gt;&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb2-6&quot; title=&quot;6&quot;&gt;hasScrollbar &lt;span class=&quot;op&quot;&gt;=&lt;/span&gt; hasScrollbar &lt;span class=&quot;op&quot;&gt;||&lt;/span&gt;&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb2-7&quot; title=&quot;7&quot;&gt;  &lt;span class=&quot;va&quot;&gt;document&lt;/span&gt;.&lt;span class=&quot;va&quot;&gt;documentElement&lt;/span&gt;.&lt;span class=&quot;at&quot;&gt;scrollHeight&lt;/span&gt; &lt;span class=&quot;op&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;va&quot;&gt;document&lt;/span&gt;.&lt;span class=&quot;va&quot;&gt;documentElement&lt;/span&gt;.&lt;span class=&quot;at&quot;&gt;clientHeight&lt;/span&gt;&lt;/a&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Again, this is an oversimplification. The &lt;code&gt;overflow&lt;/code&gt; property of the root element can modify the appearance of scrollbars (to create on-screen &lt;em&gt;faux&lt;/em&gt; llbars). Of course, once again, IE and modern browsers differ about how they’ve implemented the javascript api for accessing element styles. We can account for this difference and grab the overflow property like this:&lt;/p&gt;
&lt;div class=&quot;sourceCode&quot; id=&quot;cb3&quot;&gt;&lt;pre class=&quot;sourceCode numberSource javascript numberLines&quot;&gt;&lt;code class=&quot;sourceCode javascript&quot;&gt;&lt;a class=&quot;sourceLine&quot; id=&quot;cb3-1&quot; title=&quot;1&quot;&gt;&lt;span class=&quot;kw&quot;&gt;var&lt;/span&gt; overflowStyle&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb3-2&quot; title=&quot;2&quot;&gt;&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb3-3&quot; title=&quot;3&quot;&gt;&lt;span class=&quot;cf&quot;&gt;if&lt;/span&gt; (&lt;span class=&quot;kw&quot;&gt;typeof&lt;/span&gt; &lt;span class=&quot;va&quot;&gt;document&lt;/span&gt;.&lt;span class=&quot;va&quot;&gt;documentElement&lt;/span&gt;.&lt;span class=&quot;at&quot;&gt;currentStyle&lt;/span&gt; &lt;span class=&quot;op&quot;&gt;!==&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;#39;undefined&amp;#39;&lt;/span&gt;)&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb3-4&quot; title=&quot;4&quot;&gt;  overflowStyle &lt;span class=&quot;op&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;va&quot;&gt;document&lt;/span&gt;.&lt;span class=&quot;va&quot;&gt;documentElement&lt;/span&gt;.&lt;span class=&quot;va&quot;&gt;currentStyle&lt;/span&gt;.&lt;span class=&quot;at&quot;&gt;overflow&lt;/span&gt;&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb3-5&quot; title=&quot;5&quot;&gt;&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb3-6&quot; title=&quot;6&quot;&gt;overflowStyle &lt;span class=&quot;op&quot;&gt;=&lt;/span&gt; overflowStyle &lt;span class=&quot;op&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;va&quot;&gt;window&lt;/span&gt;.&lt;span class=&quot;at&quot;&gt;getComputedStyle&lt;/span&gt;(&lt;span class=&quot;va&quot;&gt;document&lt;/span&gt;.&lt;span class=&quot;at&quot;&gt;documentElement&lt;/span&gt;&lt;span class=&quot;op&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;#39;&amp;#39;&lt;/span&gt;).&lt;span class=&quot;at&quot;&gt;overflow&lt;/span&gt;&lt;/a&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The two values of the &lt;code&gt;overflow&lt;/code&gt; or &lt;code&gt;overflow-y&lt;/code&gt; properties that will create scrollbars are &lt;code&gt;visible&lt;/code&gt; and &lt;code&gt;auto&lt;/code&gt; provided that the &lt;code&gt;scrollHeight&lt;/code&gt; is greater than the &lt;code&gt;clientHeight&lt;/code&gt;. A value of &lt;code&gt;scroll&lt;/code&gt; for the &lt;code&gt;overflow&lt;/code&gt; or &lt;code&gt;overflow-y&lt;/code&gt; properties will always cause a scrollbar.&lt;/p&gt;
&lt;p&gt;This is, once again, a bit of a simplification.&lt;/p&gt;
&lt;p&gt;In quirksmode in IE8 &lt;code&gt;document.documentElement.clientHeight&lt;/code&gt; is 0. The root element is &lt;code&gt;document.body&lt;/code&gt;. This won’t affect most people reading this, but just to be on the safe side let’s add it into our solution.&lt;/p&gt;
&lt;p&gt;The final solution looks like this:&lt;/p&gt;
&lt;div class=&quot;sourceCode&quot; id=&quot;cb4&quot;&gt;&lt;pre class=&quot;sourceCode numberSource javascript numberLines&quot;&gt;&lt;code class=&quot;sourceCode javascript&quot;&gt;&lt;a class=&quot;sourceLine&quot; id=&quot;cb4-1&quot; title=&quot;1&quot;&gt;&lt;span class=&quot;kw&quot;&gt;var&lt;/span&gt; hasScrollbar &lt;span class=&quot;op&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kw&quot;&gt;function&lt;/span&gt;() &lt;span class=&quot;op&quot;&gt;{&lt;/span&gt;&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb4-2&quot; title=&quot;2&quot;&gt;  &lt;span class=&quot;co&quot;&gt;// The Modern solution&lt;/span&gt;&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb4-3&quot; title=&quot;3&quot;&gt;  &lt;span class=&quot;cf&quot;&gt;if&lt;/span&gt; (&lt;span class=&quot;kw&quot;&gt;typeof&lt;/span&gt; &lt;span class=&quot;va&quot;&gt;window&lt;/span&gt;.&lt;span class=&quot;at&quot;&gt;innerWidth&lt;/span&gt; &lt;span class=&quot;op&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;#39;number&amp;#39;&lt;/span&gt;)&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb4-4&quot; title=&quot;4&quot;&gt;    &lt;span class=&quot;cf&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;va&quot;&gt;window&lt;/span&gt;.&lt;span class=&quot;at&quot;&gt;innerWidth&lt;/span&gt; &lt;span class=&quot;op&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;va&quot;&gt;document&lt;/span&gt;.&lt;span class=&quot;va&quot;&gt;documentElement&lt;/span&gt;.&lt;span class=&quot;at&quot;&gt;clientWidth&lt;/span&gt;&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb4-5&quot; title=&quot;5&quot;&gt;&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb4-6&quot; title=&quot;6&quot;&gt;  &lt;span class=&quot;co&quot;&gt;// rootElem for quirksmode&lt;/span&gt;&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb4-7&quot; title=&quot;7&quot;&gt;  &lt;span class=&quot;kw&quot;&gt;var&lt;/span&gt; rootElem &lt;span class=&quot;op&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;va&quot;&gt;document&lt;/span&gt;.&lt;span class=&quot;at&quot;&gt;documentElement&lt;/span&gt; &lt;span class=&quot;op&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;va&quot;&gt;document&lt;/span&gt;.&lt;span class=&quot;at&quot;&gt;body&lt;/span&gt;&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb4-8&quot; title=&quot;8&quot;&gt;&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb4-9&quot; title=&quot;9&quot;&gt;  &lt;span class=&quot;co&quot;&gt;// Check overflow style property on body for fauxscrollbars&lt;/span&gt;&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb4-10&quot; title=&quot;10&quot;&gt;  &lt;span class=&quot;kw&quot;&gt;var&lt;/span&gt; overflowStyle&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb4-11&quot; title=&quot;11&quot;&gt;&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb4-12&quot; title=&quot;12&quot;&gt;  &lt;span class=&quot;cf&quot;&gt;if&lt;/span&gt; (&lt;span class=&quot;kw&quot;&gt;typeof&lt;/span&gt; &lt;span class=&quot;va&quot;&gt;rootElem&lt;/span&gt;.&lt;span class=&quot;at&quot;&gt;currentStyle&lt;/span&gt; &lt;span class=&quot;op&quot;&gt;!==&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;#39;undefined&amp;#39;&lt;/span&gt;)&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb4-13&quot; title=&quot;13&quot;&gt;    overflowStyle &lt;span class=&quot;op&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;va&quot;&gt;rootElem&lt;/span&gt;.&lt;span class=&quot;va&quot;&gt;currentStyle&lt;/span&gt;.&lt;span class=&quot;at&quot;&gt;overflow&lt;/span&gt;&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb4-14&quot; title=&quot;14&quot;&gt;&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb4-15&quot; title=&quot;15&quot;&gt;  overflowStyle &lt;span class=&quot;op&quot;&gt;=&lt;/span&gt; overflowStyle &lt;span class=&quot;op&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;va&quot;&gt;window&lt;/span&gt;.&lt;span class=&quot;at&quot;&gt;getComputedStyle&lt;/span&gt;(rootElem&lt;span class=&quot;op&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;#39;&amp;#39;&lt;/span&gt;).&lt;span class=&quot;at&quot;&gt;overflow&lt;/span&gt;&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb4-16&quot; title=&quot;16&quot;&gt;&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb4-17&quot; title=&quot;17&quot;&gt;    &lt;span class=&quot;co&quot;&gt;// Also need to check the Y axis overflow&lt;/span&gt;&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb4-18&quot; title=&quot;18&quot;&gt;  &lt;span class=&quot;kw&quot;&gt;var&lt;/span&gt; overflowYStyle&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb4-19&quot; title=&quot;19&quot;&gt;&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb4-20&quot; title=&quot;20&quot;&gt;  &lt;span class=&quot;cf&quot;&gt;if&lt;/span&gt; (&lt;span class=&quot;kw&quot;&gt;typeof&lt;/span&gt; &lt;span class=&quot;va&quot;&gt;rootElem&lt;/span&gt;.&lt;span class=&quot;at&quot;&gt;currentStyle&lt;/span&gt; &lt;span class=&quot;op&quot;&gt;!==&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;#39;undefined&amp;#39;&lt;/span&gt;)&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb4-21&quot; title=&quot;21&quot;&gt;    overflowYStyle &lt;span class=&quot;op&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;va&quot;&gt;rootElem&lt;/span&gt;.&lt;span class=&quot;va&quot;&gt;currentStyle&lt;/span&gt;.&lt;span class=&quot;at&quot;&gt;overflowY&lt;/span&gt;&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb4-22&quot; title=&quot;22&quot;&gt;&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb4-23&quot; title=&quot;23&quot;&gt;  overflowYStyle &lt;span class=&quot;op&quot;&gt;=&lt;/span&gt; overflowYStyle &lt;span class=&quot;op&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;va&quot;&gt;window&lt;/span&gt;.&lt;span class=&quot;at&quot;&gt;getComputedStyle&lt;/span&gt;(rootElem&lt;span class=&quot;op&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;#39;&amp;#39;&lt;/span&gt;).&lt;span class=&quot;at&quot;&gt;overflowY&lt;/span&gt;&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb4-24&quot; title=&quot;24&quot;&gt;&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb4-25&quot; title=&quot;25&quot;&gt;  &lt;span class=&quot;kw&quot;&gt;var&lt;/span&gt; contentOverflows &lt;span class=&quot;op&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;va&quot;&gt;rootElem&lt;/span&gt;.&lt;span class=&quot;at&quot;&gt;scrollHeight&lt;/span&gt; &lt;span class=&quot;op&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;va&quot;&gt;rootElem&lt;/span&gt;.&lt;span class=&quot;at&quot;&gt;clientHeight&lt;/span&gt;&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb4-26&quot; title=&quot;26&quot;&gt;  &lt;span class=&quot;kw&quot;&gt;var&lt;/span&gt; overflowShown    &lt;span class=&quot;op&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;sc&quot;&gt;^(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;visible&lt;/span&gt;&lt;span class=&quot;sc&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;auto&lt;/span&gt;&lt;span class=&quot;sc&quot;&gt;)$&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;/&lt;/span&gt;.&lt;span class=&quot;at&quot;&gt;test&lt;/span&gt;(overflowStyle) &lt;span class=&quot;op&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;sc&quot;&gt;^(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;visible&lt;/span&gt;&lt;span class=&quot;sc&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;auto&lt;/span&gt;&lt;span class=&quot;sc&quot;&gt;)$&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;/&lt;/span&gt;.&lt;span class=&quot;at&quot;&gt;test&lt;/span&gt;(overflowYStyle)&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb4-27&quot; title=&quot;27&quot;&gt;  &lt;span class=&quot;kw&quot;&gt;var&lt;/span&gt; alwaysShowScroll &lt;span class=&quot;op&quot;&gt;=&lt;/span&gt; overflowStyle &lt;span class=&quot;op&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;#39;scroll&amp;#39;&lt;/span&gt; &lt;span class=&quot;op&quot;&gt;||&lt;/span&gt; overflowYStyle &lt;span class=&quot;op&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;st&quot;&gt;&amp;#39;scroll&amp;#39;&lt;/span&gt;&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb4-28&quot; title=&quot;28&quot;&gt;&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb4-29&quot; title=&quot;29&quot;&gt;  &lt;span class=&quot;cf&quot;&gt;return&lt;/span&gt; (contentOverflows &lt;span class=&quot;op&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; overflowShown) &lt;span class=&quot;op&quot;&gt;||&lt;/span&gt; (alwaysShowScroll)&lt;/a&gt;
&lt;a class=&quot;sourceLine&quot; id=&quot;cb4-30&quot; title=&quot;30&quot;&gt;&lt;span class=&quot;op&quot;&gt;}&lt;/span&gt;&lt;/a&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;If I missed something, or if &lt;em&gt;this&lt;/em&gt; solution is a bit of an oversimplification (le sigh), please let me know in the comments.&lt;/p&gt;
</description>


	<comments>//tylercipriani.com/blog/2014/07/12/crossbrowser-javascript-scrollbar-detection/#comments</comments>

</item>
<item>
	<title>CSS display inline-block Extra Margin/Space</title>

	<guid isPermaLink="false">https://tylercipriani.com/blog/2012/08/01/display-inline-block-extra-margin/</guid>

	<link>https://tylercipriani.com/blog/2012/08/01/display-inline-block-extra-margin/</link>

	<dc:creator>Tyler Cipriani</dc:creator>



	<category>computing</category>

	<category>design</category>


	<pubDate>Wed, 01 Aug 2012 00:00:00 +0000</pubDate>
	<dcterms:modified>2017-02-14T15:11:05Z</dcterms:modified>


	<description>&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;: The margin isn’t a margin—it’s a space. Try using &lt;code&gt;display: block; float: left;&lt;/code&gt; instead.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;ALSO:&lt;/strong&gt; Checkout the amazing list of techniques to combat inline-block space-margins at &lt;a href=&quot;http://css-tricks.com/fighting-the-space-between-inline-block-elements/&quot; title=&quot;Fighting the Space Between inline-block Elements&quot;&gt;CSS Tricks&lt;/a&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;I’ve made a weird discovery about using the inline-block display. I use inline-block elements on my &lt;a href=&quot;http://www.tylercipriani.com,&quot; title=&quot;Tyler Cipriani&quot;&gt;homepage&lt;/a&gt; in the &lt;em&gt;Recent Work&lt;/em&gt; section.&lt;/p&gt;
&lt;p&gt;I noticed that the math for these block elements wasn’t quite adding up—the element width + padding + margin + border should’ve enabled three items on one line; however, the elements were wrapping.&lt;/p&gt;
&lt;p&gt;Here’s an example of what I’m talking about:&lt;/p&gt;
&lt;iframe style=&quot;margin: 1em 0; width: 100%; height: 300px;&quot; src=&quot;https://jsfiddle.net/thcipriani/r7egr/embedded/result,html,css/&quot; allowfullscreen=&quot;allowfullscreen&quot; frameborder=&quot;0&quot;&gt;
&lt;/iframe&gt;
&lt;p&gt;Even though the margin of each element is set to zero there is seemingly, a margin, between each element.&lt;/p&gt;
&lt;p&gt;This problem could be easily solved by removing the display property, floating each gallery item and using a clearfix on the parent:&lt;/p&gt;
&lt;iframe style=&quot;margin: 1em 0; width: 100%; height: 300px;&quot; src=&quot;https://jsfiddle.net/thcipriani/r7egr/2/embedded/result,html,css/&quot; allowfullscreen=&quot;allowfullscreen&quot; frameborder=&quot;0&quot;&gt;
&lt;/iframe&gt;
&lt;p&gt;That solution, however, ignores &lt;em&gt;why&lt;/em&gt; that space is being added.&lt;/p&gt;
&lt;p&gt;The inline-block display property treats block level elements (e.g. &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;) as an inline element (e.g. &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt;), and, just like if you had a line break between two &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt; elements, the line-break between the &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;s is creating a space between the &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;s. &lt;strong&gt;That extra margin is actually a space—not a margin&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Knowing what is creating an inline-block displayed &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;’s “margin” enables you to create a couple of different solutions.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;First&lt;/strong&gt;, the dumb and breakable solution, you could remove the spaces and line-breaks in your html&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Second&lt;/strong&gt;, directly address the space by setting a negative right margin or negative word-spacing for those elements&lt;/li&gt;
&lt;li&gt;Or, &lt;strong&gt;Finally&lt;/strong&gt;, just use &lt;code&gt;display: block; float: left;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here’s an example of what the second solution would look like:&lt;/p&gt;
&lt;iframe style=&quot;margin: 1em 0; width: 100%; height: 300px&quot; src=&quot;https://jsfiddle.net/thcipriani/r7egr/3/embedded/result,html,css/&quot; allowfullscreen=&quot;allowfullscreen&quot; frameborder=&quot;0&quot;&gt;
&lt;/iframe&gt;
</description>


	<comments>//tylercipriani.com/blog/2012/08/01/display-inline-block-extra-margin/#comments</comments>

</item>
<item>
	<title>Website Contrast Ratio in Practice</title>

	<guid isPermaLink="false">https://tylercipriani.com/blog/2012/07/27/contrast-ratio-in-action/</guid>

	<link>https://tylercipriani.com/blog/2012/07/27/contrast-ratio-in-action/</link>

	<dc:creator>Tyler Cipriani</dc:creator>



	<category>design</category>


	<pubDate>Fri, 27 Jul 2012 00:00:00 +0000</pubDate>
	<dcterms:modified>2017-02-14T15:11:05Z</dcterms:modified>


	<description>&lt;p&gt;While perusing &lt;a href=&quot;http://news.ycombinator.com/&quot; title=&quot;Hacker News&quot;&gt;Hacker News&lt;/a&gt; I ran across a single-page site called &lt;a href=&quot;http://contrastrebellion.com/&quot; title=&quot;Contrast Rebellion&quot;&gt;Contrast Rebellion&lt;/a&gt;— which I understand has created a bit of controversy.&lt;/p&gt;
&lt;p&gt;I think the point espoused by Contrast Rebellion is both well-made and well-taken (despite the host of straw-man style arguments to the contrary); however, I feel that—in &lt;em&gt;most&lt;/em&gt; designs—contrast arises fairly organically. If I can’t read my font, or there isn’t enough contrast in my color palate, then I know that the people from whom I solicit opinions are going to mention that before saying anything else.&lt;/p&gt;
&lt;p&gt;If only we were all so lucky. ☺&lt;/p&gt;
&lt;p&gt;On the &lt;a href=&quot;http://www.w3.org/TR/WCAG10-CSS-TECHS/#style-color-contrast&quot; title=&quot;CSS Techniques for Web Content Accessibility Guidelines 1.0&quot;&gt;topic of color contrast&lt;/a&gt; the W3C defines &lt;a href=&quot;http://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html&quot; title=&quot;Success Criterion 1.4.3&quot;&gt;Success Criterion 1.4.3&lt;/a&gt; saying:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Contrast (Minimum)&lt;/strong&gt;: The visual presentation of text and images of text has a contrast ratio of at least 4.5:1, except for the following: (Level AA)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Large Text&lt;/strong&gt;: Large-scale text and images of large-scale text have a contrast ratio of at least 3:1;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Incidental&lt;/strong&gt;: Text or images of text that are part of an inactive user interface component, that are pure decoration, that are not visible to anyone, or that are part of a picture that contains significant other visual content, have no contrast requirement.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Logotypes&lt;/strong&gt;: Text that is part of a logo or brand name has no minimum contrast requirement.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;p&gt;There is a formula for calculating the contrast of two colors available at &lt;a href=&quot;http://www.paciellogroup.com/resources/contrast-analyser.html,&quot; title=&quot;Contrast Analyser&quot;&gt;the paciello group&lt;/a&gt;— they also have a Contrast Analyser that you can download for Mac and Windows.&lt;/p&gt;
&lt;p&gt;Alternately, you could skip the download and the hand-cranking of numbers and enter your hex codes into the &lt;a href=&quot;http://juicystudio.com/services/luminositycontrastratio.php,&quot; title=&quot;Luminosity Colour Contrast Ratio Analyser&quot;&gt;Luminosity Colour Contrast Ratio Analyser&lt;/a&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;edit&lt;/strong&gt;—11/23/2012&lt;/p&gt;
&lt;p&gt;My new favorite tool for contrast checking is &lt;a href=&quot;http://leaverou.github.com/contrast-ratio/&quot;&gt;Lea Verou’s constrast checker&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr /&gt;
&lt;p&gt;&lt;strong&gt;Looking at popular websites contrast&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The genesis of this exercise was to review websites I have built and to review some other popular sites so lets do that …&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;&lt;strong&gt;The contrast on this site&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;It’s pretty good right? The text you’re reading I mean— it’easy to read, contrast-wise anyway.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Text color&lt;/strong&gt;: &lt;a href=&quot;http://www.colourlovers.com/color/444444&quot;&gt;#444444&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Background color&lt;/strong&gt;: &lt;a href=&quot;http://www.colourlovers.com/color/F8F8F8&quot;&gt;#f8f8f8&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrast-ratio&lt;/strong&gt;: 9.17:1&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Analysis&lt;/strong&gt;: Pretty amazing.&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;edit&lt;/strong&gt;—11/23/2012&lt;/p&gt;
&lt;p&gt;You’re looking at Text color: &lt;a href=&quot;http://www.colourlovers.com/color/8f8d80&quot;&gt;#8f8d80&lt;/a&gt; which means that the contrast ratio here has dropped to 3.1:1—which meets the success cirterion for the current text-size of 24px! (which is, admittedly, very large, but whatever, I ain’t scared).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr /&gt;
&lt;p&gt;&lt;strong&gt;Apple’s nav bar&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;blogImg&quot; src=&quot;http://tylercipriani-files.s3.amazonaws.com/blog/Apple-nav-bar.png&quot; alt=&quot;Apple&#39;s nav bar&quot;&gt;&lt;/p&gt;
&lt;p&gt;Apple’s nav bar is a gradient, so this analysis is for the color at the lightest point of the gradient versus the text&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Text color&lt;/strong&gt;: &lt;a href=&quot;http://www.colourlovers.com/color/FFFFFF&quot;&gt;#FFFFFF&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Background color&lt;/strong&gt; (again, at the lightest part of the gradient): &lt;a href=&quot;http://www.colourlovers.com/color/727272&quot;&gt;#727272&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrast-ratio&lt;/strong&gt;: 4.81:1&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Analysis&lt;/strong&gt;: Passed at Level AA for regular text, and pass at Level AAA for large text (18pt or 14pt bold)—Apple’s nav text is SVG (ostensibly for the new retina displays), but it seems to be about 13pt–14pt. A little low-contrast perhaps, but not too drastic.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;
&lt;p&gt;&lt;strong&gt;Google’s account settings bar&lt;/strong&gt;&lt;/p&gt;
&lt;figure&gt;
&lt;img src=&quot;http://tylercipriani-files.s3.amazonaws.com/blog/google-account-settings.png&quot; alt=&quot;Google’s account settings bar&quot; /&gt;&lt;figcaption&gt;Google’s account settings bar&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;The Google account settings bar has always seemed to be fairly low-contrast to me—let’s test a theory.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Text color&lt;/strong&gt;: &lt;a href=&quot;http://www.colourlovers.com/color/666666&quot;&gt;#666666&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Background color&lt;/strong&gt;: &lt;a href=&quot;http://www.colourlovers.com/color/F1F1F1&quot;&gt;#F1F1F1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrast-ratio&lt;/strong&gt;: 5.08:1&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Analysis&lt;/strong&gt;: Passed at Level AA for regular text, and pass at Level AAA for large text (18pt or 14pt bold)—better contrast than Apple; however, the text in this image above is 13px/27px Arial,sans-serif at the default font-weight which is close, but not quite ideal.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Out of curiousity I decided to see what these recommendations would look like for Google in practice—answer: more readable, arguably less aesthetically appealing (see below).&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;blogImg&quot; src=&quot;http://tylercipriani-files.s3.amazonaws.com/blog/google-account-settings_large.png&quot; alt=&quot;Google&#39;s account settings bar—larger font&quot;&gt;&lt;/p&gt;
</description>


	<comments>//tylercipriani.com/blog/2012/07/27/contrast-ratio-in-action/#comments</comments>

</item>

</channel>
</rss>
