The Bootstrap carousel image is not displaying properly and adapting to different screen sizes within the RenderBody() section

I'm currently working on implementing a responsive image carousel within the homepage index, which is displayed in the common layout page. However, when I decrease the height of the carousel-item div, the full image is not being displayed properly in the index.html file. How can I make sure that the full image remains responsive even if the height of the carousel-item div is reduced?

Here's the code snippet:

  1. _Layout.cshtml

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - MyCompany</title>
    <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="~/css/site.css" />

</head>

<body>
    <div class="container-fluid icon-top py-4 px-5">
        <div class="row">
             
        </div>

    </div>
    <header id="header">
        <nav class="navbar  navbar-expand-sm navbar-toggleable-sm navbar-dark bg-dark">
            <div class="container">
                <a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">MyCompany</a>
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse"
                    aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="navbar-collapse collapse">
                    <ul class="navbar-nav ml-auto">
                        <li class="nav-item active">
                            <a class="nav-link" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" asp-area="" asp-controller="Home" asp-action="Privacy">About Us</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" asp-area="" asp-controller="Home" asp-action="Privacy">Our Project</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" asp-area="" asp-controller="Home" asp-action="Privacy">Contact</a>
                        </li>
                    </ul>
                </div>
            </div>
        </nav>
    </header>

    <div class="body-container">
        @RenderBody()
    </div>

    <footer class="border-top footer text-muted">
        <div class="container" id>
            &copy; 2021 - MyCompany - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
        </div>
    </footer>
    <script src="~/lib/jquery/dist/jquery.min.js"></script>
    <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
    <script src="~/js/site.js" asp-append-version="true"></script>
    <script src="~/js/all.js"></script>
    @await RenderSectionAsync("Scripts", required: false)
</body>

</html>

  1. Index.cshtml

@{
    ViewData["Title"] = "Home Page";
}
<section id="home-heading">
    <div id="MyCarousel" class="carousel slide" data-ride="carousel">
        <div class="carousel-inner">
            <div class="carousel-item carousel-image-1 active">

            </div>
            <div class="carousel-item  carousel-image-2">

            </div>
            <div class="carousel-item carousel-image-3">

            </div>
        </div>
        <a class="carousel-control-prev" href="#MyCarousel" role="button" data-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
            <span class="sr-only">Previous</span>
        </a>
        <a class="carousel-control-next" href="#MyCarousel" role="button" data-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="sr-only">Next</span>
        </a>
    </div>
</section>

<!-- INFO SECTION -->
<section id="info" class="py-3>
    <div class=" container">
    <div class="row">
        <div class="col-md-8 align-self-center">
            <h3>Lorem Ipsum</h3>
            <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptate eveniet blanditiis incidunt iusto
                corrupti illum cum laudantium ex sequi amet. ssfsdfs fjjerhehr uiewruhweuiruiewruyhyuewiry iweuyr
                ryewiuryiweuy. uieeryewi iuweriwe yb 7weyr7ewy87r7ywe8ry8wer8 we87r y87we78r7we8r
                7we87rwe87r87wer8werweuewof
                w8ueuwe88ur9we8r </p>
            <a href="about.html" class="btn btn-outline-danger btn-lg">Learn More</a>
        </div>
        <div class="col-md-4">
            <img src="img/laptop.png" alt="" class="img-fluid">
        </div>
    </div>
    </div>
</section>

  1. Site.css

 

a.navbar-brand {
    white-space: normal;
    text-align: center;
    /* To ensure proper word wrapping */
    word-break: break-all;
}

#body-container {
    top: 0;
    bottom: 0;
    right: 0;
    left: 0;
}


/* Ensuring sufficient contrast against white background */

a {
    color: #0366d6;
}

.btn-primary {
    color: #fff;
    background-color: #1b6ec2;
    border-color: #1861ac;
}

.nav-pills .nav-link.active,
.nav-pills .show > .nav-link {
    color: #fff;
    background-color: #1b6ec2;
    border-color: #1861ac;
}


/* Sticky footer styles
-------------------------------------------------- */

html {
    font-size: 14px;
}

@media (min-width: 768px) {
    html {
        font-size: 16px;
    }
}

.border-top {
    border-top: 1px solid #e5e5e5;
}

.border-bottom {
    border-bottom: 1px solid #e5e5e5;
}

