Hiding the absolute div in a Bootstrap 4 container

Looking for help with displaying a div using bootstrap 4 with an absolute position inside a container? Here's the code I have:

Code:

<div class="container position-relative">
  <div class="position-absolute text-justify w-100">
    (Insert your text here)
  </div>
</div>

Unfortunately, when implementing this code, the div with an absolute position appears outside of the container. How can this issue be resolved?

Check out the demo here on jsfiddle.

Answer №1

It's not common to use positions in your divs, but if you must, consider wrapping your content into a row:

.container {
    height: 500px;
    background-color: #eee;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">

<div class="container position-relative">
    <div class="row">
        <div class="position-absolute text-justify w-100">
            text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo
            demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text
            demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text
            demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text
            text demo text demo text demo
        </div>
    </div>
</div>

Answer №2

When styling the container, be cautious of conflicting declarations such as using 'w-100' for 100% width along with padding. Removing the padding from the container can help resolve the issue.

.container{
  height:500px;
  background-color:#eee;
  padding: 0px;
}
<div class="container position-relative">
  <div class="position-absolute text-justify w-100">
  <p>
    text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo
    </p>
  </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

Running javascript code after the completion of the render method in Reactjs

I am working with a ReactJS component: const com1 = React.createClass({ render: function() { return ( <a href='#'>This is a text</a> ); } }); I am looking to run some Javascript/jQuery code once the rendering ...

Challenge with CSS Layering

I'm currently experiencing some issues with layering on my website. The problem at hand is that visitors are unable to interact with links within the div layers for some unknown reason. They can't click on the sidebar images or highlight text. I& ...

Revamp the table layout for mobile with a unified markup structure

I want to customize the display of my bootstrap table for mobile view. Each row entry should be shown in a separate box or card, similar to the following examples: First: Mark Last : Otto Handle: @mdo Second card- First:Jacob Last:Thornton Handle:@fat Is ...

Concluding a row in PHP Bootstrap for various grid dimensions

My grid layout for displaying a list of users now includes the classes col-xs-4 col-sm-4 col-md-3 col-lg-2. In the past, I only used col-md-2 and relied on a $counter to manage the row layout: while ($row = $business_query->fetch_assoc()){ ...

How can I eliminate excess cell spacing from a div that has a display of inline table?

This situation is really frustrating. While using Firefox and Opera, I am encountering unnecessary padding between my nested divs, which is not the case with Chrome and Safari. I attempted to use border-collapse:collapse However, it did not work. Do you ...

Setting the parent's height to match one of its children

I'm struggling to align the height of the pink '#images-wrap' with the main image. When there are too many small rollover images on the right, it causes the pink div to extend beyond the main image's height. If I could make them match i ...

What's the deal with Bootstrap 4 Card Rows?

I am currently utilizing the card-deck class from Bootstrap 4. My goal is for the h4 element to align to the right of the img-thumbnail class within the card. <div class="card-deck"> <div class="card"> ...

Guide to obtaining the dynamically generated id of an HTML element using Angular

<div *ngFor="let link of links; let i = index;"> <p>{{link.full}}</p> <button [id]='i' (click)="copyToClipboard(copy)">Copy</button> </div> Is there a way to access the [id]="i" in my TypeScript code? ...

Experiencing a problem when switching between various divs on the website

Having difficulties with tracking the state of my application. Whenever I select a ticket on the edit form, the updated information is passed to all other tickets. I suspect there is an issue with how the state is being managed. The problematic function s ...

Changing the title of a webpage dynamically with dropdown menu selections using AngularJS

Seeking assistance with dynamically changing the title of an HTML page based on a selection from a drop-down menu populated by categories retrieved from a remote database using PHP and Ajax in AngularJS. When a category is clicked, I want the page title to ...

Please ensure there is space reserved for the header above the content

Currently, I am working on creating a webpage with a unique banner design. My goal is for the content to scroll from the bottom and remain fixed directly under the upper portion of the banner. Initially, my idea was to have the content box take up the siz ...

Is it possible for the browser to ignore the style.min.css file and only use the style.css file when both files are linked in the HTML?

I have a question about file downloads: If I have two files named Style.css and Style.min.css in the same directory, and my HTML page references Style.css, will the browser or server ever download the Style.min.css file instead? (Even if they have the sa ...

Creating a pattern to match date ranges using regular expressions

Looking to extract dates from a date string, for example, how can I convert "01-Apr-2013" to "01-Apr-2016"? Any tips on creating Regex or JavaScript code for this task? ...

What is the significance of using single quotation marks to enclose the 'raw' key in Tailwind?

While reviewing the Tailwind documentation on custom media queries, I came across an interesting option to create a fully custom breakpoint using the 'raw' key. After adding this to my configuration file, I noticed that when I saved the file, Pr ...

updating the HTML DOM elements using JavaScript is not yielding any response

One way that I am trying to change the background of a div is by using a function. Below is an example of the html code I am working with: $scope.Background = 'img/seg5en.png'; document.getElementById("Bstyle").style.background = "url("+$scope.B ...

How to apply CSS to a table row while binding data in an ASP ListView

Looking for a way to apply a CSS style to a table cell based on certain conditions in my ListView control. <asp:ListView ID="lv1" runat="server" ItemPlaceholderID="itemPlaceholder" OnPagePropertiesChanging="ChangePage"> <LayoutTemplate> ...

The include function in jQuery fails to function as expected

Since my website was growing and the index.html file became too long and difficult to manage, I made the decision to split each section into separate HTML files and use jQuery to include them. I followed the instructions mentioned here on how to include a ...

Modify the hover dimensions within the CSS of a Bootstrap framework

I am trying to customize the hover effect size on my navigation bar in Bootstrap 4. I want to reduce the background size of the menu links when hovered over. I attempted a method from this source: How do i change the width of the hover in bs4 , but it did ...

Tips for preserving session on an Atheros board with C programming to access a website

Currently, I am utilizing the Atheros development board with LSDK-9.2.0_U10.5.13 stack and mips-linux-2.6.31 Linux version. On the board, I have c file, html, js, and css files, without utilizing the cgi library or any scripting language like php. My curr ...

increasing the size of a picture without resorting to a pop-up window

Struggling to implement a product details tab within a table that features a clickable image. When the image is clicked, it should enlarge but the width doesn't adjust accordingly. I'm using bootstrap 5.3 and can't seem to identify the root ...