htmlcsstwitter-bootstrapmobileresize

Site header navbar and footer wont go to 100% on mobile devices


I created this website http://fusioninfinite.com/DianeFH/ with the hope that it would display correctly on mobile devices. While it looks fine on my PC I have tested it on my IPod and the header, navbar, and footer background colors do not extend to the rest of the page when you scroll. I think it's a problem with the width being 100% but I am not sure

This is my HTML code I am using bootstrap:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="Diane Swanson&#039;s website, online gallery and blog">
    <meta name="author" content="Diane Swanson">
    <meta name="keywords" content="diane, swanson, Diane Swanson, artist, freehawk art, art, freehawk, watercolor, visual artist, American Women Artists, artist, painting, landscapes">
    <link rel="icon" href="../../favicon.ico">
    <link href='http://fonts.googleapis.com/css?family=Muli' rel='stylesheet' type='text/css'>
    <title>Diane Swanson - Home</title>

    <!-- Bootstrap core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="blog.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
    <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
    <script src="../../assets/js/ie-emulation-modes-warning.js"></script>

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>
    <div style="width:100%; background-color:#303030; class="blog-masthead">
    <div align="center" style="width:100%; height:120px; background-color:#0b0b3b;">
    <div style="width:740px; padding-top:40px;" align="left">
      <h1 style="font-size:45px; font-family: 'Muli', sans-serif; color:lightgrey;">Diane Swanson</h1>
      </div>
      </div>
      <div style="width:790px;" align="left" class="container">
        <nav class="blog-nav">
          <a class="blog-nav-item active" href="index.html">Home</a>
          <a class="blog-nav-item" href="about.php">About</a>
          <a class="blog-nav-item" href="exhibits.html">Current & Upcoming Exhibits</a>
          <a class="blog-nav-item" href="portraits.html">House Portraits</a>
          <a class="blog-nav-item" href="gallery.html">Gallery</a>
          <a class="blog-nav-item" href="wordpress/index.php">Blog</a>
        </nav>
      </div>
    </div>

    <div class="container">

    <div style="margin-top:20px;" align="center">
    <img src="images/homeheader.jpg">
    <br><br><br>
    <h2 style="float:left; color:#000066;"><strong>DIANE SWANSON</strong></h2>
    <h2 style="float:right; color:#000066; font-style: italic;">visual artist</h2>
    <br><br><br>
    <h4>Landscapes   —      Home/Building Portraits   —      Animal Portraits   —       Illustration</h4>
    <br><br><br>
    </div>

    </div><!-- /.container -->

    <div style="left:0; right:0;" class="blog-footer">
      <p>Website designed and hosted by <a href="http://fusioninfinite.com">FusionInfinite WebDesign and Hosting</a></p>
    </div>


    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/docs.min.js"></script>
  </body>
</html>

This is my CSS:

/*
 * Globals
 */

body {
  font-family: Georgia, "Times New Roman", Times, serif;
  color: #555;
}

h1, .h1,
h2, .h2,
h3, .h3,
h4, .h4,
h5, .h5,
h6, .h6 {
  margin-top: 0;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-weight: normal;
  color: #333;
}


/*
 * Override Bootstrap's default container.
 */

.container {
  width: 790px;
}


/*
 * Masthead for nav
 */

.blog-masthead {
  background-color: #428bca;
  -webkit-box-shadow: inset 0 -2px 5px rgba(0,0,0,.1);
          box-shadow: inset 0 -2px 5px rgba(0,0,0,.1);
}

/* Nav links */
.blog-nav-item {
  position: relative;
  display: inline-block;
  padding: 10px;
  font-weight: 500;
  color: #cdddeb;
}
.blog-nav-item:hover,
.blog-nav-item:focus {
  color: #fff;
  text-decoration: none;
}

/* Active state gets a caret at the bottom */
.blog-nav .active {
  color: #fff;
}
.blog-nav .active:after {
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 0;
  height: 0;
  margin-left: -5px;
  vertical-align: middle;
  content: " ";
  border-right: 5px solid transparent;
  border-bottom: 5px solid;
  border-left: 5px solid transparent;
}


/*
 * Blog name and description
 */

.blog-header {
  padding-top: 20px;
  padding-bottom: 20px;
}
.blog-title {
  margin-top: 30px;
  margin-bottom: 0;
  font-size: 60px;
  font-weight: normal;
}
.blog-description {
  font-size: 20px;
  color: #999;
}


/*
 * Main column and sidebar layout
 */

.blog-main {
  font-size: 18px;
  line-height: 1.5;
}

/* Sidebar modules for boxing content */
.sidebar-module {
  padding: 15px;
  margin: 0 -15px 15px;
}
.sidebar-module-inset {
  padding: 15px;
  background-color: #f5f5f5;
  border-radius: 4px;
}
.sidebar-module-inset p:last-child,
.sidebar-module-inset ul:last-child,
.sidebar-module-inset ol:last-child {
  margin-bottom: 0;
}



/* Pagination */
.pager {
  margin-bottom: 60px;
  text-align: left;
}
.pager > li > a {
  width: 140px;
  padding: 10px 20px;
  text-align: center;
  border-radius: 30px;
}


/*
 * Blog posts
 */

.blog-post {
  margin-bottom: 60px;
}
.blog-post-title {
  margin-bottom: 5px;
  font-size: 40px;
}
.blog-post-meta {
  margin-bottom: 20px;
  color: #999;
}


/*
 * Footer
 */

.blog-footer {
  padding: 40px 0;
  color: #999;
  text-align: center;
  background-color: #f9f9f9;
  border-top: 1px solid #e5e5e5;
}
.blog-footer p:last-child {
  margin-bottom: 0;
}

