When I try to set both my banner and navbar to width:100%, I notice that they end up having slightly varying lengths. What could

I've been working on a personal project that I'm really enjoying, but I noticed that my bootstrap 4 navbar and banner have slightly different lengths, causing a slight horizontal scroll. Despite having hidden overflow in my banner and using percentage values for width properties, the issue persists. Initially, I suspected the left padding of my top_header class to be the culprit, but changing it to a percentage value didn't solve the problem. Even removing it altogether didn't help. Can someone please assist me in resolving this issue?

Check out snippets of my HTML/CSS below:

@font-face {
  font-family: Montserrat-Regular;
  src: url("Montserrat-Regular.ttf");
}

#my_banner {
  background-image: url('banner.jpg');
  "
 padding-bottom: 100px;
  overflow: hidden;
  width: 100%;
  max-width: 100%;
}

#banner_chibi {
  width: 50%;
  padding-left: 40px;
}

.navbar {
  margin-bottom: 0;
  width: 100%;
}

.navbar,
.dropdown-menu {
  background: #e5e5e5 !important;
  border: 0;
}

.navbar li a {
  color: #7e7e7e;
}

#top_header {
  font-family: Montserrat-Regular;
  color: black;
  font-size: 20px;
  padding-left: 20px;
  padding-right: 30px;
}

#red {
  color: #cd2d3a;
}

#blue {
  color: #0047a0;
}

#main_content {
  margin-top: 4%;
}

.left_card {
  width: 20%;
  height: 400px;
  margin-left: 4%;
  position: fixed;
}

.right_card {
  width: 90%;
  margin-left: 5%;
}

#card_1 {
  position: relative;
  height: 1000%;
  top: 20%;
}

html,
body {
  height: 100%;
}

body {
  background: #5e5e5e;
  overflow-x:
}
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Bootstrap 101 Template</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" />
<!--[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]-->

<!-- Banner -->
<div id="my_banner" class="row">
  <div class="col-md-4">
    <img id="banner_chibi" src="cute_scholar.png">
  </div>
</div>
<!--Navbar -->
<nav class="navbar navbar-expand-lg navbar-default">
  <a><span id = "top_header"><span id = "red">Step</span> by <span id = "blue">Step</span> Korean</span></a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item dropdown">
        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Browse
</a>
        <div class="dropdown-menu" aria-labelledby="navbarDropdown">
          <a class="dropdown-item" href="#">Main Lesson Catalog</a>
          <a class="dropdown-item" href="#">Phonetics Study</a>
          <a class="dropdown-item" href="#">Vocab</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="#">Test Yourself</a>
        </div>
      </li>
    </ul>
  </div>
</nav>

<!-- Main Body Content -->

<div class="row" id="main_content">
  <div class="col-md-3">
    <div class="card left_card">
      <div class="card-body">
        Placeholder text.
      </div>
    </div>
  </div>
  <div class="col-md-8">
    <div class="card right_card">
      <div class="card-body">
        Placeholder text.
      </div>
    </div>
    <div class="card right_card" id="card_1">
      <div class="card-body">
        Placeholder text.
      </div>
    </div>
  </div>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.0/js/bootstrap.min.js"></script>
</body>

If you want to see the visual problem I'm facing (the black area is not part of the website), check it out here: https://i.sstatic.net/CxaGF.jpg. Your help solving this issue would be greatly appreciated. Feel free to point out any bad coding habits as well.

Answer №1

Apply the 'no-gutters' class to the row div.

<div id="my_banner" class="row no-gutters">

<div class="row no-gutters" id="main_content">

@font-face {
  font-family: Montserrat-Regular;
  src: url("Montserrat-Regular.ttf");
}

#my_banner {
  background-image: url('banner.jpg');
  "
 padding-bottom: 100px;
  overflow: hidden;
  width: 100%;
  max-width: 100%;
}

#banner_chibi {
  width: 50%;
  padding-left: 40px;
}