.box-shadow {
    box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
}

button.accept-policy {
    font-size: 1rem;
    line-height: inherit;
}


/* Sticky footer styles
-------------------------------------------------- */

html {
    position: relative;
    min-height: 100%;
}

body {
    margin-bottom: 60px; /* Margin bottom to accommodate footer height */
}

.footer {
    bottom: 0;
    width: 100%;
    white-space: nowrap;
    line-height: 60px; /* Vertically centering the text */
}

.icon-top {
    background-color: chocolate;
}

.navbar .nav-link {
    font-size: 14px !important;
    text-align: right !important;
    padding-left: 1rem !important;
    padding-right: 1rem !important;
}

.navbar .nav-item.active {
    border-left: #444 3px solid;
}

.carousel-item {
    height: 800px;
    /* Add styling details for each carousel item background */
}

.carousel-image-1 {
    background: url('../img/banner-1.jpeg');
    background-size: cover;
}

.carousel-image-2 {
    background: url('../img/banner-2.jpeg');
    background-size: cover;
}

.carousel-image-3 {
    background: url('../img/banner-3.jpeg');
    background-size: cover;
}

With gratitude, Pol

Answer №1

To customize your page layout, insert the following code.

@RenderSection("style", required: false)

Next, paste your Carousel script into any View page within

@section style{ "your bootstrap carousel code"}
. By doing this, you can display your carousel wherever needed and ensure it adjusts responsively to fit the entire image.

