Struggling to Adjust Image to Fit Within Parent Element

I recently started using bootstrap 4 to create a responsive website for practice. However, I encountered an issue with my image not resizing properly to fit the screen.

<html lang="en">
<head>
    <!-- Required Meta Data -->
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    
    <!-- Google Fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Nunito:wght@200;300;400;700&display=swap" rel="stylesheet">

    <!-- Bootstraps CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
    
    <!-- Custome CSS -->
    <link rel="stylesheet" href="app.css">

    <title>Museum of Candy</title>
</head>
<body>
    
    <nav id="mainNavbar" class="navbar navbar-dark  navbar-expand-md py-0 fixed-top">
        <a href="#" class="navbar-brand">CANDY</a>
        <button class="navbar-toggler" data-toggle="collapse" data-target="#navLinks" aria-label="Toggle Navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div id="navLinks" class="collapse navbar-collapse">
            <ul class="navbar-nav">
                <li class="nav-item">
                    <a href="#" class="nav-link">HOME</a>
                </li>
                <li class="nav-item">
                    <a href="#" class="nav-link">ABOUR</a>
                </li>
                <li class="nav-item">
                    <a href="#" class="nav-link">TICKETS</a>
                </li>
            </ul>
        </div>        
    </nav>

    <section class="container-fluid px-0">
        <div class="row align-items-center">
            <div class="col-lg-6">
                <div class="text-white text-center d-none d-lg-block">
                    <h2 class="">MUSEUM OF CANDY</h2>
                    <h2 class="">MUSEUM OF CANDY</h2>
                    <h2 class="">MUSEUM OF CANDY</h2>
                </div>
            </div>
            <div class="col-lg-6 px-0">
                <img class="img-fluid" src="imgs/img1.jpg" alt="Hand Donut">
            </div>
        </div>
    </section>



    <!-- Optional JavaScript -->
    <!-- JQuery First, Then Popper.js, then Bottstarp JS -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
</body>
</html>

My problem is that the image is not filling the entire column space and leaving some white space. https://i.sstatic.net/hAfIR.png

Even when I resize the screen to medium resolution, the image still does not cover the full screen width.

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

When I tried adding CSS styles to it, they were being overridden.

CSS File

body{
    background: #f5d9d5;
    font-family: "Nunito", sans-serif;
}



#mainNavbar{
    font-size: 1.5rem;
    font-weight: 100;
}

#mainNavbar .nav-link{
    color: white;
}

#mainNavbar .nav-link:hover{
    color: #EA1C2C;
}

#mainNavbar .navbar-brand{
    color: #EA1C2C;
}

Answer №1

<img class="responsive-img" style="float:right;" width="100%" src=...>

By adding this code, the image will automatically adjust to fit within its parent div, resolving your problem.

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

Using the double class within the .solution environment and adjusting the label of the .solution environment using CSS styling

Currently constructing a book with the use of quarto, where the inclusion of theorems, lemmas, corollaries, and other elements is necessary. In the quarto documentation, as seen here, it is advised to utilize the proof, remark, and solution environments fo ...

What is the reason behind the _set.all function not working in the template?

I have a scenario where I have three interconnected models: GroupRequirementType --> GroupRequirement --> Requirement. When trying to display all requirements in the template, only GroupRequirementType objects are being shown. It appears that there m ...

Achieving the extraction of a particular string from an HTML element using JavaScript

<input id="WD01B3" ct="CB" lsdata="{2:'WD01B4',4:'Any',20:'\x7b\x22WDA_TYPE\x22\x3a\x22DROPDOWN_BY_KEY\x22,\x22WDA_ID\x22\x3a\x22ABCA950297D2C0C432BAB9BB ...

Is it possible to use JQgrid to navigate to a new page upon double-clicking?

