Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As the previous answers suggest, you could put <code>float:left</code> on the <code>menulinkboxaround</code>.</p> <p>It is difficult to tell from your description the desired effect, I am assuming you want the menu to be horizontal with 50px either side of the links.</p> <p>With the code you currently have, the hover state only stretches in one direction, also as you are only specifying :hover it is not really as keyboard friendly as it would be if you specified :focus as well. </p> <p>Also because you are setting the height in px as you increase the font size the text becomes clipped at the bottom. Not specifying the pseudo selectors on the link may also cause you later problems in Internet Explorer.</p> <p>You could also tidy up the code a little to reduce the unnecessary classes and improve the semantics of the menu. </p> <p>For example:</p> <pre><code> &lt;style type=&quot;text/css&quot;&gt; ul.menu { /* removing the browser defaults for margin padding and bullets */ margin: 0; padding: 0; list-style-type: none; /* Now you have a sensible parent it is a good idea to put the font family here, I have also added a fallback of sans-serif in the rare case Helvetica and Verdana are not available on the users computer, it might be best to set this on the body if you are using this font site-wide */ font-family: Verdana, Helvetica, sans-serif; /* To create symetry I am adding 25px to the right and left of the menu, this will stay green even if the items inside are not */ padding: 0 25px; background-color: green; /* increacing the lineheight so the background color of the links does not overflow the green of the menu behind it, for a simple menu like this it is fine, a more complex or longer links that need to wrap I suggest changing the method of implementation from display inline to floating which is a bit more complex */ line-height:1.95; } /* because all the list items are inside this parent list you can use the descendant selector to target them rather than adding a separate class, you are saying all list items inside the unordered list that has a class of menu */ ul.menu li { /* telling the list items to behave like inline elements so they are naturally on one line also removint the browser default margin and padding */ display: inline; margin: 0; padding: 0; } ul.menu a:link, ul.menu a:visited, ul.menu a:hover, ul.menu a:focus, ul.menu a:active { /* you can combine all your padding rules together in the order Top Right Bottom Left, I remember this like it kinda spells TRouBLe :) */ padding: 5px 25px 5px 25px; background-color: green; /* setting the color to white because the default link color of blue is not that visible against green */ color: white; } /* adding the :focus selector to make this more keyboard accessible */ ul.menu a:hover, ul.menu a:focus { background-color: red; color: black; } ul.menu a:visited { background-color: yellow; color: black; } &lt;/style&gt; &lt;/pre&gt; &lt;ul class=&quot;menu&quot;&gt; &lt;!-- Putting these all on one line because we are making them display:inline so the spaces get counted and there will be a gap otherwise --&gt; &lt;li&gt;&lt;a href=&quot;asdf.gif&quot;&gt;Link 1&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;asdf.gif&quot;&gt;Link 2&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;asdf.gif&quot;&gt;Link 3&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>I have tested this in recent versions of FF, Opera and Safari, and IE6 IE7 and IE8</p> <pre><code> &lt;style type=&quot;text/css&quot;&gt; ul.menu { margin: 0; padding: 0; list-style-type: none; font-family: Verdana, Helvetica, sans-serif; padding: 0 25px; background-color: green; /* overflow hidden clears the internal floated links and zoom 1 kicks IE into doing the same, I suggest you move the zoom: 1 into an IE stylesheet using conditional comments */ overflow: hidden; zoom: 1; } ul.menu li { display: inline; margin: 0; padding: 0; } ul.menu a:link, ul.menu a:visited, ul.menu a:hover, ul.menu a:focus, ul.menu a:active { padding: 5px 25px 5px 25px; background-color: green; color: white; /* setting the links to float left and giving them display block as well explicitly, this is so that the vertical padding of 5px gets applied, inline elements can only have horizontal margin and padding, and since we are floating them they now take up 0 vertical height in the document which is why we needed to clear the float on the surrounding menu */ display: block; float: left; } ul.menu a:hover, ul.menu a:focus { background-color: red; color: black; } ul.menu a:visited { background-color: yellow; color: black; } &lt;/style&gt; &lt;ul class=&quot;menu&quot;&gt; &lt;li&gt;&lt;a href=&quot;asdf.gif&quot;&gt;Link 1&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;asdf.gif&quot;&gt;Link 2&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;asdf.gif&quot;&gt;Link 3&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>This second method is much more reliable, deals with wrapping links nicer and is generally a better solution but a bit harder to explain.</p> <p>If you didn't want the menu to fill the full width of the screen just as long as the text takes up, regardless of which method you are using above, I suggest you put <code>float: left</code> and <code>clear: both</code> on the <code>ul.menu</code> which should shrink to the width it needs to take up</p> <p>I hope this helps</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.
    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