There appears to be no alteration in the documentation, yet why is there a discrepancy in image scaling based on width between Bootstrap 4 and 5?

My picture is positioned in a grid column. When utilizing Bootstrap 4, the .title-image { width: 60%;} style works as intended.

However, upon transitioning to BS 5, the image suddenly expands and protrudes. It appears that the width attribute is now aligned with the body width, rather than the image column container.

Both Bootstrap 4.5 and 5 documentation mention that images are treated with

.img-fluid { max-width: 100%; and height: auto;}

source:

v5: https://getbootstrap.com/docs/4.5/content/images/

v4.5: https://getbootstrap.com/docs/5.0/content/images/

Given that the specifications are the same, why does width: 60%; act differently?

CSS

.title-image {
  width: 60%;  /* this has different image display
                  between Bootstrap 4 and Bootstrap 5. Why? */
  transform: rotate(25deg);
  position: absolute;
  right: 23%;
}

#features {
  background-color: #fff;
  padding: 7% 15%;
  position: relative;
}

/* below is just decoration */
#title {
  background-color: #ff4c68;
  color: #fff;
  text-align: left;
}

h1 {
  font-family: 'Montserrat', sans-serif;
  font-weight: 900;
  font-size: 3.5rem;
  line-height: 1.5;
}

h2 {
  font-family: 'Montserrat', sans-serif;
  font-weight: 700;
  font-size: 2.5rem;
  line-height: 1.5;
}

h3 {
  font-family: 'Montserrat', sans-serif;
  font-weight: 700;
  font-size: 1.5rem;
}

p {
  color: #8f8f8f;
}

body {
  font-family: 'Montserrat', sans-serif;
  font-weight: 400;
}

.container-fluid {
  padding: 3% 15%;
}

.navbar {
  padding-bottom: 2.5rem;
}

.navbar-brand {
  font-family: "Ubuntu";
  font-size: 2.5rem;
  font-weight: bold;
}

.nav-link {
  font-family: "Montserrat";
  font-weight: 300;
  font-size: 1.2rem;
}

.download-button {
  margin: 3%;
}

HTML

 <section id="title">
    <div class="container-fluid">

      <!-- Nav Bar -->

      <nav class="navbar navbar-expand-lg navbar-dark">
        <a class="navbar-brand" href="">tindog</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarTogglerDemo02">
          <ul class="navbar-nav ms-auto">
            <li class="nav-item">
              <a class="nav-link" href="">Contact</a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="">Pricing</a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="">Download</a>
            </li>
          </ul>
        </div>
      </nav>

      <!-- Title -->
      <div class="row">
        <div class="col-lg-6">
          <h1>Meet new and interesting dogs nearby.</h1>
          <button type="button" class="btn btn-dark btn-lg download-button"><i class="fab fa-apple"></i> Download</button>
          <button type="button" class="btn btn-outline-light btn-lg download-button"><i class="fab fa-google-play"></i> Download</button>
        </div>

        <div class="col-lg-6">
          <img class="title-image" src="https://i.ibb.co/yFBgCTG/iphone6.png" alt="iphone-mockup">
        </div>
      </div>
      
  </div>
</section>

  <!-- Features -->

  <section id="features">
    <div class="container-fluid">
      <div class="row">
        <div class="grid-align-center col-lg-4">
          <i class="fas fa-check-circle"></i>
          <h3>Easy to use.</h3>
          <p>So easy to use, even your dog could do it.</p>
        </div>
        <div class="grid-align-center col-lg-4">
          <i class="fas fa-bullseye"></i>
          <h3>Elite Clientele</h3>
          <p>We have all the dogs, the greatest dogs.</p>
        </div>
        <div class="grid-align-center col-lg-4">
          <i class="fas fa-heart grid-align-center"></i>
          <h3>Guaranteed to work.</h3>
          <p>Find the love of your dog's life or your money back.</p>
        </div>
      </div>
    </div>
  </section>

Feel free to play around with the Bootstrap framework (switch between 4 and 5) using the codeply setting icon for further experimentation:

Answer №1

In Bootstrap5, the removal of position: relative for all column selectors sets it apart from Bootstrap4 where it was used with .col-lg-6.

If your CSS relies on

.title-image { position: absolute; }
, it needs the parent element to have position: relative to function correctly. The change between versions 4 and 5 might not be clear, but you can update the parent div to col-lg-6 position-relative to fix this issue.

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

Display the image on the right side when a specific number of pixels are available

Looking to have text wrapped around an image? Using float:right; can do the trick. However, is it possible to only float the image to the right when there is more than 200px of space available? For example: _____ |img | | | |_ ...

Tips for concealing labels until the submit button is activated

I am currently handling a project involving a Spring Controller and JSP. Within a JSP page, I have included a button labeled Process. Upon clicking this button, two radio buttons are displayed below it along with a Submit button. After tapping the Submit ...

