Bootsrap 3 Inline Full Width List - Problem

Hi

I was wondering if the attached example could be acheived using Bootstrap 3.

I have this already in my code


<div class="container">
    <div class="row clearfix">
        <div class="col-md-12 footer-services">
            <ul class="nav nav-justified">
                <li><a href="#">Home</a></li>
                <li><a href="profile.htmm">Profile</a></li>
                <li><a href="sectors.htm">Sectors</a></li>
                <li><a href="clients.htm">Clients</a></li>
                <li><a href="accreditations.htm">Accreditations</a></li>
                <li><a href="contact.htm">Contact</a></li>
            </ul>
        </div>
    </div>
</div>

But the last item CONTACT does not “align to the right” fully of the page width.

Any ideas on how I could achieve this as per the example?

Many Thanks

You can try something like this:


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>justified menu items</title>
<!--
http://www.sitepoint.com/forums/showthread.php?1204989-Bootsrap-3-Inline-Full-Width-List-Problem
2014.04.11 18:44
mumford1
-->
    <style type="text/css">
ul {
    list-style:none;
    background-color:#eee;    /* TEST background-color */
    font-size:0;
    text-align:justify;
    padding:0;
    margin:0;
}
li {
    display:inline-block;
    background-color:#cff;    /* TEST background-color */
    font-size:1rem;
}
ul:after {
    content:'';
    display:inline-block;
    width:100%;
    height:1px;    /* TEST only */
    outline:1px solid pink;    /* TEST only */
}
a {
    display:block;
    padding:2px 10px 3px;
}
   </style>
</head>
<body>

<div class="container">
    <div class="row clearfix">
        <div class="col-md-12 footer-services">
            <ul class="nav nav-justified">
                <li><a href="#">Home</a></li>
                <li><a href="profile.htmm">Profile</a></li>
                <li><a href="sectors.htm">Sectors</a></li>
                <li><a href="clients.htm">Clients</a></li>
                <li><a href="accreditations.htm">Accreditations</a></li>
                <li><a href="contact.htm">Contact</a></li>
            </ul>
        </div>
    </div>
</div>

</body>
</html>


If setting the font-size to zero in the <ul> causes a problem in any devices, delete it and go from there. The <ul> will show space for an additional line below it.

Hi

Thanks for the response.

It is sort of working but I have a few issues as seen in the attachment.

Below is my CSS code


.nav-justified {
    width: 100%;
}
.nav-justified > li {
    float: none;
    margin:0;
}
ul.nav-justified {
    list-style:none;
    background-color:#eee;    /* TEST background-color */
    text-align:justify;
    padding:0;
    margin:0;
}
ul.nav-justified li {
    display:inline-block;
    background-color:#cff;    /* TEST background-color */
}
ul.nav-justified:after {
    content:'';
    display:inline-block;
    width:100%;
    height:1px;    /* TEST only */
    outline:1px solid pink;    /* TEST only */
}
ul.nav-justified li a {
    display:block;
    padding:2px 10px 3px;
}
.nav-justified > li > a {
  margin-bottom: 5px;
  text-align: left;
}
.footer-services .nav li a {
  margin:0;
  padding:0;
}

The lists are breaking out of the container, and the last list item is very narrow.

Hope you can help.

Thanks again.

I’m not sure what you mean by “breaking out of the container”.


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>justified menu items</title>
<!--
http://www.sitepoint.com/forums/showthread.php?1204989-Bootsrap-3-Inline-Full-Width-List-Problem
2014.04.11 18:44
mumford1
-->
    <style type="text/css">

ul.nav-justified > li {
    float:none;
    margin:0;    /* probably not necessary */
}

ul.nav-justified {
    list-style:none;
    width: 100%;    /* probably not necessary */
    background-color:#eee;    /* TEST background-color */
    text-align:justify;
    padding:0;
    margin:0;
}
ul.nav-justified li {
    display:inline-block;
    background-color:#cff;    /* TEST background-color */
    margin-bottom:5px;
}
ul.nav-justified:after {
    content:'';
    display:inline-block;
    width:100%;
    height:1px;    /* TEST only */
    outline:1px solid pink;    /* TEST only */
}
ul.nav-justified li a {
    display:block;
    white-space:nowrap;
    padding:2px 10px 3px;
}

