Note that there are some explanatory texts on larger screens.

plurals
  1. POJQuery stretch buttons horizontal to window width
    primarykey
    data
    text
    <p>I try to create a menu that streches its items to the window width. Could someone please tell me what I'm doing wrong? I know that this question has been asked before but I just don't know what's wrong with my code.</p> <p>This is what I"m trying to achieve. The red is the window</p> <p><img src="https://i.stack.imgur.com/KOFiE.jpg" alt=""></p> <p><a href="http://jsfiddle.net/JdGeQ/5/" rel="nofollow noreferrer">http://jsfiddle.net/JdGeQ/5/</a></p> <p>Javascript</p> <pre><code>$(function(){ $(window).resize(function (e) { setTimeout(function () { resizeButtons(); }, 200); }); resizeButtons(); }); function resizeButtons() { var count = $("#menu").length; var itemwidth = $(window).width / count; $(".item").css("background", "blue"); $(".item").css("width", itemwidth); } </code></pre> <p>css</p> <pre><code>.elementtop { position: fixed; top: 0; } .elementfooter { position: fixed; bottom: 0; } .elementright { right: 0; } ul { min-width:100%; padding:0; margin:0; float:left; list-style-type:none; background: #000000; } li { display:inline; } a { overflow: hidden; text-decoration:none; color:white; background-color:purple; padding:0.2em 0.6em; border-right:1px solid white; } </code></pre> <p>html</p> <pre><code>&lt;div&gt; &lt;ul id="menu"&gt; &lt;li&gt; &lt;a href="#" class="item"&gt; &lt;span&gt;Text text&lt;/span&gt; &lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="#" class="item"&gt; &lt;span&gt;Text2&lt;/span&gt; &lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="#" class="item"&gt; &lt;span&gt;Text3&lt;/span&gt; &lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; </code></pre> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload