Creating a sleek design with bootstrap and rails: stationary top navigation bar, persistent footer at the bottom, and a central full-height content section

I have come across multiple threads discussing this topic, but I am struggling to identify where I am going wrong.

The website I am currently working on for testing purposes is located at:

My goal is to ensure that the navbar stays fixed at the top of the page, with the image-containing div covering the space above the fold. Following that, I want to display additional div(s) and the footer, which should always remain at the bottom of the page when there isn't enough content to fill the entire height.

Below is a snippet of my coding from application.html.erb:

<!DOCTYPE html>
  <html>
  
  <head>
    <title><%= full_title(yield(:title)) %></title>
    <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
    <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
    <%= csrf_meta_tags %>
    <%= render 'layouts/shim' %>
  </head>
  
  <body>
      <%= render 'layouts/menu' %>
      <% flash.each do |message_type, message| %>
        <div class="container alert alert-<%= message_type %>"><%= message %></div>
      <% end %>
      <%= yield %>
      <%= render 'layouts/footer' %>
  </body>
  
  <%= debug(params) if Rails.env.development? %>
  
  </html>
  

Next, here is the code snippet from home.html.erb:

<header>
      <div class="header-content">
          <div class="header-content-inner">
              <h1>This is TwitterDave</h1>
              <hr>
              <h2>
                A big THANK YOU to 
                <a href="http://www.railstutorial.org/" target="_blank">Ruby on Rails Tutorial</a>
                for making this possible ;)
              </h2>
              <%= link_to "Sign up now!", signup_path, class: "btn btn-primary btn-xl" %>
  
          </div>
      </div>
  </header>
  

This section showcases the code from the footer partial _footer.html.erb:

<footer class="footer">
        <div class="container">
            <copyright>
                &copy; Twitterdave <%= Time.now.year %>
            </copyright>
            <nav>
              <ul>
                <li><%= link_to "About",   about_path %></li>
                <li><%= link_to "Contact", contact_path %></li>
                <li><a href="http://news.railstutorial.org/">News</a></li>
              </ul>
            </nav>
        </div>
  </footer>
  

Lastly, we have the code snippet from the menu partial -menu.html.erb:

<nav class="navbar navbar-inverse navbar-fixed-top">
    <div class="container">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
          <span class="sr-only">Toggle navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
        <%= link_to "twitterdave", root_path, class: "navbar-brand", id: "logo" %>
      </div>

      <div id="navbar" class="collapse navbar-collapse">
        <ul class="nav navbar-nav navbar-right">
          <li><%= link_to "Home", root_path %></li>
          <li><%= link_to "Help", help_path %></li>
          
          <!-- User Authentication Handling -->
          
        </ul>
      </div><!--/.nav-collapse -->

    </div>
  </nav>
  

In addition, here are some relevant CSS styles:

@import "bootstrap-sprockets";
  @import "bootstrap";

  /* mixins, variables, etc. */

  $gray-medium-light: #eaeaea;

  @mixin box_sizing {
    -moz-box-sizing:    border-box;
    -webkit-box-sizing: border-box;
    box-sizing:         border-box;
  }
  
  /* universal */
  
  html {
    position: relative;
    min-height: 100%;
  } 
  
  body {
    margin-top: 51px;
    margin-bottom: 100px;
  }

  section {
    overflow: auto;
  }
  
    ...

  footer {
    ...
  }

  footer a {
    ...
  }

  footer copyright {
    ...
  }

  footer ul {
    ...
  }

  

That concludes my initial attempt at customizing Michael Hartl's Ruby on Rails tutorial's sample app... Any assistance or guidance would be greatly appreciated! :)

Answer №1

After trying different solutions, I finally managed to figure it out on my own. Here is the solution that others might find useful:

header {
    position: relative;
    width: 100%;
    height: calc(100vh - 151px); //footer = 100, topmenu = 50
    max-width: 100%;
    min-height: auto;
    text-align: center;
    color: #fff; 
    background-image: url(image-path('header.jpg'));
    background-position: center;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    background-size: cover;
    -o-background-size: cover;
    overflow-wrap: break-word;
    word-wrap: break-word;

}

By adding

height: calc(100vh - 151px); //footer = 100, topmenu = 50
to the existing header class, everything started working as expected.

Cheers :)

Answer №2

    <div class="header-wrapper">
  <div class="container">
   <nav class="navbar navbar-default navbar-fixed-top">
      <div class="container">
        <div class="header">
          <button type="button" class="menu-toggle collapsed" data-toggle="collapse" data-target="#menu" aria-expanded="false" aria-controls="menu">
            <span class="sr-only">Toggle menu</span>
            <span class="line"></span>
            <span class="line"></span>
            <span class="line"></span>
          </button>
          <a class="logo" href="#">Welcome to my website</a>
        </div>
        <div id="menu" class="menu-collapse collapse">
          <ul class="nav navbar-nav">
            <li class="active"><a href="#">Home</a></li>
            <li><a href="#about">About Me</a></li>
            <li><a href="#work">My Portfolio</a></li>
            <li><a href="#webdev">Web Development</a></li>
            <li><a href="#contact">Contact Me</a></li>
            </li>
          </ul>
        </div>
      </div>
    </nav>

  </div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having difficulty upgrading from BootStrap 3 to BootStrap 4

Need assistance updating from BootStrap 3 to BootStrap 4 on my local server. After trying to update, I ended up with a result that still reflects BootStrap 3. https://i.sstatic.net/Bs9H0.jpg Here's the code snippet I used for linking: <link rel=& ...

What is the best way to dynamically fill the content of a second input field when a selection in a dropdown menu triggers an onchange event?

Looking for a way to duplicate the value of a select input into a second input field using Javascript. Attempted to achieve this with an onchange event call, but encountering difficulties. What is the proper JavaScript code to populate the input field with ...

When attempting to access the submenu in Bootstrap 5 dropdown, it does not slide down as expected upon clicking

Why isn't the rest of the menu expanding downward when I select a submenu? The submenu is already selected, but it hides other items. How can I make it expand downwards? <!DOCTYPE html> <html lang="en"> <head> <meta charse ...

Create a table that excludes the content of the initial cell

I am seeking to update my table design. The desired look can be found here. Currently, my table looks like this: current table. The key difference I want to achieve is the removal of the first cell (positioned at 0;0) in the desired table design. Additio ...

Is it possible to change the CSS styling of a specific DIV class that contains nested anchor tags using jQuery?

The HTML: <div id="main_menu"> <a id="menu_item_articles" href="articles">articles</a> </div> The CSS: #main_menu { float: left; padding-top: 10px; vertical-align: middle; text-align: center; width: 500px; ...

When I adjust the window size, the media queries cause the responsive side menu to quickly show and hide

After creating a responsive side menu that automatically appears when resizing the browser window, I encountered an unexpected issue. The side menu seems to appear and disappear quickly without clicking on the designated button. This particular problem is ...

Using Styled Components to achieve full width for input tag in relation to its parent

I am working with an input field that has a specific width set. My goal is to increase the width of this input field to 100% by selecting it from its parent component. Is there a way to achieve this without passing an explicit width prop in the styled c ...

Looking for assistance with aligning UL elements in CSS using absolute positioning for a dropdown effect

I'm currently working on implementing a language switching feature on this website. The concept involves using a SPAN element that reveals a dropdown box (based on UL) containing a list of available languages when hovered over. Below is a preview of t ...

What could be the reason for the active class not being triggered by Bootstrap?

After making an Ajax call to a PHP file from jQuery, I am trying to loop through the information and format it within table rows and cells. Specifically, I want to use the <tr class="active"> class and the <tr><td> structure provided by B ...

Ensure that the CSS property has fully transitioned before verifying the change

Currently, I am working with Python webdriver and facing a challenge in making the system wait until the border color of a password field changes after clicking on a submit button. The transition happens from one color to another, and I have managed to ach ...

Is there a way for me to keep an image stationary on the page while allowing overlaying text to move?

Currently, I am exploring the process of coding a website that mimics the style of this particular webpage: . I am particularly interested in learning how to create a scrolling effect for text within a fixed area, while keeping the accompanying images st ...

The image within the element is being cropped despite having a higher z-index

On my page, I am dynamically generating a table using an API request. Each row in the table has an icon that, when hovered over by the user, displays an image associated with that item. However, I seem to have misunderstood how z-index functions, as I have ...

Retrieving the HTML Head Element from Internet Explorer's Document Object Model

For extracting the HTML body of a document, I am familiar with utilizing the IHTMLDocument2 interface by invoking the get_body member function. However, obtaining the head seems to be more challenging. Is there an alternative method since the IHTMLDocumen ...

Adjusting the properties of a <span> tag when hovering over a different element

Query: I am trying to dynamically change the color of the span element with classes glyphicon and glyphicon-play when the user hovers over the entire element. How can I achieve this? Recommendation: .whole:hover > span.glyphicon.glyphicon-play { c ...

Issues with the functionality of Angular 2 routerLink

Unable to navigate from the homepage to the login page by clicking on <a routerLink="/login">Login</a>. Despite reviewing tutorials and developer guides on Angular 2 website. Current code snippet: index.html: <html> <head> ...

What is the best method for arranging three DIV elements with a width of 33.333% on a single line, while also including a 10px margin on the right side of

When I apply a margin-right of 10px to the first and second child elements, and 0px to the third child element, the third child jumps to a new line. I can see that the double 10px margin-right is the issue here, but I'm not sure how to fix it. .al ...

The animations in fontawesome 6.2 are completely ineffective

I've been struggling to make a spinner icon spin on my webpage. I made sure to download the latest version of font awesome and created a simple HTML file to troubleshoot the issue. Take a look at the HTML code below: <!doctype html> <html la ...

Guide to altering the properties of child divs using JavaScript within the parent div

#va{ color:yellow; } #v{ color:pink; } <div id = "va"> <div id ="v">my name is </div> <div>khan</div> </div> After trying to use document.getelementbyid("va").style.color="yellow";, I found ...

What are the steps to create a table using divs and CSS?

Can someone guide me on how to create a table using divs, CSS, and proper XHTML formatting? <table width="100%" border="1"> <tr> <td style="width: 130px">1</td> <td align="center">2</t ...

Apply CSS styles by either passing them in through @Input or directly from an object property

In our main application, we utilize an RTF control that is standalone and generates CSS classes along with HTML using these classes. This content is loaded through an API. The generated output looks like this: .cs95E872D0{} .csCF6BBF71{font-weight:normal ...