/* these styles interfere with or override some of those above */
.nav-justified > li > a {
/*    margin-bottom: 5px;  /* Adds bottom height to anchors? */
/*    text-align: left;  /* I don't believe this should be necessary */
}
.footer-services .nav li a {
/*    margin:0;  /* unnecessary */
/*    padding:0;  /* this overrides the padding within the anchor */
}
    </style>
</head>
<body>

<div class="container">
    <div class="row clearfix">
        <div class="col-md-12 footer-services">
            <ul class="nav nav-justified">
<!--
                <li><a href="#">Home</a></li>
                <li><a href="profile.htmm">Profile</a></li>
                <li><a href="sectors.htm">Sectors</a></li>
                <li><a href="clients.htm">Clients</a></li>
                <li><a href="accreditations.htm">Accreditations</a></li>
                <li><a href="contact.htm">Contact</a></li>
-->
                <li><a href="contact.htm">Heating</a></li>
                <li><a href="contact.htm">Cooling</a></li>
                <li><a href="contact.htm">Ventilation</a></li>
                <li><a href="contact.htm">Plumbing</a></li>
                <li><a href="contact.htm">Design</a></li>
                <li><a href="contact.htm">Installation</a></li>
                <li><a href="contact.htm">Service</a></li>
                <li><a href="contact.htm">Maintenance</a></li>
                <li><a href="contact.htm">Emergency Call Out</a></li>
                <li><a href="contact.htm">Boiler Replacements</a></li>
                <li><a href="contact.htm">Electrics</a></li>
                <li><a href="contact.htm">Renewable Energy</a></li>
                <li><a href="contact.htm">Gas Safety</a></li>
            </ul>
        </div>
    </div>
</div>

</body>
</html>


If you look at the attachment. ul.nav-justified has a background colour. You can see that the last list item is overflowing this and is very narrow.

hope that makes more sense?

Here is a cut down version of the site I am working on

http://www.cre8tivesource.co.uk/test/about-test.htm

This has the footer ul code you are kindly helping me with.

The anchors are missing. According to your post and sample code, the text is supposed to be within anchors.

Copy the code that I posted into a file. It is a standalone web page. Give it a name with .html suffix. Double-click it and open it in your browser. It works.

Ok, thanks, sorry that was my mistake, they are not meant to have anchors. How would I achieve the dot separators, as per my first example?

I will work on your example for the time being. Thanks again.

This line of Bootstrap code is applying a width of 1% to the list items.
bootstrap.css (line 4220)


.nav-justified > li {
    display: table-cell;
    width: 1%;
}

You need to override that in your style.css by adding width:auto;
style.css (line 262)


ul.nav-justified li {
    background-color:#CCFFFF;
    display:inline-block;
    [color=blue]width:auto;[/color]
    margin-bottom:5px;
}

ahhhh sweet! yes that works much better now :slight_smile:

Try this: (this replaces the code in my previous posts, except for the first one where I talked about font-size assignments.)


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <link href="styles/bootstrap.css" rel="stylesheet">
    <link href="styles/site.css" rel="stylesheet">
    <link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:400,300,300italic,400italic,600,600italic,700,700italic,200,200italic' rel='stylesheet' type='text/css'>
    <style type="text/css">
ul.nav-justified {
    list-style:none;
    background-color:#eee;    /* TEST background-color */
    text-align:justify;
    padding:0;
    margin:0;
}
ul.nav-justified li {
    display:inline-block;
    width:auto;
    background-color:#cff;    /* TEST background-color */
    padding:2px 10px 3px;
}
ul.nav-justified:after {
    content:'';
    display:inline-block;
    width:100%;
    height:1px;    /* TEST only */
    outline:1px solid pink;    /* TEST only */
}
    </style>
