The nested div is not expanding to fill its parent div completely, leaving some space on both the right and left sides

I'm in the process of creating a responsive website and I've encountered an issue while using Bootstrap's columns and rows. It seems that the inner div with the class profile_left is not occupying the entire space within another div, leaving some empty space on each side.

Could you please help me identify what might be going wrong?

Below is a snippet of my code:

.profile_left{
border: 1px solid black;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
}

.profile_picture{
    padding:20px;
    overflow: hidden;
}

<div class="container">
    {% block content %}
        <div class="row">
            <div class="profile_left col-lg-8 col-md-8 col-sm-8 col-xs-12" style="width: 30%;">
                <div style="background-color: #01226c; text-align:center; padding:20px;">
                    <h3 style="color: white;"><strong>PROFILE</strong></h3>
                </div>
                <div style="background-color: white;">
                    <div class="profile_picture">
                        <figure>
                            <img src="{{ student.profile_picture.url }}">
                        </figure>

                        {% if student.profile_picture == 'default.png' %}  
                             <a href="">Add a picture</a>
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>
{% endblock content %}
</div>

Answer №1

The challenge arises when the inner div expands to occupy the entire available width. This issue is typically caused by the Bootstrap framework, as its column elements (identified with the class col-) are styled with padding properties. To address this problem, you need to eliminate the default padding by adding padding: 0;

.profile_left{
  border: 1px solid black;
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;
  padding: 0;
}

Answer №2

After analyzing the details provided and reviewing your code snippet, it appears that you are looking to have the inner div occupy the entire space without any margin. The extra space you are noticing is due to the Bootstrap class "col-xs-12", which adds a padding of 15px on both sides of the inner div.

To resolve this, simply set the padding to 0 in the CSS for your div with the class .profile_left

div .profile_left{
 border: 1px solid black;
 border-top-left-radius: 5px;
 border-top-right-radius: 5px;
 padding: 0px;
}

If the above solution does not work, you can try using the following:

div .profile_left{
 border: 1px solid black;
 border-top-left-radius: 5px;
 border-top-right-radius: 5px;
 padding: 0px !important;
}

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

Steps to automatically navigate to a new page following user registration in Django

Upon successful registration, the webpage should redirect to a specific path called 'products/index' within my application. This will automatically log in the user after registration using function-based views. This is how it looks in my views.p ...

Utilizing ReactJS to extract and manipulate HTML data

My MongoDB database contains raw HTML content, and I have added a custom attribute called kk-id to specify objects within the HTML. Now, I need to replace a specific HTML tag with an anchor tag. I managed to achieve this using vanilla JavaScript, but I am ...

Prevent improper text wrapping of certain words in RTL languages like Farsi and Arabic

In languages like Farsi and Arabic, as well as other RTL languages, letters are connected to each other (e.g. سیب), but not always (e.g. می شود). This can sometimes cause issues with the flow of text when half a word wraps over to the next line due ...

How can I display a list of relative urls in an android TextView?

I have a situation in my application where I am displaying a block of HTML content in a TextView, which has been extracted and parsed from a webpage. This HTML includes numerous links, with some being absolute and others relative. My goal is to allow the u ...

`Looking for a solution: Bootstrap failing to align right properly`

In my Bootstrap 4 project, I am facing an issue with aligning a label and an icon within a Card-Header. I want the Label to be left-aligned and the icon to be right-aligned, but for some reason, the icon is always attached to the label instead. Even when I ...

Expand the functionality of XHTML by incorporating namespaces

I remember coming across this concept somewhere, but I can't recall the exact source. I am interested in expanding HTML tags to include my own attributes on the HTML elements. I remember seeing an example where a developer added a new xmlns to the pa ...

Adding color to the header's top section and leaving the navigation bar untouched

A few days ago, I posted a question on this platform regarding customizing CSS related to search forms within Bootstrap. The response I received from Charlie was incredibly helpful in refining the code for my header and navigation elements. You can view hi ...

Adjust the size of the background image using a media query

.logo { background-image: url(https://ofbuckleyandbeatles.files.wordpress.com/2011/01/testpattern.gif); background-size: 100%; } @media(max-width:767px) { .logo { background-image: url(https://ofbuckleyandbeatles.files.wordpress.com/2011/01/te ...

Ways to address the horizontal shift of an element caused by the Cumulative Layout Shift issue

My header is styled with a max-width and margin to position it in the center of the page horizontally. Despite this, running a lighthouse report reveals a horizontal shift issue. If anyone has faced this problem before and knows how to fix the horizontal ...

What could be the reason that the accordion is failing to expand or collapse when clicked?

I am facing an issue where the div is not expanding or collapsing upon clicking the + sign. I have tried removing unnecessary scripts but it still doesn't work. Additionally, there is an error in the console: Uncaught TypeError: $(...).slideReveal is ...

Checkbox value not being accurately retrieved by Struts2 page

I have a form that captures phone information for two different phones, with each phone having its own set of details. If the user enters the same phone number for both phones, the second checkbox is automatically checked using the JavaScript code below: ...

Enable scrolling for divs on mobile devices

My filter layout is a customized HTML and CSS template based on Bootstrap. Here is an example of the code: a:hover { color: #444; text-decoration: underline; } /* Rest of the CSS styling */ I ...

Styling Multiple Fullscreen Rows with Bootstrap CSS

Does anyone have any suggestions for the CSS code needed to stack five rows on top of each other? Each row should be 100% height and width of the browser. Here is the HTML code I currently have: <div id="wrapper"> <div class="container-fluid"> ...

Assistance with Ajax for content loading

Greetings, I am encountering an issue with the following code snippet (located in a js file named ajax.js) $(function(){ $("#loading").hide(); $("ul#nav a").click(function(){ page = "content/"+$(this).attr('href') ...

What is preventing me from utilizing Jinja in JavaScript for a django website?

When using Python and Django framework for website development, one useful tool to incorporate is the jinja template engine. For instance: Rather than hard-coding an import like this: <script src="assets/js/onebutton.js"></script> We can do ...

Strategies for overcoming cyclic dependencies when defining generic models in Django

I am looking to establish a versatile model that can be utilized in any application. The definitions of my generic models are as follows: User = settings.AUTH_USER_MODEL # This mixin is used to track the user who created this object. class OwnedModel(mod ...

Building an HTML table dynamically with JavaScript

Can anyone help me figure out why my JavaScript code isn't populating the HTML body table as expected? var shepard = { name: "Commander", victories: 3, ties: 1, defeats: 6, points: 0 }; var lara = { name: "RaiderOfTombs", victories: ...

Styling a webpage with a two-row layout using just CSS

I am looking to design a 2-row layout for a webpage where one row will contain filters and the other row will display results. The layout should meet the following criteria: The page height should not exceed 100% The first row's height will vary bas ...

In search of a customized CSS design for drop-down lists and menus inspired by Apple's sleek aesthetic

I've been on the hunt for a CSS example that showcases Apple-style drop down lists and buttons. Despite my efforts to search through Google, I can't seem to find exactly what I'm looking for. I've tried various search phrases like "Appl ...

Using an HTML element to pass a variable into a replace function

I am looking to highlight a 'SearchString' by replacing it with <span style="background-color: yellow">SearchString</span> within a targetString. The SearchString varies, so I am wondering how I can make this happen. This is what I ...