The breadth of the container

I am facing challenges in determining the setup of the content width with a fixed side panel. I want the side panel to maintain a set width regardless of the screen size, while the rest of the window accommodates the navbar, content, and footer. I have been attempting to achieve this using bootstrap grid and flex properties, but I always find myself needing to calculate the width of the content div in the end. One approach that has worked for me so far is:

<div class="container-fluid main_page">
        <div class="row">
            <div class="col-md-1">
                {% include 'includes/sidebar.html' %}
            </div>
            <div class="col">
                <div class="row">
                    <div class="col-md-12">
                        {% include 'includes/navigation.html' %}
                    </div>
                </div>
                <div class="row content">
                    {% block content %}{% endblock content %}
                </div>
                <div class="row">
                    <div class="col-md-12">
                        {% include 'includes/footer.html' %}
                    </div>
                </div>
            </div>
        </div>
    </div>

While this setup works fine, my footer ends up stuck right under the content block. I am trying to either ensure that the content block always has a minimum height of 100% with:

min-height: 100%;
height: 100%;

However, this solution doesn't seem to have any effect. Alternatively, I can "fix" the footer at the bottom using:

position: absolute;
bottom: 0;

But this causes the footer to be cut off and requires me to calculate the width. Simply using width: 100% makes the content extend beyond the screen due to the side panel. So I need to implement something like: width: 100%-$sidepanel-width where the side panel width is 70px; but this requires consistent units, such as: width: 1330px-$sidepanel-width or

width: 100%- $sidepanel-width-in-%

Neither of these solutions is working for me as the window width needs to be dynamic while the side panel remains fixed. I am looking for a simpler way to achieve this. What approach should I take to resolve this issue?

Answer №1

I believe I have a solution to your issue that involves utilizing the grid property along with min-height: 100vh.

.main_page{
  display:grid;
  grid-template-columns:70px repeat(2,minmax(0, 1fr));
  grid-template-rows:1fr 5fr 1fr;
  grid-template-areas:
    "s n n"
    "s c c"
    "s f f";
  min-height:100vh;
}
.sidebar{
  grid-area:s;
  background:red;
}
.navbar{
  grid-area:n;
  background:blue;
}
.content{
  grid-area:c;
  background:green;
}
.footer{
  grid-area:f;
  background:gold;
}
<div class="main_page">
  <div class="sidebar">side bar
  </div>
      <div class="navbar">navbar
    </div>
    <div class="content">content
    </div>
      <div class="footer">footer
      </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

Achieving the perfect alignment for expandable divs next to a consistently centered element using CSS

On my page, I want to ensure that the logo is always perfectly centered both horizontally and vertically when the page loads without any interactions. To achieve this, I used simple margin properties: margin: auto; position: absolute; top: 0; bottom: 0; ...

SB Admin 2 menu with multiple levels does not collapse as expected

I'm in the process of integrating the menu from the sb admin 2 template into my Ruby on Rails application: As I gradually added components to test functionality, I successfully implemented the top and side nav bars. However, I encountered an issue wi ...

What is the best way to display numerical data within an inline list format?

Here is a list I have: <ol> <li>Login</li> <li>Address</li> <li>Shipping</li> </ol> The numbers in the list display correctly as decimals. However, when I change the <li> tag to inline or ...

JavaScript scrollable selection menu with a favorite option button

I am looking to enhance a standard select element by adding a favorite button that can be toggled on and off for each option. Utilizing Bootstrap for styling, I want to create a user interface element that allows for smooth scrolling through the options an ...

What location is most ideal for incorporating JavaScript/Ajax within a document?

Sorry for the seemingly simple question, but I would appreciate some clarification from the experts. When it comes to the three options of placing JavaScript - head, $(document).ready, or body, which would be the optimal location for ajax that heavily rel ...

What is the method for showcasing an h1 heading and an unordered list link side by

Can you help me align my h1 and ul elements on the same line in my header? I want to have my logo and navigation links next to each other (This extra text is just filler) Below is the code snippet: HTML: <div id="header"> <h1>Logo</h1> ...

Creating an HTML table with multiple styled images is a simple process that can greatly enhance the

I am experiencing difficulty with arranging images The primary goal is to achieve this layout: ---------------———————- Table header ----------------—————— | Img1 | | img4 | -------| Img3 |--————— | Img2 | ...

Image expansion

I have a container element div that holds various content of unknown length. How can I add a background image that extends the entire length of the container since background-images do not stretch? I attempted to use a separate div with an img tag inside. ...

Creating dynamic DIV elements in an AngularJS file using data retrieved from a Sql server

I need to dynamically add elements based on data retrieved from a MSSQL server in the specified area: <div id="ApplicationForm" class="tabcontent" style="display:none;"> <div class="tab_section"> ...

The function in jQuery that can be used to hide a <div> when clicked

I am facing a problem with my jQuery code that is supposed to remove/hide a specific div. Despite checking various examples, I can't seem to make it work properly. This issue arises in the context of jQuery on Drupal 7. The live site where this proble ...

Struggling to get JavaScript to successfully load a .txt file in order to load various links

I created a cool feature that takes users to a random link, but I currently have a large list of links and wanted to find a way for JavaScript to read them from a text file. The code I have tried so far is not working, and I have experimented with other s ...

In the production mode, Nuxt styles may not be properly applied

After working on this project for about four months, everything seems fine in the development version. However, once I build the project and upload it to the server, some of my styles are not applied. For more information, I have imported styles both in c ...

Positioning Multi-level Drop Down Div in Javascript - How to do it efficiently?

I'm currently working on a horizontal menu using CSS and JavaScript with multiple levels. I've implemented a toggle function to show the submenu container, but it's causing the links below it to be pushed down. Is there a way to make the dis ...

Deactivate a feature by clicking on it

HERE IS WHERE YOU CAN VIEW MY JSFIDDLE On my website, I have a main home page with a smooth scroll wheel script implemented. Additionally, I have a 'about' div that becomes visible when a button is clicked. The issue I am facing is that I want t ...

Determine the difference between the starting and ending dates in AngularJS

In my project, I am trying to implement a feature where an error message should be displayed next to the control if the "ToDate" is before the "FromDate". Currently, I have set a minimum date which successfully disables the selection of ToDate before FromD ...

Is it possible to align the last item in a MUI stack to the bottom?

https://i.stack.imgur.com/IsutM.png Currently, I am working on a modal component using MUI's Grid. My goal is to position the Button at the bottom of the modal. const styles = { modalBox: { position: 'absolute', top: &ap ...

Image broken on default bootstrap navbar

On my computer where I am developing a Ruby on Rails app, I have a relative link to an image. To customize the style, I am using Bootstrap and have used their code to source the image for the top left brand placement. You can view the Bootstrap link here. ...

If the text is too wide for the parent div width, wrap it in a child div

<div class='jfmfs-friend' id='123'> <input type='checkbox'/> <img src='id.jpg'/> <div class='friend-name'>Himanshu Yadav</div> </div> I am looking to modify the st ...

Experience the illusion of three-dimensional depth with SVG light and shadow effects

I am trying to achieve a 3D effect on an SVG by adding a light source at the top and left border, and a shadow on the bottom and right border. Here is an example: #div1 { background: #ddd; } #div1, #div2, #div3 { width: 100px; height: 100px; po ...

Alignment of elements in a list at the bottom

I am looking to create multi-level tabs using <li> that grow from bottom to top. Here is the current code I have: div{ width: 200px; border: 1px solid black; } ul{ margin: 0px; padding: 0px; } li{ margin: 2px; width: 20px; display: ...