Adding margin causes Bootstrap 5 column to surpass 100vh height limit

I am experimenting with Bootstrap 5 on a simple webpage that contains one row with two columns. The left column is working correctly, but the right column is causing some issues. I want the webpage to be full-screen without any scrolling. However, whenever I add margin to an element inside the right column, the entire column's height increases and goes beyond 100vh/100%. Specifically, I want the content-right-inner class to have a margin of 50px all around. Deleting the min-height property causes all items to move to the top. How can I achieve a full-screen size with margins?

Here is the code snippet:

*, 
*:before, 
*:after {
  margin: 0px;
  padding: 0px;
  box-sizing: border-box;
}

body {
  font-family: Arial, sans-serif;
  line-height: 1.7;
  font-size: 1.6rem;
  background-color: #fff;
  color: #000;
}


h1, h2, h3, h4, h5, h6, p {
  margin: 0px;
}

button, 
input {
  overflow: visible;
}

button, 
input, 
optgroup, 
select, 
textarea {
  margin: 0;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
}

.row>* {
  padding-right: 0; 
  padding-left: 0; 
}

.main {
  background-color: green;
  max-height: 100vh;
}


.content-left{
  height: 100vh;
  padding: 0;
  color: #fff;
  background-color: red;
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: center;
}


.content-right{
  background: blue;
}
.content-right-inner{
  margin: 50px;
  position: relative;
  min-height: 100vh;
}


.logo p{
  font-family: Lato-Light;
  font-size: 1.5rem;
  color: #F7A14C;
  font-weight: 600;
}

.main-content{
  position: absolute;
  left: 0;
  top: 50%;
  bottom: auto;
  -webkit-transform: translateY(-50%);
  -moz-transform: translateY(-50%);
  -ms-transform: translateY(-50%);
  transform: translateY(-50%);
}

