Creating a dynamic and modern website header using Bootstrap 4.0, featuring a responsive design with an eye-catching image

Currently, I am in the process of constructing a dynamic webpage using Bootstrap 4. This page includes a header section with the client's logo, their name, and a responsive navbar. The challenge lies in making these elements adapt to various screen sizes seamlessly - the image should resize accordingly, and the navbar should collapse on smaller screens.

Next, I aim to make the body of the page responsive as well. Essentially, I want it to occupy the remaining height of the screen, utilizing a scrollbar when needed to display all content.
Despite my efforts, I'm struggling to span this section over the entire height of the page effectively. It either appears too large on larger screens, fits well on mobile devices but not on larger screens, or has inadequate height on mobile devices despite looking fine on large screens.

This is an outline of the webpage structure:

<!DOCTYPE html>
<html lang="de" style="height:100%">

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  <title>Client Name</title>
</head>

<body class="main" style="height:100%">
  <div class="container">
    <div class="text-center">
    <!-- Client image goes here -->
    <h1 style="display:inline;margin-left:0.6em;color:#8b7d7b">Client Name</h1>
   </div>
  </div>
  <nav class="navbar navbar-expand-lg navbar-light" style="background-color:#e0eee0">
    <button class="navbar-toggler collapsed" type="button" data-toggle="collapse" data-target="#mainnavbar" aria-controls="mainnavbar" aria-expanded="false" aria-label="Toggle Navigation">
  <span class="navbar-toggler-icon"></span>
</button>
<div id="mainnavbar" class="navbar-collapse collapse justify-content-md-center">
  <ul class="navbar-nav">
    <li class="nav-item nav-link active">Page A</li>
  </ul>
</div>
</nav>
<div class="container" style="height:70vh">
<div class="row" style="height:100%">
  <!-- Main body of page -->
  <div class="col-sm-1 col-md-9" style="height:100%">
    <p class="col-scrol">
      <!-- Main part of the page. Content should have full height and scroll vertically if necessary -->
    </p>
  </div>
  <!-- Comment section (scrolling) -->
  <div class="d-none d-md-block col-md-3 comment-section">
        <!-- Comment section at the left hand side of the page -->      
  </div>
 </div>
 </div>
</body>

</html>

To see the complete webpage, you can check out this Plunker link:
https://plnkr.co/edit/GQHoephQyx3hoejgkT4k?p=preview

What would be the appropriate approach using Bootstrap 4.0 to achieve the desired design, ensuring that the content adapts to the available space once the image adjusts based on the screen size?

EDIT for clarification:
The main requirement is for the content itself to possess a scrollbar when necessary, rather than scrolling the entire page. Thus, the header displaying the image and menu bar should always remain visible, while the subsequent content area should contain a scroll feature for vertical navigation.

Answer №1

To ensure the content area fills the height of its parent container (in this case, the body), avoid setting specific heights and instead utilize flexbox.

body {
    display:flex;
    flex-direction:column;
}

.flex-fill {
    flex: 1 1 auto;
}

.flex-shrink {
    flex-shrink: 0;
}

Visit this link for a live example.

Please note: The flex-fill utility class will be part of the upcoming Bootstrap 4.2 release: Learn more here.


For similar queries, check out:
How to make nested row in Bootstrap 4 fill parent with viewport height using flex-grow
Achieving navbar and content to fill height using Bootstrap 4 flexbox
Creating a page-wide header bar above navbar in Bootstrap 4

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

Firefox browser does not display flashing titles for tabs

Every second, I want to display "New message..." in the title when the browser tab is inactive or the user is in another tab. Here's the code I used: <script> var mytimer; function log() { document.title = document.title == "" ...

html text alignment in the center

Is there a way to align text in the center without shifting the starting position of the first letter? before text 1 text text text 2 text text after ...

After loading ajax content onto the page, the scroll bars fail to appear

I am currently constructing a website that loads page content through ajax. Everything seems to be functioning perfectly, except for a peculiar issue I have encountered in Chrome and Safari. Surprisingly, it is working flawlessly in IE! The problem lies i ...

Turn off the automatic resizing of Internet Explorer 11 to fit the width of the viewport - IE11

