Stop the "float:right" div from taking up all available space

I encountered an issue while developing a reddit clone.

Just to clarify, I'm using bootstrap v5.0

The problem arises when trying to position the sidebar on the right and the content on the left. The layout seems fine at first, but the content section ends up taking up the space allocated for the sidebar and pushing it down.

https://i.sstatic.net/zABpV.png

Below is the code snippet:

<div>
    <div class="container" style="margin-top: 80px;">
        <div class="posts jumbotron">
            <div class="post">
                <h3 class="post-heading"><a href="#">Lorem</a></h3>
                <p class="post-content">Lorem ipsum dolor sit amet consectetur adipisicing elit. Possimus maxime odio soluta eveniet, illum rem corporis minima velit quam voluptatibus earum quae quibusdam aut molestias? Consequuntur quibusdam odio culpa delectus!</p>
                <hr style="height: 3px; margin-top: 30px;">
                <br><br>
            </div>
            <div class="post">
                <h3 class="post-heading"><a href="#">Lorem</a></h3>
                <p class="post-content">Lorem ipsum dolor sit amet consectetur adipisicing elit. Possimus maxime odio soluta eveniet, illum rem corporis minima velit quam voluptatibus earum quae quibusdam aut molestias? Consequuntur quibusdam odio culpa delectus!</p>
                <hr style="height: 3px; margin-top: 30px;">
                <br><br>
            </div>
        </div>
    </div>

    <!-- Sidebar -->
    <div class="sidebar jumbotron">
        <h3 class="brand">Joined subreddits</h3>
        <br><br>
        <p style="margin-top: 20px; margin-bottom: 20px;"><a href="#" class="sidebar-link">Some text</a><p>
        <hr>
        <p style="margin-top: 20px; margin-bottom: 20px;"><a href="#" class="sidebar-link">Some text</a><p>
        <hr>
        <p style="margin-top: 20px; margin-bottom: 20px;"><a href="#" class="sidebar-link">Some text</a><p>
        <hr>
    </div>
</div>

Here's the accompanying CSS:

.sidebar {
    float: right;
    padding: 50px;
    box-shadow: rgba(50, 50, 93, 0.25) 0px 50px 100px -20px, rgba(0, 0, 0, 0.3) 0px 30px 60px -30px, rgba(10, 37, 64, 0.35) 0px -2px 6px 0px inset;
    border-radius: 10px;
    margin-right: 150px;
    width: 20%;
}

.posts {
    border: 1px solid gray;
    width: 75%;
    padding: 50px;
}

Answer №1

Implementing the desired layout using Bootstrap can be done through these recommended techniques:

  • Utilizing the BS grid system with the appropriate hierarchy .container>.row>.col:

/* Specific selectors to override default Bootstrap styles */

.sidebar.jumbotron {
  /* float: right; */
  padding: 50px;
  box-shadow: rgba(50, 50, 93, 0.25) 0px 50px 100px -20px, rgba(0, 0, 0, 0.3) 0px 30px 60px -30px, rgba(10, 37, 64, 0.35) 0px -2px 6px 0px inset;
  border-radius: 10px;
  /* margin-right: 150px; */
  /* width: 20%; */
}

