Styling List Buttons - html

Using a list, I want to create a list of links as in the image
<div id="toolbarbottom" class="toolbar" style="position: fixed; clear: both; overflow: visible; bottom: 0px; left: 0px; width: 100%;">
<ul>
<li id="active"><span><a id="current" href="#add" class="button">News</a></span></li>
<li><span> Updates</span> </li>
<li><span>Contact Us</span></li>
<li><span>Website </span></li>
<li><span>Refresh</span> </li>
</ul>
</div>
I am kind of stuck on the CSS (button) and probably the spacing between the list elements. to make the list appear in this form. Anyone with an idea of how I can tackle this please?

or another way is to use floats, and make the ul display: inline-block to contain the floated li's
you need to slightly change the HTML so the span is inside the a - this is so you can hide the spanned text, but keep the image background and clickable area for the a elements, also I'd give each link a unique reference (class or ID) so the backgrounds can be applied separately.
example HTML:
<div id="toolbarbottom" class="toolbar" style="position: fixed; top: 0px; left: 0px; width: 100%;">
<ul>
<li class="active"><span>News</span></li>
<li><span> Updates</span></li>
<li><span>Contact Us</span></li>
<li><span>Website </span></li>
<li><span>Refresh</span> </li>
</ul>
</div>
you can then put the whole background on the ul and put the individual images on each link.
#toolbarbottom ul {
list-style: none;
margin: 0;
padding: 0;
display: inline-block;
width: 100%;
background: #ff0;
}
#toolbarbottom li {
float: left;
width: 80px;
height: 80px;
border: 1px solid #000; /* not required, just to show where individual links are */
}
#toolbarbottom li a { /* make link fill the li element */
display: block;
height: 80px;
}
#toolbarbottom li span { /* hide the text */
position: absolute;
clip: rect(1px, 1px, 1px, 1px);
clip: rect (1px 1px 1px 1px);
}
/* couple examples of where to put individual backgrounds */
#toolbarbottom #mupdates {background: #dad;}
#toolbarbottom #mcontact {background: #0f0;}

fiddle: http://jsfiddle.net/YaS9J/
css
#toolbarbottom li {
display:inline-block;
padding:0 10px;
}
/* if you have one */
#toolbarbottom li img {
display:block;
}

You should first set up your css as an external style sheet rather than hard code it into your html. (See http://www.w3.org/TR/html4/present/styles.html for more on this). To add spacing between the li elements you can use the css cascade to add some bottom padding as follows:
#toolbarbottom ul li {
padding-bottom:4px;
}
To make the list appear inline you would use:
#toolbarbottom ul{
list-style: none;
display: inline;
padding-left: 0;
margin-left: 0;
}
Those button look like images, so to achieve that you'd just include them within each li element:
<li><img src="/path/to/image.jpg"></li>

Related

<ul> Background colour won't work. I'm trying to add a background for my page breadcrumbs

I'm trying to add my website breadcrumbs to a list and change the list background to #0765de, i have tried as seen below, only the <li> background will change colour.
I have to change the width of li so the text is in the page so the background cuts off. that's why I need it in ul.
Heres the HTML:
<ul class="breadcrumb_unli">
<li class="breadcrumb_unli">{ include'breadcrumb' }</li>
</ul>
Heres the CSS:
.breadcrumb_unli ul {
width: 100%;
overflow: hidden;
background-color: #0765de;
}
.breadcrumb_unli li {
width: 60%;
color: white;
margin: auto;
margin-top: -30px;
padding: 10px 10px 10px 0px;
}
Any help would be appreciated.
to select a ul with a specific class you should do this:
ul.breadcrumb_unli {
width: 100%;
overflow: hidden;
background-color: #0765de;
}
if it didn't work, try adding display: block or display: inline-block to the ul

Having issues with CSS3 background colors