Is there a way to stop Internet Explorer 11 from automatically zooming to fit the viewport width? I need the browser to respect my max-width rule and not scale the content to fill the entire width of the viewport on its own. This issue is happening in IE ...

Freemarker substitute & and &ampersand;

I am facing an issue with Freemarker. I need to eliminate all the special characters from this sentence as well as from similar sentences in the future: BLA BLA RANDOM &, RANDOM BLA In particular, I want to remove the & character. The platform ...

The battle between Hover, Focus, and Blur modes intensifies

My goal is to implement 4 different effects on an element: When hovering over the element. When moving away from the element. When focusing on the element. When blurred. However, I'm encountering a conflict where when I focus on the element, the ...

Displaying images in Ionic from a JSON URL source

I am having trouble getting an image from a JSON to display on an Ionic card. Although I can see the JSON response in the console log, the image is not showing up on the card, leaving it blank. It seems like I'm making a mistake in the HTML code. Any ...

Elevate Your Flipclock.js

I am currently working on a website that utilizes flipclock.js, but I am facing some challenges in enlarging it to occupy more space on the page. Is there anyone who knows how to upscale or increase its size? ...

Discover the value of the textbox within a gridview row that has been checked using Jquery

I'm working with a Gridview that has checkbox and textbox columns. I need to figure out how to retrieve the value of the textbox associated with the checked row. var checkCheckBox = $("#<%=GrdV.ClientID %> [id*=chkOrder]"); $(checkCheckBox).cli ...

JavaScript: Locate the HTML Attribute that Matches an ID

If you want to use just JavaScript, without relying on libraries like JQuery, how can you retrieve the data attribute associated with a specific Id? For example: <div id="id-test" data-qa="data-qa-test"> </div> Input: &quo ...

Minimize the number of HTTP requests by including CSS and JS files in PHP

I've been considering a method to reduce the number of HTTP requests made when loading a page by minimizing the amount of downloaded files, while still keeping separate files on the server. The thought process is as follows: <!DOCTYPE html> &l ...

Show several popovers concurrently by hovering over text utilizing Bootstrap 3's popover feature

Is there a way to display multiple popovers at once when hovering over text, similar to the example provided in this link? I attempted the following method, but it wasn't successful. <div class="row"> <div class="col-md-12"><br/&g ...

Unlimited image rotation with JQuery

I'm currently working on a project where I have a series of images that are moving left or right using the animate() function. My goal is to create a loop so that when the user clicks "next", the last image transitions to the first position seamlessly ...

Avoiding the collapse of the Bootstrap 4 navbar

Having trouble with the navbar collapsing on itself? The issue seems to occur around 1280px window size, but works fine when the window is wider or narrower. https://www.bootply.com/AcsaaqReAL .navbar-custom { background-color: #333333; border- ...

Tips on resizing images in card groups with bootstrap 4?

Hey there! I've come across an issue with my code that was initially working perfectly. The images I'm using have different resolutions, causing the card images to display in various sizes. Is there a way to implement image scaling to ensure all ...

the label remains grounded even as the browser autocompletes passwords with the password manager

https://i.stack.imgur.com/vJMyg.png I noticed that the password label on my login form does not float when the browser's password manager auto-completes. Can someone help me fix this issue? Attached is an image for reference. /* login form ...

Execute only HTML code (PHP)

Here I come with a query regarding a project; Let me explain it as clearly as possible: I have a text area where users can input any content they desire. The issue arises when someone tries to inject malicious code (such as js xss, for instance). Initiall ...

Creating an animated CSS growth effect using inline SVG

I'm trying to make these circuits look like they are running downwards. I have the right movement, but I can't seem to start them at their actual size, causing them to appear skewed at the beginning of the animation and then scaling to full size ...

How can I create dynamic tabs using Tailwind CSS?

I am looking to create an animated tab using React and Tailwind CSS. Here is the code I have so far: import React from 'react' import clsx from 'clsx' export const Modal = () => { const [theme, setTheme] = React.useState<' ...

Checking the opacity with an if/else statement, then adding a class without removing the existing class

This function is designed to check the opacity of the header, which fades out as a user scrolls down. If the opacity is less than 1, it disables clickability by adding the class "headerclickoff". However, there seems to be an issue with removing the clas ...