Unable to modify div height once Layout has been applied

On my razor view web page, there is a div element where I dynamically populate data in various ways like lazy loading or looping.

If I do not use a layout, for example:

@{
        Layout = "_Layout";
    }
    

Then the div will adhere to my specified height and display a scrollbar if necessary with overflow: auto.

However, when I introduce a layout, even an empty one, I find that I am unable to alter the height of the div, causing it to stretch from the layout to the bottom of the screen without any scrolling capability.

What is preventing me from changing the height?

(the div where I load data into has id container)

index.cshtml:

... (Content continued)

_Layout.cshtml:

...

Empty _Layout.cshtml: (also encountering issues with this layout)

...

Generated page (Using the empty layout):

...

Visual representation of current output and desired outcome: (Note: Placeholder representing AJAX call results shown within gray box) https://i.sstatic.net/keeKO.png

Generated code after incorporating @section and @style, excluding redundant elements from layouts:

...

Answer №1

It's recommended to utilize sections for managing styles, scripts, and more within the layout. The head and body tags should only be included in the layout page.

Example of an Empty _Layout.cshtml:

<!DOCTYPE html>
<head>
    <style>
        .main-header {
            background: url(/images/bg-header.png) transparent repeat-x 0 0;
        }
    </style>
    @RenderSection("Styles", required: false)
</head>
    <body>
        <div>
            @RenderBody()
        </div>
        @RenderSection("Scripts", required: false)
    </body>
</html>

Sample Index.cshtml:

@{
    Layout = "_Layout";
}
@section Styles {
<style>
    table, th, td {
        border: 1px solid black;
        border-collapse: collapse;
        width: 100%;
    }

    th, td {
        padding: 5px;
        text-align: center;
        width: 15%;
    }

    .Good {
        background-color: green
    }

    .Bad {
        background-color: red
    }

    #container {
        background: #eee;
    }
</style>
}

<div>
    <div>
        <h3 id="Progression"></h3>
    </div>
    <div id="container" style="width: 100%; height: 80%; overflow: auto;">

    </div>
    <div id="progress" style="display: none; height: 20%">
        <h4>Loading...</h4>
    </div>
</div>  
@section Scripts {
        <script src="/JQuery/jquery-3.3.1.min.js"></script>
}

UPDATE

A modification is needed as follows:

<div id="container" style="width: 100%;height: 155px;overflow: scroll;display: block;">

Using a percentage for height requires adding position:absolute;. For just the vertical scrollbar, use overflow-y:scroll;.

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

jquery does not reset trigger for menu navigation

At the moment, I am using a script that enables a button to toggle a menu open and closed, while also changing its class to create a simple animation effect depending on whether it's open or closed. It's a straightforward yet effective method. $ ...

Separate the selected option in the TEXTAREA by commas to make it easier to

Can you assist me with integrating this example? I have the following elements: When adding a textarea, I require an option to be selected and separated by a comma. For instance: Here I will select an option: Subsequently, this chosen option must be ad ...

Toggle the visibility of an element with a single button click

Below is a snippet of my sample code: SAMPLE HTML CODE: <ul> <li class="item"> item 1 </li> <li class="item"> item 1 </li> <li class="item"> item 1 </li> <li class="item"> item 1 </li> <l ...

I am consistently finding a class in my program, but when I try to locate the same class in the HTML, it seems to be non-existent

Here's the issue: when I manually search for a class = "warn," it only finds it if the seller does not have the card. This is because the text indicating that the card is unavailable has that class. However, the code below always returns TRUE even if ...

Troubleshooting problem with RadEditor rendering (LI)

I'm experiencing an issue with Telerik RadEditor specifically in IE (not Firefox, Chrome, or Safari). It seems like there may be a conflicting css style causing the problem, but I'm not sure which one it is even after deleting several styles. I h ...

How to access a separate database's Javascript library in XPages resources

Is there a way to import the javascript library from another database (content.nsf) into my current xpages database resources? I am trying to load the common.js file using the code below but it's not working. Can someone please help me correct it? &l ...

Strategies for creating smooth transitions for elements using CSS transformations

Is there a way to smoothly fade in edits to elements in CSS when hovered over? I am looking to change the border from solid to dotted, but want the transition to be gradual. How can this be achieved? UPDATE: To provide more context, here is the current c ...

Navigating React Router: Updating the page on back button press

Looking for a solution to a persistent issue. Despite various attempts and exhaustive research, the problem remains unresolved. Here's the situation: Within my React-Router-Dom setup, there is a parent component featuring a logo that remains fixed an ...

The data model is missing during a postback on Razor view in MVC4

I need help with retrieving model data from a Razor view in my controller during postback. Currently, I am getting a null value for the model data. Can anyone guide me on how to correctly obtain the data from the view on form submit? Here is my current co ...

Having trouble with CSS messing up your gridview button display?

Oddly enough, whenever I place buttons inside a gridview, they end up looking very small (as shown in the image below), even though the gridview itself has no CSS applied to it. Is it possible that some other CSS is affecting the buttons? I have too much ...

Preventing default behavior in a JQuery post request

Encountering an issue with jQuery functionality on a mobile device. function send() { $.post("scripts/post.php", { username: $("input[name=username]").val(), password: $("input[name=password]").val() }, function(data) { if ($(".data div" ...

Tips for choosing a sibling element on hover using CSS

I'm having trouble figuring out how to make the rect element change color to purple when the text is highlighted. Right now, only the text color is changing. Is there a way to achieve this using just CSS? The goal is for the rect to turn purple on ho ...

Tips for changing the style ID depending on the variable value

Currently, I am exploring the possibility of switching CSS styles using jQuery through a simple if condition. Is there an easy method to switch styles based on IDs? In my case, I have two CSS blocks each with different IDs. Here is an example: <style ...

Tips for inserting a button under a div when clicked

I am working on a layout where I have several div cards aligned side by side using the display: inline-block property. What I want to achieve is that when I click on a card, a button is added below the respective div. To accomplish this, I tried using jqu ...

Why isn't the image utilizing all the available space?

I'm working on creating a simple card to display services, with just an image and some text. However, I'm facing an issue where the image is not taking up the full width and height of the container as expected. Could someone help me figure out w ...

In what way does Angular incorporate _page-theme.scss assets?

The Angular Material Documentation homepage includes a specific scss file: https://github.com/angular/material.angular.io/blob/master/src/app/pages/homepage/_homepage-theme.scss Although this scss file is not directly imported into the component's ...

Are you looking to present information through indexing?

Currently, I am working on codeigniter and facing an issue while trying to display data from the backend onto the view files. Below is the snippet of my code: $result = $obj->get_details(); if ($result[0]) { for ($i=0; $i<count($res ...

Tips for monitoring a field within an angularJS factory

Within my web application, I am utilizing a factory. This factory contains an object named mapLayers. Within my controller, I am assigning this factory.mapLayers object to a variable on the scope called $scope.mapLayers and using ngRepeat to iterate over i ...

Determine whether the user is scrolling the window or clicking using jQuery

Is there a way to detect scrolling or clicking using jQuery? While I can monitor these events individually (scroll or click on the page), how can I ensure that if either of them occur, the user is able to proceed to the next step? ...

Tips for switching the status of each item as I navigate the page with the tab key

I am facing an issue with my list of items that have hidden content appearing on hover. I want to achieve the same functionality while tabbing through my page, but currently, all hidden content appears at once. Check out a live example of my code here jQ ...