.navbar {
  margin-bottom: 0;
  width: 100%;
}

.navbar,
.dropdown-menu {
  background: #e5e5e5 !important;
  border: 0;
}

.navbar li a {
  color: #7e7e7e;
}

#top_header {
  font-family: Montserrat-Regular;
  color: black;
  font-size: 20px;
  padding-left: 20px;
  padding-right: 30px;
}

#red {
  color: #cd2d3a;
}

#blue {
  color: #0047a0;
}

#main_content {
  margin-top: 4%;
}

.left_card {
  width: 20%;
  height: 400px;
  margin-left: 4%;
  position: fixed;
}

.right_card {
  width: 90%;
  margin-left: 5%;
}

#card_1 {
  position: relative;
  height: 1000%;
  top: 20%;
}

html,
body {
  height: 100%;
}

body {
  background: #5e5e5e;
  overflow-x:
}
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Bootstrap 101 Template</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" />
<!--[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]-->

<!-- Banner -->
<div id="my_banner" class="row no-gutters">
  <div class="col-md-4">
    <img id="banner_chibi" src="cute_scholar.png">
  </div>
</div>
<!--Navbar -->
<nav class="navbar navbar-expand-lg navbar-default">
  <a><span id = "top_header"><span id = "red">Step</span> by <span id = "blue">Step</span> Korean</span></a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav mr-auto">
      <!--<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li> -->
      <li class="nav-item dropdown">
        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Browse
</a>
        <div class="dropdown-menu" aria-labelledby="navbarDropdown">
          <a class="dropdown-item" href="#">Main Lesson Catalog</a>
          <a class="dropdown-item" href="#">Phonetics Study</a>
          <a class="dropdown-item" href="#">Vocab</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="#">Test Yourself</a>
        </div>
      </li>
      <!--<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>-->
    </ul>
    <!--<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>-->
  </div>
</nav>

<!-- Main Body Content -->

<div class="row no-gutters" id="main_content">
  <div class="col-md-3">
    <div class="card left_card">
      <div class="card-body">
        Placeholder text.
      </div>
    </div>
  </div>
  <div class="col-md-8">
    <div class="card right_card">
      <div class="card-body">
        Placeholder text.
      </div>
    </div>
    <div class="card right_card" id="card_1">
      <div class="card-body">
        Placeholder text.
      </div>
    </div>
  </div>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.0/js/bootstrap.min.js"></script>
</body>

Answer №2

It seems like the issue might be caused by the default margin of the HTML page.

To fix this in your CSS file, you can give this a try:

html,
body {
    height: 100%;
    margin : 0;
}

You can also update your CSS with this modification (I removed the " from the code).

#my_banner {
       background-image: url('banner.jpg');
       padding-bottom: 100px;
       overflow: hidden;
       width: 100%;
       max-width: 100%;
}

Let me know how it goes after implementing these changes.

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

Exploring the world of CSS and JavaScript event handling