.posts.jumbotron {
  border: 1px solid gray;
  /* width: 75%;*/
  padding: 50px;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dfbdb0b0abacabadbeaf9feaf1eef1ee">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">

<div class="container" style="margin-top: 80px;">
  <div class="row">
    <div class="posts jumbotron col-8">
      <div class="post">
        <h3 class="post-heading"><a href="#">Lorem</a></h3>
        <p class="post-content">Lorem ipsum dolor sit amet consectetur adipisicing elit. Possimus maxime odio soluta eveniet, illum rem corporis minima velit quam voluptatibus earum quae quibusdam aut molestias? Consequuntur quibusdam odio culpa delectus!</p>
        <hr style="height: 3px; margin-top: 30px;">
        <br><br>
      </div>
      <div class="post">
        <h3 class="post-heading"><a href="#">Lorem</a></h3>
        <p class="post-content">Lorem ipsum dolor sit amet consectetur adipisicing elit. Possimus maxime odio soluta eveniet, illum rem corporis minima velit quam voluptatibus earum quae quibusdam aut molestias? Consequuntur quibusdam odio culpa delectus!</p>
        <hr style="height: 3px; margin-top: 30px;">
        <br><br>
      </div>
    </div>
    <!-- Sidebar -->
    <div class="sidebar jumbotron col-4">
      <h3 class="brand">Joined subreddits</h3>

      <br><br>

      <p style="margin-top: 20px; margin-bottom: 20px;"><a href="#" class="sidebar-link">Some text</a>
      </p>
      <hr>
      <p style="margin-top: 20px; margin-bottom: 20px;"><a href="#" class="sidebar-link">Some text</a>
      </p>
      <hr>
      <p style="margin-top: 20px; margin-bottom: 20px;"><a href="#" class="sidebar-link">Some text</a>
      </p>
      <hr>

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

<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="70121f1f04030402110030455e415e41">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ" crossorigin="anonymous"></script>

.sidebar.jumbotron {
  /* float: right; */
  padding: 50px;
  box-shadow: rgba(50, 50, 93, 0.25) 0px 50px 100px -20px, rgba(0, 0, 0, 0.3) 0px 30px 60px -30px, rgba(10, 37, 64, 0.35) 0px -2px 6px 0px inset;
  border-radius: 10px;
  /* margin-right: 150px; */
  /* width: 20%; */
}

.posts.jumbotron {
  border: 1px solid gray;
  /* width: 75%;*/
  padding: 50px;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3f5d50504b4c4b4d5e4f7f0a110e110e">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">

<div class="container" style="margin-top: 80px;">

  <!-- This -->
  <div class="d-flex flex-row">

    <div class="posts jumbotron">
      <div class="post">
        <h3 class="post-heading"><a href="#">Lorem</a></h3>
        <p class="post-content">Lorem ipsum dolor sit amet consectetur adipisicing elit. Possimus maxime odio soluta eveniet, illum rem corporis minima velit quam voluptatibus earum quae quibusdam aut molestias? Consequuntur quibusdam odio culpa delectus!</p>
        <hr style="height: 3px; margin-top: 30px;">
        <br><br>
      </div>
      <div class="post">
        <h3 class="post-heading"><a href="#">Lorem</a></h3>
        <p class="post-content">Lorem ipsum dolor sit amet consectetur adipisicing elit. Possimus maxime odio soluta eveniet, illum rem corporis minima velit quam voluptatibus earum quae quibusdam aut molestias? Consequuntur quibusdam odio culpa delectus!</p>
        <hr style="height: 3px; margin-top: 30px;">
        <br><br>
      </div>
    </div>
    <!-- Sidebar -->
    <div class="sidebar jumbotron">
      <h3 class="brand">Joined subreddits</h3>

      <br><br>

      <p style="margin-top: 20px; margin-bottom: 20px;"><a href="#" class="sidebar-link">Some text</a>
      </p>
      <hr>
      <p style="margin-top: 20px; margin-bottom: 20px;"><a href="#" class="sidebar-link">Some text</a>
      </p>
      <hr>
      <p style="margin-top: 20px; margin-bottom: 20px;"><a href="#" class="sidebar-link">Some text</a>
      </p>
      <hr>

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

<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="92f0fdfde6e1e6e0f3e2d2a7bca3bca3">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ" crossorigin="anonymous"></script>

Answer №2

Include a floating left:

.articles {
    border: 1px solid darkgray;
    width: 75%;
    padding: 50px;
    float:left;
}

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

Update the src attribute in an HTML document

I am looking to dynamically change the size of an image on an HTML page using a dropdown list. Here is my code: <html> <head> </head> <body> <select id="selectbox" name=""> <opti ...

How can I utilize the Facebook API on Tizen to share a video?

Could someone please provide guidance on how to incorporate video uploading functionality into a Tizen application using the Facebook API and HTML5? ...

Show an image when hovering over a dot using CSS - without hovering directly on the image

I'm currently working on a merchandising page that involves photoshopping several products onto a background image. I want customers to be able to hover over a dot positioned on each product to reveal its information and provide a link similar to . Ho ...

What is the right way to efficiently rotate a View in React Native?

Here is my code snippet: <View style={{borderColor:"red",borderWidth:4,flex:1,transform: [{ rotate:'90deg' }]}}> <Text>Hi</Text> </View> The result can be seen here: https://i.sstatic.net/C9ryl.jpg Unf ...

Creating a Visual Loading Effect in HTML

My website's layout scheme gets lost if the page isn't fully loaded. I'm interested in implementing an animation that is tied to the loading progress, similar to a progress bar but without the visual element of a bar itself. One idea is to ...

Manipulate the DOM to remove a checkbox using JavaScript

I'm brand new to exploring the world of Javascript and could use some guidance with this task. I have a collection of checkboxes that I'd like to manipulate so that when one is checked, it disappears from the list automatically. I've come ac ...

What is the best way to apply a semi-transparent background to my navigation bar, while maintaining a blue background across my entire page?

Currently, I have a background set for my website along with a navigation bar that displays my name and additional information. I am looking to make the background of this navigation bar semi-transparent so that it is possible to see through it. I tried ...

Can Jquery be used to swap out specific li content?

<div class="widget_ex_attachments"> <ul> <li> <i class="fa fa-file-word-o"></i> <a href="uploads/2014/09/Parellel-universe.docx">Parellel universe</a> </li> ...

The scrolling function halts as soon as the element that was middle-clicked is deleted from the

I am knee-deep in developing my own React virtualization feature and encountering a minor annoyance. When I middle click on an item in the list and start scrolling, the scrolling stops once that item is removed from the DOM. My initial thought was that the ...

Avoiding the selection of HTML canvas objects

I am currently working on customizing my homepage with an interactive animation. However, I am facing some challenges in integrating it seamlessly into the page. You can view the progress at . My main issue is preventing the canvas object from being select ...

Tips for seamlessly incorporating advertisements into a mixed application

I am having trouble adding banner ads to my hybrid application developed with Telerik. Despite my extensive research, I have been unable to find a suitable solution. Is there any html5 or javascript banner advertising service/API that is compatible with ...

Creating a Authentic Screw Top Appearance with CSS

I am striving to create a realistic screw head. Here is what I have done so far: <div class="screw"><div class="indent"></div></div> .screw { position: absolute; top: 10px; left: 49%; width: 30px; height: 30px ...

Guide to dynamically implementing pagination through AJAX calls

In this javascript code snippet, I have a class named PurchaseHistory. var baseUrl = null; var parameters = null; var currentPageNumber = null; var TotalPages = null; var PageSize = null; $(document).ready(function () { baseUrl = "http://localhost/AP ...

Adjusting the width of a Material UI select/dropdown component

In my material-ui grid setup, each <Grid> contains a <Paper> element to define the grid's boundaries precisely. Inside every <Paper>, there is a custom <DropDown> component (a modified version of Material-UI's Select). I ...

What is the correct way to utilize href in CSS content property?

Below is the content of a box I have: https://i.sstatic.net/QmG5i.png When the above box is hovered over, it flips to this: https://i.sstatic.net/QsS9t.png This block's HTML code is as follows: <div class='tiles'> <div class= ...

Create a page that expands to full height with the ability to scroll

I am trying to achieve a layout using flex that fills the entire height of the screen. https://i.sstatic.net/s1RA5.png My goal is to have a red background that scrolls based on the content inside. If there is more content, I want it to maintain the same ...

Is there a way to automatically display the detailsPanel in Material-table upon loading?

I am currently working on creating a subtable for the main React Material-Table. So far, everything is functioning correctly as expected, with the details panel (subtable) appearing when the toggle icon is pressed. Is there a way to have it displayed by d ...

incorporating numerous interconnected javascript files within a single html document

I have a pair of JavaScript files (file1, file2). File1 utilizes a class that is defined in file2. Can I include these files in an HTML document like this: <script type="text/javascript" src="file1.js"></script> <script type="text/javascrip ...

Is there a way to dynamically change the source of an image based on different screen sizes using Tailwind CSS?

Currently, I am utilizing the next/Image component for setting an image and applying styling through tailwindcss. However, I have encountered a roadblock at this juncture. My Objective My goal is to dynamically change the src attribute of the image based ...

Fixed and percentage widths in horizontal divs for children, with the percentage width exceeding the desired size

Here's the code snippet I'm working with: http://pastebin.com/W3ggtgZB. The body of this code can be found here: http://pastebin.com/2tkmhnfW. My goal is to create a div containing two child divs. One child div should have a fixed width, while t ...