Basically there should be a background color for the whole navbar across the screen, but it isn't showing up when I run the code. I would expect them to format everything inside the navigation div to that color, but it doesn't. I am fairly new to HTML5 and CSS3, so it could be a stupid mistake, but I have done some research and can't find any answers.
#navigation {
width: 100%;
height: auto;
background-color: #1d517e;
background: linear-gradient(to bottom, #003b6e, #1d517e);
}
#navigation ul {
display: inline-block;
margin: 0;
padding: 0;
}
#navigation ul.left {
float: left;
}
#navigation ul.right {
float: right;
}
#navigation ul li {
display: inline-block;
margin: 0;
padding: 6px 10px 5px 10px;
list-style: none;
background-color: transparent;
background-color: rgba(0, 0, 0, 0.12);
}
#navigation ul.left li {
float: left;
border-right: 1px solid black;
}
#navigation ul.right li {
float: right;
border-left: 1px solid black;
}
<div id="navigation">
<ul class="left">
<li>Electronics</li>
<li>Gardening</li>
<li>Cooking</li>
<li>Art</li>
</ul>
<ul class="right">
<li>About Us</li>
</ul>
</div>
<div class="clear"></div>
That's because you're floating the ul . You will need to clear them.
Try adding this:
#navigation:after {
clear: both;
content: " ";
display: block;
}
Also, ul.right needs to have li first and a inside li
Basically, since you're floating the uls, you must add float: left to their parent, #navigation too. Otherwise it will just have zero height and that's why the background isn't visible.
Replace height:auto; with height:29px; for #navigation
The reason why your background on the #navigation div is not showing on the navbar is because both of the children uls are floating. This makes it so that the parent div does not have a height. You can fix this by either adding a height to #navigation like so:
#navigation {
height: 29px;
}
or you can add a .clearfix class to the #navigation div with the css below:
.clearfix:after {
content: "";
display: table;
clear: both;
}
and add the class to your div like so:
<div class="clearfix" id="navigation"></div>
It is nice to create a clearfix class because you will be able to use this in your project everywhere else you have this issue. This will also allow you to get rid of that clear div you have at the bottom. If you want to learn more about clearfix here is the article I always refer too, CSS Tricks. There a lot of articles to read about how it works.
I'm assuming by a background colour, you're meaning the colour defined in the navigation div. Your navigation div has height: auto on it. You're floating the navigation links, but not clearing the floats or floating the parent. Because there is nothing for it to adjust based on, it takes up a height of 0 pixels by default.
Either float the parent:
#navigation {
width: 100%;
float: left; /* or height: 30px; */
background-color: #1d517e;
background: linear-gradient(to bottom, #003b6e, #1d517e);
}
Set a fixed height on the parent:
#navigation {
width: 100%;
height: 30px;
background-color: #1d517e;
background: linear-gradient(to bottom, #003b6e, #1d517e);
}
Or clear the floats (using overflow: auto is preferred):
#navigation {
width: 100%;
height: auto;
background-color: #1d517e;
background: linear-gradient(to bottom, #003b6e, #1d517e);
overflow: auto;
}
Which approach you go with is up to you :)
Hope this helps!
The clearer div should be placed inside the navigation bar just after the floated divs and the clear:both css should apply to it, currently it doesn't
add
#navigation {
overflow: hidden;
}
hope this helps

Horizontal menu not stretching to full width on hover in certain browsers