.social-box{
  margin: 0 10px 0px 15px;
  float: left;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/css/bootstrap.min.css" rel="stylesheet"/>
<section class="main">
        <div class="container-fluid position-relative h-auto p-0 overflow-hidden">
            <div class="row">

                <section class="content-left col-xs-12 col-lg-6">
                    <div class="inner-container">
                  <p>Boom Boom</p>
                    </div>
                </section>

                <section class="content-right col-xs-12 col-lg-6">
                    <div class="content-right-inner">
                        <div class="logo text-center">
                            <p>test</p>
                        </div>

                        <div class="main-content">
                            <h1>Lorem Ipsum!</h1>
                            <p>Lorem Ipsum Lorem Ipsum Lorem Ipsum.</p>
                            <p>Lorem Ipsumsdfafafafafa!</p>
                            <button>Lorem Ip</button>
                        </div>

                        <div class="social-icons">
                            <div class="social-box">
                                <i class="fab fa-facebook-f"></i>
                            </div>

                            <div class="social-box">
                                <i class="fab fa-twitter"></i>
                            </div>

                            <div class="social-box">
                                <i class="fab fa-linkedin-in"></i>
                            </div>

                            <div class="social-box">
                                <i class="fab fa-instagram"></i>
                            </div>
                        </div>
                    </div>
                </section>

            </div>
        </div>
    </section>

Answer №1

After troubleshooting the issue, I discovered a solution. By adding margin all around and specifically at the bottom, the container exceeded its designated height of 100vh. To rectify this, I utilized calc() within the styling of .content-right-inner.

Below is the revised code:

.content-right-inner{
  position: relative;
  margin: 50px;
  height: 95vh;
  height: calc(100vh - 100px);
} 

It appears that using calc() effectively subtracts the extra height caused by a 50px margin.

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

Why do my Wix-hosted images appear fine on desktop but not on mobile? What steps should be taken to correct this issue?

My website is finally live! I included several links to images hosted on various websites. Everything looks great on desktop, but when viewed on mobile, all the images hosted on Wix are not displaying properly. Instead, a text box appears saying "respons ...

Utilizing CSS for modifying spacing within a span element

I am facing a challenge with displaying a full name (firstName lastName) on a webpage. Within my JSP file, the code snippet looks like this: <span> <c:if test="${someCondition1}"> <c:out value="${firstName}"> </c:if&g ...

Aligning a bootstrap button group at the center of a container

Looking for suggestions on how to center a Bootstrap button group (btn-group) within an element? For instance, consider the following structure: <div id='toolbar'> <div class="btn-group"> <button type="button" class="b ...

SOLVED: How to utilize CSS to confine scrollbars within nested div elements

As a novice in web programming, I am currently working on a userscript to add hotkeys to a website. I am using Firefox on Linux for this project, focusing solely on desktop functionality. Right now, my main focus is on enhancing the pop-up help view, which ...

Email Embedder - Incorporating HTML source code into email communications

I've encountered an issue where the CDNs (Bootstrap and FontAwesome) do not work when I embed my HTML source code into an email. Despite using inline styling throughout, the receiver still faces this problem. Any insights on why the CDNs are failing t ...

Tips for switching the status of each item as I navigate the page with the tab key

I am facing an issue with my list of items that have hidden content appearing on hover. I want to achieve the same functionality while tabbing through my page, but currently, all hidden content appears at once. Check out a live example of my code here jQ ...

What is the simplest method to create a scroller for engaging narratives?

I am in the process of creating a static but responsive storytelling website using HTML. My objective is to create an effect similar to this: https://i.stack.imgur.com/zIEpU.gif The idea is to have text on the left and a *.jpg image fixed on the right. As ...

Using a comma as a decimal separator for input is not permitted when working with angular/typescript/html

I am facing an issue with my Angular frontend where I have numerous html input fields that trigger calculations upon typing. <input type="text" [(ngModel)]="myModel.myAttribute" (input)="calculate()"> The problem arise ...

The gap between list items(`<li>`s)

Feeling a bit perplexed here. I'm working on creating a page to showcase images. My goal is to have 5 images displayed per row, with maximum spacing when the window is at its widest (~950 px). However, as the window size decreases, I want the images t ...

Dynamically resizable overlapping divs in CSS

Encountering an issue with a div element on a webpage. When resizing the browser page in Chrome, the div overlaps other elements and part of it is hidden. However, in IE, the height:auto property behaves as expected without any overlapping. I have attempte ...

Simple steps to add a click event listener to every element within a div

I need to assign a click handler to multiple elements and perform different actions based on which one is clicked. To illustrate, I can create an alert displaying the class of the button that was clicked. The elements I am working with have a similar str ...

Activating the first item in a custom menu in WordPress

I'm trying to make the first custom menu item active by adding an "active" class. Can anyone help me achieve this? Here is the HTML code: <nav class="secondmenu"> <div class="menu-captain-crew-container"> <ul id="menu-capta ...

What is the best way to display a new line when printing a string as <pre> in HTML without using ` `

I receive a text file from the PHP server that has the following content: "File version: 5\n\nstart: 1410355285955(2014/09/10 11:58:05.955)\nend: 141090402750(2014/09/10 12:00:02.750)\nUEID: 301660031\nCNC: 1181 ...

What are some best practices for integrating CSS grid layouts with React for optimal results?

My current project involves developing a Single Page Application using ReactJs and CSS grid layouts for styling components. However, I've encountered an issue where the two technologies do not seamlessly integrate: CSS grid layouts are typically appli ...

Received an unexpected GET request while attempting to modify an HTML attribute

After clicking a button in my HTML file, a function is called from a separate file. Here is the code for that function: function getRandomVideoLink(){ //AJAX request to /random-video console.log("ajax request"); var xhttp = new XMLHttpRequest( ...

Navigational dropdown menu in Bootstrap

I'm a bit rusty with Bootstrap and I'm struggling to make my NavBar dropdown toggle. I've gone through all the documentation and forums available but can't seem to figure it out. Any ideas on what I might be missing? <nav class=" ...

Is it possible to remove htmlescape from the custom options in Magento? Can you specify which file showcases the custom

Looking to incorporate HTML into custom option labels for products on my Magento store. Unfortunately, Magento does not parse HTML by default when it is placed in the custom options interface. I suspect there may be a line like "$this->htmlEscape()" wit ...

Exploring the inner workings of AngularJS SEO in HTML5 mode: Seeking a deeper understanding of this hidden functionality

There are plenty of resources available for incorporating SEO-friendly AngularJS applications, but despite going through them multiple times, I still have some confusion, especially regarding the difference between hashbang and HTML5 mode: In hashbang (# ...

Interacting with PHP through JavaScript function calls

I am facing some frustration with my website due to an issue involving PHP. When I retrieve data from a PHP file, it returns a JSON list like this: {"Data":{"Recipes":{"Recipe_5":{"ID":"5","TITLE":"Spaghetti Bolognese"},"Recipe_7":{"ID":"7","TITLE":"Wurst ...

Problems with scrolling in the navigation bar, main content area, and footer

The challenge Encountering a scrolling anomaly with the Navigation Bar, Body, and Footer while utilizing Bootstrap 4. Everything appears to function smoothly on the desktop view. The glitch arises when I reduce the viewport size. The body fails to stay in ...