</head>
<body>

<div class="container"> <!--START ROW 5 -->
    <div class="row clearfix">
        <div class="col-md-12 footer-services">
            <ul class="nav nav-justified">
                <li>Heating</li>
                <li>&bull;</li>
                <li>Cooling</li>
                <li>&bull;</li>
                <li>Ventilation</li>
                <li>&bull;</li>
                <li>Plumbing</li>
            </ul>
            <ul class="nav nav-justified">
                <li>Design</li>
                <li>&bull;</li>
                <li>Installation</li>
                <li>&bull;</li>
                <li>Service</li>
                <li>&bull;</li>
                <li>Maintenance</li>
                <li>&bull;</li>
                <li>Emergency Call Out</li>
            </ul>
            <ul class="nav nav-justified">
                <li>Boiler Replacements</li>
                <li>&bull;</li>
                <li>Electrics</li>
                <li>&bull;</li>
                <li>Renewable Energy</li>
                <li>&bull;</li>
                <li>Gas Safety</li>
            </ul>
        </div>
    </div>
</div> <!--END 3 ROW 5 -->
<hr />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/scripts.js"></script>
</body>
</html>


WOW! That is great, I thank you very much for your time.

I do have another annoying issue with the site I am working on and the Bootstrap framework I am using. It is with regard to <h1> tags that are for example in a column


<div class="col-md-8 column">
<div class="header-text-block">
 <h1>Text</h1>
 <h1>longer Text Longer Text</h1>
</div>
</div>

I have applied this css


.header-text-block h1 {
    background:#d52641;
    color: #fff;
    font-size:3.063em;
    font-weight:bold;
    line-height:30px;
    margin:0 0 10px 0;
    padding:15px;
}

I want the width of the <h1> and background colour to fill the space of the text and not the whole column width.

Again a visual would explain more. So please look at http://www.cre8tivesource.co.uk/test/about-test.htm (how it is currently)

And the attachment what I would like to achieve.

I hope you can help, and I will stop “bugging” you :slight_smile:

Thanks again, I do appreciate it.

An <h1> is a block element which means that it stretches the full width of its container by default. If you change <h1> to {display:inline-block;} it’s width will shrink to fit its contents and behave as you describe.


.header-text-block h1 {
    [color=blue]display:inline-block;[/color]
    background:#d52641;
    color:#fff;
    font-size:3.063em;
    font-weight:bold;
    line-height:30px;
    margin:0 0 10px 0;
    padding:15px;
}


This works on your page because the sum of the width of the two <h1> elements is greater than the width of their container. If the sum of their width were less than the width of their container, they would align in-line just like a sentence. You can delete a word or two from either line and see what I mean.

A more reliable technique is to enclose the text in each <h1> (block) element within <span> tags and set the <span> tags to {display:inline-block;} as shown here:


.header-text-block h1 {
    color:#fff;
    font-size:3.063em;
    font-weight:bold;
    line-height:30px;
    margin:0 0 10px;
}
h1 span {
    display:inline-block;
    background:#d52641;
    padding:15px;
}



                    <h1><span>We aim to exceed our</span></h1>
                    <h1><span>customers expectations</span></h1>

The above examples demonstrate how to achieve your objective; however, would like to mention that a page is expected to have only 1 <h1> tag which expresses the company name or something of equal weight. Search engines see it as the most important header on the page. Using 2 <h1> tags is semantically poor code.

There may be a more “economical” way to do this, but the following example works with only 1 <h1> tag:


.header-text-block h1 {
    color:#fff;
    font-size:3.063em;
    font-weight:bold;
    line-height:30px;
    margin:0;
}
h1 div {
    margin:0 0 10px;
}
h1 span {
    display:inline-block;
    background:#d52641;
    padding:15px;
}



                    <h1>
                        <div><span>We aim to exceed our</span></div>
                        <div><span>customers expectations</span></div>
                    </h1>


Hopefully, I kept my notes straight :slight_smile:

Hi