@section style{

<div id="myCarousel" class="carousel slide" data-ride="carousel" style="margin-top:-15px">
    <ol class="carousel-indicators">
        <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
        <li data-target="#myCarousel" data-slide-to="1"></li>
        <li data-target="#myCarousel" data-slide-to="2"></li>
    </ol>

    <div class="carousel-inner" role="listbox">
        <div class="carousel-item active">
            <img class="d-block w-100" style="background-color: gray; height: 550px; width: 100%;" src="~/images/family1.jpeg" alt="Img1" />
            <div class="carousel-caption">
                <h3>Image 1</h3>
                <p>A happy image</p>
            </div>
        </div>
        <div class="carousel-item">
            <img class="d-block w-100" style="background-color: gray; height: 550px; width: 100%;" src="~/images/family1.jpeg" alt="Img2" />
            <div class="carousel-caption">
                <h3>Image 2</h3>
                <p>A new image</p>
            </div>
        </div>
        <div class="carousel-item">
            <img class="d-block w-100" style="background-color: gray; height: 550px; width: 100%;" src="~/images/family1.jpeg" alt="Img3" />
            <div class="carousel-caption">
                <h3>Image 3</h3>
                <p>An old image</p>
            </div>
        </div>
    </div>
    <a class="carousel-control-prev" href="#myCarousel" role="button" data-slide="prev">
        <span class="carousel-control-prev-icon" aria-hidden="true"></span>
        <span class="sr-only">Previous</span>
    </a>
    <a class="carousel-control-next" href="#myCarousel" role="button" data-slide="next">
        <span class="carousel-control-next-icon" aria-hidden="true"></span>
        <span class="sr-only">Next</span>
    </a>
</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

How come my div can alter its own attributes on hover, but its sibling cannot?

As I delve into the realm of web development, my initial project involves creating a portfolio site. However, I am facing difficulties with the dropdown section in one of the menus. I incorporated a :hover pseudo-class to the dropdownhover div to signal ...

Choosing comparable choices from the drop-down menu

I am working on a dropdown menu that contains different options. I need to use jQuery to automatically select the option that corresponds to the branch of the currently logged in user. However, when some option text is very similar, it causes an issue. // ...

Utilizing a select option dropdown to compute multiple values simultaneously

Can you help me figure out how to calculate multiple options from values in a dropdown menu? Below is some simple HTML code and a function from PDO functions. What I am trying to achieve is to calculate the values inside <div id="RightBox">, which a ...

Tips for converting mobile numbers into clickable links using JavaScript

I am working on an HTML page where data is being dynamically loaded, including some mobile numbers. I'm looking for a way to wrap all these mobile numbers in anchor tags using JavaScript. For example: <a href="tel:+91 9999999999">+91 9999999999 ...

Instructions for swapping images by triggering a .on click event with four buttons

Hi everyone, I could really use your assistance with this issue. Let me explain the situation. I have 4 buttons that are meant to trigger different images. When a button is clicked, it should become active (I think I have this part figured out, but let me ...

What causes the modal to appear and then vanish suddenly?

I've created a simple modal code with minimal JS involved. When the button is clicked, the modal appears briefly, then the page refreshes and the modal disappears. I'm not sure what could be causing this issue. Any help would be appreciated! h ...

Access the video file from the center

I am trying to implement video streaming in small chunks, for example 0-50, 50-100, etc. I need the ability to play the video starting from 0 but not be able to play it from random ranges. Any help or guidance is appreciated. createReadStream(path,{star ...

What is the significance of an empty href attribute in the HTML <base> tag?

If my website URL is: http://example.com/path/to/dir/index.html And I decide to proxy this page through: http://proxyserver.com/path/to/dir/index.html. I would like all relative URLs on the page to be resolved by proxyserver.com instead of example.com. Wh ...

After attempting various solutions for days, the navbar was finally switched to a vertical layout following the addition of the Bootstrap Carousel, although functionality

After adding the Bootstrap carousel to my index.html, the navbar unexpectedly switched to a vertical layout. I tried adjusting various elements such as font size and width, but it seems like the issue lies within the carousel itself. Whenever I include th ...

Is there a way to retrieve php session in a javascript file?

Here's the code snippet for reference: Contents of index.php file Javascript code from index.php function Result() { var marks = 55; document.getElementById("hdnmarks").innerHTML= marks; window.location = "results.php"; } HTML code from ind ...

Create a dynamic feature in Bootstrap4 where the navigation bar changes color as the user scrolls to different sections of the

Currently building my personal portfolio website with Bootstrap 4, I came up with a great idea: changing the navigation bar color based on different sections of the website. I attempted to achieve this using JQuery's offset and scrollTop functions, bu ...

Resolve the issue of Dojo images not appearing on a div in Internet Explorer

I am trying to incorporate images into a dojo chart using the given code: var l_images = ["images/clearnight.png","images/clear.png","images/partlyCloudy.png","images/cloudy.png","images/showers.png","images/rain.png","images/thunderstorms.png","images/ic ...

Explore the world of interior CSS border styles

Trying to achieve a unique border effect like the one shown in the image. Experimented with different styles such as inset, outset, ridge, and groove, but unable to get the desired outcome. Is there a way to create a border that bends inwards towards the m ...

Leveraging Angular interpolation with the "ngIf" directive

In my table, I have a specific requirement for the first column to change color based on a variable within my class. For instance, within my DisplayProject.ts class, there is a property named indexOfColor DisplayProject.ts export class DisplayProject impl ...

Adjust a variable based on the current value in JavaScript

I'm looking to change the label based on the value of a textbox. I attempted the code below, but it didn't work as expected. I suspect that the issue lies in not having any value in my textbox. If anyone has a solution for achieving this, please ...

CSS Flexibility in Action

Presently, my tab bar has a fixed look as shown here: https://codepen.io/cdemez/pen/WNrQpWp Including properties like width: 400px; etc... Upon inspecting the code, you'll notice that all the dimensions are static :-( Consequently, I am encountering ...

The component is not responding to list scrolling

Issue with Scroll Functionality in Generic List Component On the main page: <ion-header> <app-generic-menu [leftMenu]="'left-menu'" [rightMenu]="'client-menu'" [isSelectionMode]="isSelectio ...

instructions on implementing Arial Black font style in LESS

Using less-1.7.0.min.js, I encountered an issue when setting Arial Black as the font. @fontFamily: Arial Black,Arial Black,Gadget,sans-serif; Upon generating the CSS, it resulted in: p, span { font-size: 14px; font-family: Arial #000000, Arial #000000, ...

Setting an error state on the parent div of a checkbox

I am facing an issue with styling a standard HTML checkbox when it is in an error state. Since it's not possible to style the checkbox directly, I am attempting to apply the styling to its parent div instead. Consider this example: <div class="fo ...

What is the best way to ensure that cards are uniform in height across all screen sizes while keeping the footer pinned to the

When I click on the card tabs, the entire page shifts due to differences in height. I attempted to adjust the size of the cards, but this approach resulted in white space below the footer and did not display correctly on mobile devices or screens of varyin ...