Spacing between cards using Bootstrap

I have a collection of cards styled with Bootstrap and I am looking to add a left margin. I want the cards to be evenly spaced across the width. Right now, there is excess red on the right side that I want to remove... .azer { background: red; } .car ...

Guide on setting up p-menubar in PrimeNG to expand in the opposite direction, from left to right, for the responsive

How can I modify the CSS styles or configure the p-menubar from PrimeNg to have it expand from right to left in the responsive version? Currently, when using the classes align-items-center flex justify-content-between, the menu remains stuck to the right e ...

List with Columns for Organization

I am not seeking advice on how to use columns in lists, but rather on aligning the columns on my website. Below is the code I have: <ol class="threecolumns"> <li>Item 1</li> <li>Item 2</li> <li>Item 3< ...

What's the best way to avoid global application of stylesheets imported for svelte carbon components?

My dilemma lies in wanting to utilize the DatePicker feature from carbon-components-svelte. Unfortunately, when I do so, the global application of styles from carbon-components ends up causing some conflicts with my own custom styles. As per the documenta ...

React can easily incorporate CSS from multiple components

I'm experiencing a CSS import issue in my React project. I have a "Home" page that imports Home.css and a "Hero" page that imports Hero.css. Strangely, the styles from Hero.css are being applied to every page in the application without me explicitly d ...

Ways to add buttons to the navigation bar without placing them in the collapsed menu

I'm looking to add a button to the navbar with a red frame that remains visible at all times. The image above illustrates the desired button appearance. Thank you in advance to those who can assist! Image URL: <link rel="stylesheet" href="http ...

Instructions for accessing and printing text from a nested ul tag with Selenium in Java

Hello everyone, I am currently learning about Selenium Automation and have created a website as shown below. Here is the HTML code: <!DOCTYPE html> <html> <head><title>Shop</title></head> <body> <ul> < ...

Using getServerSideProps in Next.js is preventing the global css from loading

In my Next.js application, I have defined global styles in the file /styles/globals.css and imported them in _app.tsx. // import default style import "../styles/globals.css"; function MyApp({ Component, pageProps }) { return <Component {...pageProps ...

Is there a way to create a fixed container aligned to the right and have the parent container handle scrolling?

My setup is as follows: Full width, 100px height header The header is always visible at the top. Full width, remaining height details The content of details can scroll vertically and horizontally. A fixed 200px width, full height container is right- ...

Floating elements in IE are dropping below a floated input within an unordered list, while in Chrome everything displays correctly

I've been troubleshooting this issue for an hour now with no success. I'm facing a problem in Internet Explorer and can't figure out why. This is a snippet of the HTML code I'm using to display my registration form: <ul id="registe ...

<p> The box is massive, and its size is a mystery to me

https://i.sstatic.net/xPoDz.png Why is the box around my paragraph tag so large? I suspect this could be why I am unable to move the <p> tag down with margin-top: 50px; .train p { margin: 0; font-size: 2.5vw; } <div class="train"> < ...

Arranging elements on a webpage using Javascript

Creating a Dynamic Div Layout with JavaScript I have successfully implemented functionality wherein clicking on + opens a div and clicking on - closes it. However, I am now faced with the challenge of handling multiple divs at runtime. How can this be ach ...

Function in jQuery to reference two different divs

I'm currently facing an issue with a code snippet that I have. The requirement is for the user to be able to hover over "Div 1" and/or "Div2" and trigger a red border around both elements simultaneously. Due to the complexity of my WordPress theme, th ...

Creating transparent overlay boxes with CSS grid

I'm working on a design where I need to display text information over an image. The challenge is aligning the text properly, especially when the screen size changes due to using a grid system (1140). Currently, I have a div with transparent background ...

My page is experiencing delays due to setInterval

Currently, I am delving into the world of Chrome Extension development and am faced with a roadblock in replacing elements on a live chat page. While most of my tasks are running smoothly, the one thing causing issues is the setInterval option that trigger ...

The styles are not being rendered on the Angular application

I have successfully implemented a Modal service with working HTML/CSS (Check it out on StackBlitz) div.cover { align-items: center; background-color: rgba(0, 0, 0, 0.4); bottom: 0; display: flex; justify-content: center; left: 0; ...

What are some strategies for customizing the appearance of child components within a parent component?

I have a scenario where I am using parent and child components. When I use the HTML in another component, I also apply my CSS. For example, in my parent component: HTML <div class="chips"> <p class="tags">Tag 1</p&g ...

activating a button following the selection of a checkbox

My code includes a submit button that is currently disabled. I am looking to enable it when the user clicks on the "I agree" checkbox using jQuery. Can someone assist me with this? My code is written in HTML, JavaScript, and jQuery. <input id="agree" ...