Percentage-based height is malfunctioning across all browsers when utilizing bootstrap framework

I have provided my code below. How can I effectively use percentage height?

<div class="container" >
    <div class="row">
        <div class="col-" id="t1"></div>
    </div>
</div>

Css

body{
    background-color:aquamarine;
}
#t1{       
    height:100%;
    border:1px solid brown;
}

When setting height:100px; everything works fine, but when using height:100%; it doesn't work as intended.

How can the height be set in percentage using bootstrap for each div?

https://i.sstatic.net/fAjNr.jpg

https://i.sstatic.net/AxwZh.jpg

Answer №1

If you're looking to adjust the height of an element, consider incorporating something like style="min-height: 70vh;

The term "vh" in this context represents viewport height. Therefore, specifying "70vh" translates to 70% of the viewport's height.

For additional methods to manage height utilizing Bootstrap classes, check out the following resource:

https://getbootstrap.com/docs/4.0/utilities/sizing/

Answer №2

Avoid using vh as it is based on the viewport of the device, not the parent container you may be working with. Instead, consider using height, which is relative to the height of the parent element. Always ask yourself, "100% of what?" when setting height: 100%;, as this refers to the height of the parent element.

To ensure consistency, assign a unit value such as px, em, or even vh to the parent's height.

Understanding these concepts can be complex, so referring to the CSS spec is highly recommended for further guidance.

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

What is the best way to maintain a div centered when the browser window shrinks smaller than the div's dimensions?

Is there a way to keep a div centered and create white space around it when the browser window is resized? I want this effect to happen whether the browser window gets larger or smaller. Currently, when the window size decreases, the left side of the div l ...

Ways to display sneak peeks of preceding and succeeding images within a carousel using Bootstrap 5

I am looking to achieve a carousel effect where the previous and next images partially show on either side of the central image, similar to what is shown in this example: https://i.sstatic.net/HahbP.png Below is the code snippet. <div class="c ...

Customize the background color of selected date in MUI DatePicker 6.19.7 with sx styling

Looking to update the color of a specific element highlighted by an arrow using sx{} DatePicker <LocalizationProvider dateAdapter={AdapterDayjs}> <DatePicker className={styles.picker} ...

the jQuery event is triggered every time the modal is opened

I am facing an issue with a bootstrap modal form that includes a list of items to be tracked. There is a toggle all checkbox that selects or deselects all items in the list. Strangely, the jquery function is being called multiple times when I open the moda ...

Provide spacing on the sides for a background position

Is there a way to evenly space my background image with 10px margins on all sides instead of just the left side? Currently, it's only working on the left side. .login-page { display: flex; flex-direction: column; background: url("../src/As ...

Adjust padding of radio button labels in Qualtrics for a cleaner, more streamlined appearance

As I delve into the world of CSS, my goal is to customize the existing survey theme known as "Minimal 2014". Specifically, my focus is on minimizing the spacing in various areas to create a more compact design. So far, I've successfully reduced the g ...

Changing a URL parameter based on the element's width is a simple task when

I'm trying to display elements on a page by replacing a string in the URL parameter with the width of each element of a certain class. I'm new to JavaScript, so any help would be appreciated! Here's an example of the HTML for objects on the ...

Arrange elements with Material-UI's Grid system

Check out my codesandbox example (here) showcasing how I have set up my current app with Material-UI grid. I have 5 components that need to be positioned in a specific way for different screen sizes. For screens sized lg and above, I want the components t ...

The background image in CSS fails to display on IE11 when applied to a pseudo-element with the position set to fixed

Check out the issue showcased in JSfiddle: https://jsfiddle.net/qjtbchpu/11/ <div id="container"> <article> content here </article> <article> more content here </article> </div> #container::before { ...

Is there a way to ensure a table created with CSS display: table adheres to a specified minimum height?

Using display: table, display: table-row and display: table-cell, I am dealing with a large number of rows in a table and utilizing AngularJS ng-repeat to populate them. Although the example shows just two rows, in reality there are many more that all need ...

What is the method for setting an image to stretch and fill the divided screen?

I'm having trouble getting my image to fill the screen correctly on a split screen. The top half of the screen has an image, while the bottom half has text. No matter what I do, there always seems to be a blank space either at the top of the image or ...

Z-Index not functioning as expected

I've been trying to position my <h1> header on top of a light div with a background image called light.png. I used Z-index to stack them and added position:relative, but for some reason, the <h1> is not showing above the <div class=ligh ...

Continuously I am being informed that the value is null

Check out this code snippet: var Ribbon = /** @class */ (function () { function Ribbon(svg) { // Code here... } Ribbon.prototype.init = function() { // Initialization code here... }; Ribbon.prototype.updateR ...

Troubleshooting problems with CSS borders and margins in the anchor element

Having a peculiar box-model issue here. My header is filled with links, but despite setting 0px margins, the links are displaying with 2px margins around each one. To demonstrate the problem, I've created a test page located at . Ideally, each link i ...

The appearance of an SVG image inside an absolutely positioned div varies between Firefox and Chrome

The web page I am working on can be found at the following link: This webpage consists of text and SVG images, with the hex bolts positioned over specific areas of the text. Achieving this effect requires absolute positioning within a relatively positione ...

Handling onMouseLeave event for Popover component in material ui library with hiderBackdrop parameter specified

<Popover key={element.id} className={classes.popoverItem} classes={{ paper: classes.paperElement }} open={isOpen} anchorEl={this.myRef.current} anchorOrigin={{ vertical: 'bottom&apo ...

What is the best way to conceal a bootstrap directive tooltip in Vue.js for mobile users?

Currently, I'm tackling a project with Vuejs and Laravel. There's a tooltip directive incorporated that relies on Bootstrap's functionality. Check it out below: window.Vue.directive("tooltip", function(el, binding) { // console ...

CSS absolute positioning not functioning as expected

I am experiencing an issue with positioning child elements within a parent element. The parent element is relatively positioned, while the two child elements are absolutely positioned to be in the top left and top right corners. However, despite having exp ...

Modifying CSS property values by handling a returned validation error

Allow me to describe a scenario I've created. Please excuse any language errors in my explanation. I have designed a form for users to submit values. Within this form, users can choose an option - one of which is "Others specify...". When this option ...

Is it possible to gradually open or close a div element?

Looking for a way to add an effect to the code below that opens/closes a div on mouseover above an image. Any examples or suggestions? I'm not exactly a javascript expert. HTML: <div> <div class="under"><img src="http://oi60.tinypic.c ...