I have a horizontal menu that is made up of a series of ul's and li's. The submenus look great so I don't need to do anything with those. The primary ul looks great until you hover over the far right li.
When doing that, it looks good in Safari but the hover comes about 2 pixels short of the background on the ul in Firefox and IE and even more in Chrome. I have tried adjusting the padding to make it look good in Firefox and IE but then you still have the same issue in Chrome and in Safari, that far right li breaks down to a new line. Of course, adjusting it to look good in Chrome makes all the other browsers break to a new line. This site is using Wordpress which creates the menu dynamically so I can only change the CSS. Here is the basic idea for the code:
<html>
<head>
<style type="text/css">
#header {
margin: 0 auto;
width: 980px;
}
ul li {
font-size: 13px;
line-height: 21px;
}
#header .main-nav #menu-main-navigation {
background: #169BAC;
width: 100%
}
#header .main-nav > div ul {
width: 100%;
list-style: none;
float: left;
margin: 0;
padding: 0;
vertical-align: baseline;
}
#header .main-nav > div ul li ul{
top: 43px;
}
#header .main-nav .menu-div>ul>li {
padding: 5px 14px;
float: left;
border-right: solid 1px #54AEC2;
}
#header .main-nav .menu-div ul li:hover {
background: #2A588D;
}
#header .main-nav .menu-div>ul>li:first-child {
padding-top: 9px;
height: 28px;
}
#header .main-nav .menu-div>ul>li:last-child {
padding: 5px 26px;
border-right: none;
}
#header .main-nav .menu-div>ul>li a{
line-height: 15px;
text-decoration: none;
color: #FFF;
padding: 0px 13px;
text-align: center;
display: inline-block;
}
</style>
<head>
<body>
<header id="header">
<nav class="main-nav">
<div class="menu-div">
<ul id="menu-main-navigation" class="menu">
<li id="menu-item-275">Home</li>
<li id="menu-item-310">For New<br />Patients</li>
<li id="menu-item-376">Cleanings &<br />Prevention</li>
<li id="menu-item-381">General<br />Dentistry</li>
<li id="menu-item-453">Restore Your<br />Smile</li>
<li id="menu-item-462">Dental Anxiety &<br />Sedation Options</li>
<li id="menu-item-463">Dentistry For<br />Kids</li>
<li id="menu-item-464">Insurance &<br />Payment Options</li>
</ul>
</div>
</nav>
</header>
</body>
You can see the site at http://riverbend.caswellwebcreations.com.
Thank you for any help that you can give me on this.
The width of the li elements is being defined by their padding and the font-size (and padding) of the a elements inside them. The font propertys are not uniform between browsers, some browsers put text bigger or smaller than others. That seems to be the problem.
If you want to stretch the li elements "cross-browser" you should define the width of the li elements via css like this:
#menu-item-275{
width: 64px;
}
#menu-item-310{
width: 77px;
}
#menu-item-376{
width: 96px;
}
#menu-item-381{
width: 82px;
}
#menu-item-453{
width: 104px;
}
#menu-item-462{
width: 131px;
}
#menu-item-463{
width: 105px;
}
#menu-item-464{
width: 132px;
}
If you sum the width of each li item (plus padding and border) you get the width of the menu container: 980px. And the browsers will take that width to render the li's.
I hope this works!
UPDATE
Just found another (and more easy) solution!: https://stackoverflow.com/a/14361778/3762078
#header .main-nav .menu-div>ul>li:last-child {
padding: 5px 20px;
border-right: none;
float: none; /* ADD THIS */
overflow: hidden; /* AND THIS */
}
'float: none'. Forces last li element to be as wide as it can (the
default block element's behavior).
'overflow: hidden'. Prevents the last li element to stretch to ul's full width.
Although this doesn't prevent the width changes to all li elements on every browser, hence making the last li's width be thinner or wider (and sometimes expanding that li's height), is a nice solution.

How to make a navbar like WikiHow?

I would like a navbar like WikiHow with a icon on top and text beneath. I have been taking a look at their code but it seems pretty messy and I think there is easier ways to do it.
CSS
nav ul li{
border-left: 1px solid red;
height: 80px;
position: relative;
display: inline-block;
width: 70px;
}
.nav_icon{
margin-top: 15px;
background: url('inc/icon.png');
}
HTML
<nav>
<ul>
<li><div class="nav_icon"></div>HOME</li>
<li>PICTURES</li>
<li>ABOUT</li>
</ul>
</nav>
Then I created a <div> that I inserted before "HOME" in the first <li> element. I put some padding-top: 15px; on the div to make it go down a bit, but affects the whole <li> elements. I just want the icon to get some margin from the top...
http://jsfiddle.net/JmZbG/1/
By default inline blocks will align based on their text baseline.
Just add vertical-align: top; to the CSS for nav ul li to have them align by their top edge instead.
Here's my version: http://jsfiddle.net/JmZbG/2/
And here's an explanation of the changes:
nav ul li {
border-left: 1px solid red;
height: 80px;
line-height: 80px; /* Center the labels vertically */
float: left; /* Another way of lining up the <li>s horizontally */
display: inline-block;
}
.nav_icon {
display: inline-block; /* Needs to be an inline-block to be inline with the text */
vertical-align: middle; /* This centers the image vertically in it's <li> */
width: 46px; /* Need to define a size for an empty <div>... */
height: 41px; /* ...in order to see the background image */
background-image: url("http://i.imgur.com/mDXvZOZ.jpg");
}

Right align some text within a list item

I have a nested unordered list which has main content on the left, and I would like to add options which are floated right, such that they are aligned on the right regardless of the level of indentation.
<ul>
<li> Item 1 <span class='options'> link </span> </li>
<li> Item 2 <span class='options'> link </span>
<ul>
<li>Item 3 <span class='options'> link </span> </li>
</ul>
</li>
</ul>
I have the following css:
ul {
list-style: none;
padding: 0;
margin: 0;
}
li {
padding-left: 15px;
width: 400px;
}
.options {
float: right;
width: 50px;
}
When this is used however the options span is aligned to the right, but 1 line below the expected line.
How can I get the options span to line up with the list item?
TIA,
Adam
Instead of floating, you may want to try absolute positioning.
ul {
list-style: none;
padding: 0;
margin: 0;
}
li {
padding-left: 15px;
width: 400px;
position: relative;
}
.options {
width: 50px;
position: absolute;
right: 0px;
}
Using this CSS:
ul {
list-style: none;
padding: 0;
margin: 0;
}
li {
padding-left: 15px;
width:400px;
}
.options {
float: right;
width: 50px;
}
li li { width:385px}
This unfortunately requires your to define a width minus the padding. depending on your flexibility this will work. Tested in Chrome 3.0.
If modifying the HTML code is OK, you could enclose "Item 1" in a first span and:
float it to left (still floating .options to the right)
use display: inline-block on both span and text-align: right on .options, instead of floats (no compatible with Fx2 though, and only working in IE6/7 because span is an inline elements by default. Would not work with div)