Thats great, yes your right about the <h1> tag and search engines. Thank you for all your help!

Hi Ronpat

I am having issues with the footer list you kindly helped me with.

Here is the updated link http://www.cre8tivesource.co.uk/test/about-test.htm

I need the margin or padding of the lists to match the orig example graphic I sent. I have tried but I cannot get this to be altered.

Also when you scale the example link down to say 800x600 it does not look good, is their a way I can display the content when scaled down into ‘blocks’

Hope the above makes sense!

Many Thanks

This demo code renders the same as your original graphic on my PC.

Comments highlight what each selector does and additional comments highlight relevant styles within each selector.

Reduce or eliminate the letter spacing and the width should be reducable to slightly narrower than 600px. You could do this gradually with media queries. Choice of font and font related styles affect the minimum width of each row. Your design is not intended to wrap, so you might want to apply a min-width to the to the page.

This is a slightly refined version of the technique that was suggested in post #2.


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
<!--
http://www.sitepoint.com/forums/showthread.php?1204989-Bootsrap-3-Inline-Full-Width-List-Problem
2014.04.11 18:44
mumford1
-->
    <title>menu styles</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <link href="styles/bootstrap.css" rel="stylesheet">
    <link href="styles/site.css" rel="stylesheet">
    <link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:400,300,300italic,400italic,600,600italic,700,700italic,200,200italic' rel='stylesheet' type='text/css'>
    <style type="text/css">

ul.nav-justified {
    list-style:none;
    [color=blue]font-size:0;   /* setting the font-size to zero eliminates space beneath each row. */[/color]
    text-align:justify;
    padding:0;
    margin:0 auto;
    [color=blue]width:80%;    /* adjust as needed.  If "100%", then omit. */[/color]
}

/* justifies the lines and adds space beneath the rows */
ul.nav-justified:after {
    content:'';
    display:inline-block;
    width:100%;
    height:3px;    /* space beneath rows */
}

/* colors words in the middle row red, if desired.  ...or you could just target a class. */
ul.nav-justified:nth-child(even) li:nth-child(odd) {color:red}

/* assigns a font-size and font styles to list items.  */
ul.nav-justified li {
    display:inline-block;
    width:auto;
    [color=blue]font-size:.8rem;    /* desired font-size should be applied here using a unit other than "em" or "percent". */[/color]
    [color=red]font-family:arial;         /* for this demo only. not expected to be copied to your working page */
    text-transform:uppercase;  /* for this demo only. not expected to be copied to your working page */
    letter-spacing:.5em;       /* for this demo only. not expected to be copied to your working page */[/color]
    padding:2px 1px 3px;
}

/* increases the size of the bullets */
ul.nav-justified li:nth-child(even) {
    font-size:1.2rem;
    line-height:.4;
    vertical-align:-.15rem;
}
    </style>
</head>
<body>

<div class="container"> <!-- START ROW 5 -->
    <div class="row clearfix">
        <div class="col-md-12 footer-services">
            <ul class="nav nav-justified">
                <li>Heating</li>
                <li>&bull;</li>
                <li>Cooling</li>
                <li>&bull;</li>
                <li>Ventilation</li>
                <li>&bull;</li>
                <li>Plumbing</li>
            </ul>
            <ul class="nav nav-justified">
                <li>Design</li>
                <li>&bull;</li>
                <li>Installation</li>
                <li>&bull;</li>
                <li>Service</li>
                <li>&bull;</li>
                <li>Maintenance</li>
                <li>&bull;</li>
                <li>Emergency Call Out</li>
            </ul>
            <ul class="nav nav-justified">
                <li>Boiler Replacements</li>
                <li>&bull;</li>
                <li>Electrics</li>
                <li>&bull;</li>
                <li>Renewable Energy</li>
                <li>&bull;</li>
                <li>Gas Safety</li>
            </ul>
        </div>
    </div>
</div> <!--END 3 ROW 5 -->
<hr />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/scripts.js"></script>
</body>
</html>


Hope this helps.

Many thanks, I will give it a go.