I am currently working on a project involving replicating user actions from one browser to another. Both users are viewing the same page. I have set up an environment where the mouse movements of one user can be transferred to another browser (both users ...

Can the top header stay fixed to the top of the screen even when scrolling down?

Code snippet: http://jsfiddle.net/R3G2K/1/ In my project, there are multiple divs with content and each div has a header. My goal is to make the last header that goes out of viewport "sticky" or fixed at the top. I have explored various solutions for thi ...

Display an image overlaying a div

I am attempting to position an image outside of its parent div in such a way that it appears to be sitting on top of the div without affecting the height of the parent. However, no matter what I attempt, the image consistently gets clipped by the parent di ...

Shifting components around with CSS

My website's home page appears differently on a 1920px screen (big desktop screen) versus a 1366px (15" laptop) screen. While it looks perfect on the larger screen, there is a noticeable gap between the menu, text below, and the banner image on the s ...

jQuery unable to target Bootstrap button

I've been experiencing some trouble trying to attach a listener to a button I made with Bootstrap. <button type="button" id="buttonone" class="btn btn-default btn-lg good"> <span class="glyphicon glyphicon-minus" aria-hidden="true">< ...

The Angular Material FAB Speed Dial feature is causing a slight offset within the Toolbar

Attempting to incorporate design examples from the angular material site, I am utilizing Angular Material 1.0.0RC5. I am aiming to position the FAB Speedial within the Toolbar, similar to the example demonstrated on their site: https://material.angularjs. ...

Issues with receiving incorrect orders and implementing switch case statements in JavaScript

Attempting to utilize a switch-case structure based on months. For example, if the user selects 1, it should display January. The months are stored in an array where arr[0] = January. However, when selecting 1 from the dropdown, it displays "january" inste ...

Grant permission for cross-domain access on the ADFS server

We are facing a specific scenario where we are using MS Teams Task Module to display and load a web page. This web page is connected with SSO (ADFS). Upon loading the web page in the popup, it redirects to the SSO link. The challenge we are currently enco ...

Bottom is not adhering properly to the page (blocking content)

Hey there! I'm using Weebly as a CMS for my website, and I've encountered some issues with a custom footer. Specifically, on this page: The content seems to disappear if you're not using a large monitor and the page height is short. Upon in ...

Error message encountered in Python: AttributeError stating that the 'List' object does not possess the attribute 'click'. This error occurred while using Selenium. (Image attached for reference)

Help needed! I am struggling to select an item within the table cell. Below is the source code: <div class="clear formrow top_border"> <div> <table class="infoGrid" cellspacing="0" cellpadding="0" border="0" id="ctl00_cphMain_gd ...

Minimum number of cards in each column

I'm currently utilizing media queries to make sure that my card-columns are shown in a responsive manner. However, I have noticed that there is a minimum requirement of 2 cards in each column before it moves on to the next one (from left to right). T ...

Capture Your Scene with Three.js

I am facing an issue where I need to capture a screenshot of a website. I have tried using html2canvas and it is working fine. However, the problem arises because I am using both THREE.WebGLRenderer and THREE.CSS3DRenderer (for HTML in webGL). The screen ...

Is the input text returning NULL on postback?

Could someone please explain why the id value of the checkbox 'userId' is coming back as null during the POST request? <input type='checkbox' onclick='$("#userId").val("@user.Id"); return true; '/> @using (Html.BeginFo ...

Is there a way to incorporate ellipsis for text that overflows in the AntDesign Table component?

Issue: While working with AntDesign's Table component, I have successfully set the width of each cell. However, I am facing a challenge with text overflow as I would like the overflowing text to be truncated and displayed with an ellipsis. My ultimate ...

The selection will remain hidden and attempting to make a choice will be ineffective

Received an HTML sample from another company () and now I am attempting to create a web form based on it (). Using the same scripts, the basic structure mirrors the sample closely. After meticulously comparing the code, I can't find any discrepancies. ...

Get the dropdown values after a successful return from a jQuery AJAX call

When using jQuery AJAX, I retrieve values from the database to populate a dropdown menu. The process involves sending an ID to fetch the level, and then using that level ID and name to obtain related values for the selected level, which are displayed in th ...

Exploring the origins of CSS through patch design

Want to learn how to create a background like this using CSS? Check out this link for inspiration! ...

Formatting HTML Output Using PHP

Looking to format html output sourced from a database using php and facing an issue: Desired Format: ... <li> <div class="row-wrapper"> <div class="some-class-1">ARRAY-ELEMENT-1</div> <div class="some-class-1" ...

Pass the variable to another page (Deliver a message)

If the registration and login pages are completed, is it possible to pass a variable from the registration page to the login page? I aim to notify the user that the account has been successfully created. The notification should appear similar to this: Che ...

JavaScript and modifying color using hexadecimal color codes

Being a novice in front-end development, I embarked on a project using JavaScript that would alter the color of a div based on environmental parameters such as temperature and pressure. My initial idea involved creating buttons to adjust the temperature - ...