Solution

  • To make your website responsive, you are using Bootstrap, which is great, but you are using it incorrectly. By overwriting bootstrap's default CSS, it will only break it, as I said earlier. What you want to do is include your own DIVs or custom classes and apply the CSS to these.

    Speaking of CSS, I would recommend to avoid inline CSS, in the style attribute, and to regroup all your CSS in a single stylesheet. It will be easier for you to edit your website afterwards. In my example, I added a lot of custom classes.

    Also, don't use BR tag, except to break a line for text inside a P tag. In order to define spaces around an element, use MARGIN or PADDING

    Next, I noticed that you compressed your website's content, or content container in this case to 790px. Nowadays, most screen resolution tends to be between 1920px and 1280px, excluding mobile and tablet resolution of course. By compressing, you are: 1) breaking bootstrap, 2) containing your content to the middle of the page and therefore leaving huge empty gaps to each sides for users with higher resolution screens.

    Using bootstrap is great, but using it efficiently is better. Don't be afraid to use bootstrap to it's full potential. When looking at my take on the Html, notice how I abused DIV containers and added all of boostrap's own row and columns DIVs. When resizing the browser window, you will notice that all elements will follow and place itself on top of each other when there is no more room for elements to be side by side.

    In the stylesheet, I added a bit of Media Queries. What this do is simple, it checks if the browser's width reached the threshold I specified. If it does, the I can target specific elements and apply additional CSS style. If the browser's width returns to normal, the additional CSS is removed.

    For some reason unknown, I cannot create a Bootply example for you at the moment. But you can try to test it by adding my code and click Play to see how it looks and react to resizing. Bootply Website

    If you have any questions, don't hesitate

    Here is the complete html:

    <div class="header">
        <div class="container name-container">
            <div class="row">
                <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                    <h1>Diane Swanson</h1>
                </div>
            </div>
        </div>
        <div class="container">
            <div class="row">
                <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                    <nav class="blog-nav">
                        <ul>
                            <li><a class="blog-nav-item active" href="#">Home</a></li>
                             <li><a class="blog-nav-item" href="#">About</a></li>
                             <li><a class="blog-nav-item" href="#">Current & Upcoming Exhibits</a></li>
                             <li><a class="blog-nav-item" href="#">House Portraits</a></li>
                             <li><a class="blog-nav-item" href="#">Gallery</a></li>
                             <li><a class="blog-nav-item" href="#">Blog</a></li>
                        </ul>
                    </nav>
                </div>
            </div>
        </div>
    </div>
    <div class="content-container">
        <div class="container">
            <div class="row">
                <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                    <img class="blog-img" src="http://fusioninfinite.com/DianeFH/images/homeheader.jpg" alt="">
                </div>
            </div>
        </div>
        <div class="container middle-container">
            <div class="row">
                <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 leftbox">
                    <h2>Diane Swanson</h2>
                </div>
                <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 rightbox">
                    <h2>Visual artist</h2>
                </div>
                <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 description-container">
                    <h4>Landscapes   —      Home/Building Portraits   —      Animal Portraits   —       Illustration</h4>
                </div>
            </div>
        </div>
    </div>
    <div class="blog-footer">
        <p>Website designed and hosted by <a href="http://fusioninfinite.com">FusionInfinite WebDesign and Hosting</a></p>
    </div>
    

    Here is the CSS:

    .header{
        width: 100%;
        background-color: #303030;
    }
    
    .header h1{
        font-size: 45px;
        font-family: 'Muli', sans-serif;
        color: lightgrey;
        margin-left: 8px;
    }
    
    .name-container{
        padding-top: 25px;
    }
    
    .blog-nav ul{
        margin: 0;
        padding: 0;
    }
    
    .blog-nav li{
        float: left;
    }
    
    .blog-nav-item{
        position: relative;
        display: inline-block;
        padding: 10px;
        font-weight: 500;
        color: #cdddeb;
        text-decoration: none;
        font-family: Georgia, "Times New Roman", Times, serif;
    }
    
    .blog-nav-item:hover{
        text-decoration: none;
        color: #FFF;
    }
    
    .active{
        color: #fff;
    }
    
    .blog-nav .active:after {
        position: absolute;
        bottom: 0;
        left: 50%;
        width: 0;
        height: 0;
        margin-left: -5px;
        vertical-align: middle;
        content: " ";
        border-right: 5px solid transparent;
        border-bottom: 5px solid;
        border-left: 5px solid transparent;
    }
    
    .blog-img{
        max-width: 100%;
        width: 1170px;
    }
    
    .content-container{
        padding-top: 25px;
        padding-bottom: 65px;
    }
    
    .middle-container{
        padding-top: 10px;  
    }
    
    .description-container{
        text-align: center;
        padding-top: 10px;  
    }
    
    .leftbox h2{
        color: #000066;
        font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
        font-weight: 700;
        text-transform: uppercase;
    }
    
    .rightbox h2{
        float: right;
        color: #000066;
        font-style: italic;
    }
    
    .blog-footer{
        padding: 40px 0;
        color: #999;
        text-align: center;
        background-color: #f9f9f9;
        border-top: 1px solid #e5e5e5;
    }
    
    /*MEDIA QUERIES*/
    @media only screen and (max-width:770px) {
        .rightbox h2{
            float: none;
        }
    }
    
    @media only screen and (max-width:585px) {
        .blog-nav li {
            float: none;
        }
    
        .blog-nav .active:after{
            display: none;
        }
    }