I have a straightforward jQgrid implementation on my website <div id="catalogueSearchList" class="dataGrid"> <script type="text/javascript"> var catalogueSearchListConfig = { ...

Responsive Grid with Card component using React Material UI

Struggling to devise a responsive grid layout with same height cards featuring images in a React and Material-UI setup. After hours of tinkering, the "flex" part is proving to be quite puzzling. Seeking guidance. The code snippet in question: const useSt ...

Combining Images and Navigation in Next.js using Tailwind CSS

I am facing an issue where the image from a particular section overlaps with the Navbar dropdown on mobile devices. Adding z-50 to the navbar did not solve the problem as expected. What I want is for the image to remain below the dropdown menu when it is ...

Require the header text to appear black on a white background and white on a dark background

As someone who is not experienced in coding, I have tried multiple methods without success. It seems like none of the solutions available are compatible with my Squarespace theme. Any assistance you can provide would be greatly appreciated! Here is a link ...

Guide to taking a screenshot of an HTML page using Javascript, Jquery, and HTML5 functionality

I am looking to add a unique feature to my website - the ability to capture the current image of my webpage with just the click of a button. Inspired by Google's "send feedback" function, I want to implement something similar on my own site. After res ...

JavaScript library for creating animated car movements on a map using JPG images

Looking for a way to animate a car's movement on a map? I have a map image in jpg format (not svg) and a sequence of (x,y) points ready to go! If you could recommend a JavaScript library that can help me easily create an HTML page with this animation ...

Sleek carousel design with optimal spacing between images

Solving the Issue Utilizing Ken Wheeler's Slick plugin has allowed me to create a carousel on my website. However, I've encountered an issue where the images inside the <a> tag aren't evenly spaced and are even overlapping in some ins ...

Divide Footer Information into Two Sections: Left and Right

<footer> <div class="copyrights-left"> <p>&copy 2015. <a style="color: #fff;" href="index.html">Free Xbox Live Gold Membership and Free Xbox Live Gold Codes</a>. All rights reserved.</p></div> <div class="co ...

Disabling click events on a span tag in Angular 6: A step-by-step guide

Is there a way to disable the click event for deleting hours with the 'X' symbol based on a condition? Thank you in advance. <table navigatable class="<some_class>"> <tbody> <tr *ngFor="let item of ...

disable caching for xmlhttp request

One issue I am facing is with a JavaScript function that retrieves JSON data via an Ajax request. The problem I'm encountering is that the browser starts caching the response to this request, which means I am not getting the most recent data from the ...

Incorporate a dropdown menu based on the selection made in another dropdown menu

I have a scenario on my website where I want to dynamically add select boxes based on the value selected in the previous one. Here is the code snippet: <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.js"> </script> & ...

Create a replication of this in VB.NET using an ASPX Repeater to iterate over the specified content

Need help with repeating the following code in vb.net/asp.net: <ul id="prod_nav" class="clearfix"> <li class="top"><a href="05-Pink-02-Category-List.html" class="top_link"><span class="down">Body and Trim</span></a&g ...

Concerns with the Width of Gutters in Susy

I am working with a 24 Susy column grid and trying to create boxes that span 6 columns each, allowing for 4 boxes per row. However, I also want to add gutters around them within a wider container that is 24 columns wide. Despite my efforts, the columns do ...

Failure to establish a viewport results in mobile devices displaying long lines with a bigger font size

Below is a code snippet that I am working with: <!doctype html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>Document</title> </head> <body> ...

The detailView feature in wenzhixin bootstrap-table is failing to initialize the child row

I am currently utilizing the wenzhixin bootstrap table and attempting to initialize another bootstrap table within a child row known as 'detailView' in the code. Previously, I was using datatables but found this method to be simpler and more dir ...

Retrieving the first child in a tree via URL parameters using JavaScript, rather than the currently selected one

I'm currently facing a specific issue with my webpage and I will elaborate on what's happening. Within my page, I have created a list containing multiple sections. Here is an example of how it looks: <ul class="menu__list--nested active& ...

Responsive background with full width for mobile using Bootstrap version 2.3.2

I am facing an issue with mobile resolutions as the background does not expand to 100% width on smaller screens. Here is how it looks: However, everything works fine on higher resolutions. Upon testing my website using , I found that the 100% width backgr ...