Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

JavaScript

Get Viewport width. jQuery

1
2
3
4
5
6
7
8
function viewportWidth() {
    var $body = $('body'),
        viewPortWidth = $body.css('overflow', 'hidden').width();
    
    $body.css('overflow', '');

    return viewPortWidth;
}
https://snipt.net/embed/9935d9ab42e952161c3411323936eafc/
https://snipt.net/raw/9935d9ab42e952161c3411323936eafc/
9935d9ab42e952161c3411323936eafc
js
JavaScript
8
2016-12-06T17:13:36
True
False
False
Apr 05, 2014 at 03:42 PM
/api/public/snipt/127685/
get-viewport-width-jquery
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="kd">function</span> <span class="nx">viewportWidth</span><span class="p">()</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="kd">var</span> <span class="nx">$body</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="s1">&#39;body&#39;</span><span class="p">),</span> </span><span id="L-3"><a name="L-3"></a> <span class="nx">viewPortWidth</span> <span class="o">=</span> <span class="nx">$body</span><span class="p">.</span><span class="nx">css</span><span class="p">(</span><span class="s1">&#39;overflow&#39;</span><span class="p">,</span> <span class="s1">&#39;hidden&#39;</span><span class="p">).</span><span class="nx">width</span><span class="p">();</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a> <span class="nx">$body</span><span class="p">.</span><span class="nx">css</span><span class="p">(</span><span class="s1">&#39;overflow&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">);</span> </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a> <span class="k">return</span> <span class="nx">viewPortWidth</span><span class="p">;</span> </span><span id="L-8"><a name="L-8"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
function, jquery, simple, width

CSS

Natural box style

1
2
3
4
/* apply a natural box layout model to all elements */
* { -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; }

/* paulirish.com/2012/box-sizing-border-box-ftw/ */
https://snipt.net/embed/15dbbdd06a377e4b5d02aa5bea7e1e05/
https://snipt.net/raw/15dbbdd06a377e4b5d02aa5bea7e1e05/
15dbbdd06a377e4b5d02aa5bea7e1e05
css
CSS
4
2016-12-06T17:07:36
True
False
False
/api/public/snipt/41946/
natural-box-style
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c">/* apply a natural box layout model to all elements */</span> </span><span id="L-2"><a name="L-2"></a><span class="o">*</span> <span class="p">{</span> <span class="o">-</span><span class="n">moz</span><span class="o">-</span><span class="n">box</span><span class="o">-</span><span class="n">sizing</span><span class="o">:</span> <span class="nb">border</span><span class="o">-</span><span class="n">box</span><span class="p">;</span> <span class="o">-</span><span class="n">webkit</span><span class="o">-</span><span class="n">box</span><span class="o">-</span><span class="n">sizing</span><span class="o">:</span> <span class="nb">border</span><span class="o">-</span><span class="n">box</span><span class="p">;</span> <span class="n">box</span><span class="o">-</span><span class="n">sizing</span><span class="o">:</span> <span class="nb">border</span><span class="o">-</span><span class="n">box</span><span class="p">;</span> <span class="p">}</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="c">/* paulirish.com/2012/box-sizing-border-box-ftw/ */</span> </span></pre></div> </td></tr></table>
border-box, margin, padding, width

CSS

IE max/min-width

1
2
3
4
5
div{
width: expression(document.body.clientWidth < 762? "760px" : document.body.clientWidth > 1242? "1240px" : "auto");
min-width: 760px;
max-width: 1240px;
}
https://snipt.net/embed/3dbc022bb8c3577b4148113dc66de008/
https://snipt.net/raw/3dbc022bb8c3577b4148113dc66de008/
3dbc022bb8c3577b4148113dc66de008
css
CSS
5
2016-12-07T19:57:25
True
False
False
/api/public/snipt/34580/
ie-maxmin-width
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="nt">div</span><span class="p">{</span> </span><span id="L-2"><a name="L-2"></a><span class="nb">width</span><span class="o">:</span> <span class="n">expression</span><span class="p">(</span><span class="n">document</span><span class="o">.</span><span class="n">body</span><span class="o">.</span><span class="n">clientWidth</span> <span class="o">&lt;</span> <span class="m">762</span><span class="o">?</span> <span class="s2">&quot;760px&quot;</span> <span class="o">:</span> <span class="n">document</span><span class="o">.</span><span class="n">body</span><span class="o">.</span><span class="n">clientWidth</span> <span class="o">&gt;</span> <span class="m">1242</span><span class="o">?</span> <span class="s2">&quot;1240px&quot;</span> <span class="o">:</span> <span class="s2">&quot;auto&quot;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="nb">min-width</span><span class="o">:</span> <span class="m">760px</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="nb">max-width</span><span class="o">:</span> <span class="m">1240px</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
ie, max, min, width

CSS

simple css

.ccc{width:100px; float:left;}
https://snipt.net/embed/b35e550d1ad83eed1f0b4a6db784d456/
https://snipt.net/raw/b35e550d1ad83eed1f0b4a6db784d456/
b35e550d1ad83eed1f0b4a6db784d456
css
CSS
1
2016-12-02T21:03:07
True
False
False
/api/public/snipt/27921/
simple-css
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="nc">.ccc</span><span class="p">{</span><span class="nb">width</span><span class="o">:</span><span class="m">100px</span><span class="p">;</span> <span class="nb">float</span><span class="o">:</span><span class="nb">left</span><span class="p">;}</span> </span></pre></div> </td></tr></table>
css, width
Copyrighted, illegal, or inappropriate content? Email [email protected].