Something is off with the CSS height property

I am facing an issue with setting the height of a div inside another div. To better illustrate my problem, here is the code snippet:

.prodContent1 {
position: absolute;
background-color: #e1e1e1;
border: 1px solid #ddd;
width: 100%;
box-sizing: border-box;
height: 300px;
z-index: 1;
display: none;
}
.prod-div {
background-color: grey;
width: 20px;
height: 20px;
box-sizing: border-box;

}
<div class="prodContent1" id="prodCont1">
    <div class="prod-div">
    </div>

</div>

Despite setting both width and height to be equal, I expected the div to form a cube. However, when I checked it in the browser, all I could see was a small grey box as shown in this image: https://i.stack.imgur.com/nINmo.png

I have tried setting the height to just 1px but upon further investigation using browser measurement tools, I found that the actual height was four times more than what I had set. (Please ignore the display:none property, as this div is meant for dropdown purposes).

Has anyone ever encountered such an issue before?

Answer №1

It seems like the code you shared is functioning fine, except for the "display: none;" property which is causing it to be hidden from view. The issue may lie elsewhere in your code:

.prodContent1 {
position: absolute;
background-color: #e1e1e1;
border: 1px solid #ddd;
width: 100%;
box-sizing: border-box;
height: 300px;
z-index: 1;
}
.prod-div {
background-color: grey;
width: 20px;
height: 20px;
box-sizing: border-box;
}
<div class="prodContent1" id="prodCont1">
    <div class="prod-div">
    </div>
</div>

Answer №2

After some troubleshooting, I was able to identify the issue. It turns out that I had inadvertently created four divs with the same class. This resulted in all of them stacking up on top of each other, creating a tall square shape. It was a silly mistake on my part, but now it's fixed.

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 could be causing the lack of animation in W3schools icons?

I've followed the steps provided and even attempted to copy and paste them. However, I'm experiencing an issue where the animation doesn't fully execute. Instead of the bars turning into an X shape, they reset halfway through the animation. ...

Can the bottom border on an input textfield be removed specifically under the new character?

This is the new visual design I received: https://i.stack.imgur.com/kiQGe.png The label CLG is represented as a label, with the line being an input type=tel. Disregard the purple overlay... The designer has requested that I remove the border when a user ...

The button in my form, created using React, continuously causes the page to refresh

I tried to create a chat application using node.js and react.js. However, I'm facing an issue where clicking the button on my page refreshes the entire page. As a beginner in web development, please forgive me if this is an obvious problem. You can fi ...

Discover the best ways to repurpose an HTML page with varying jQuery/PHP code

After recently venturing into web development, I decided to create a guestbook that requires login information. Users with valid accounts have the ability to log in/out, create new entries, and edit their own content. They also have the option to change th ...

problem with the picture and wrapper expanding to fill the entire width of the screen

I'm having an issue with the image I added and its hover effect. The image seems to be leaving space on both sides of the screen, even though I've included background-size: cover and width:100% in my code. Could someone please point out where I ...

How can I extract data from a swiffy animation?

Suppose I am tracking the number of mouse clicks in Flash. To do this, I have utilized the following code: import flash.events.MouseEvent; plus.addEventListener(MouseEvent.CLICK,aaa) var i:int=0; function aaa(e:MouseEvent) { i++; var a:Number ...

Resolving the Persistence Problem of Navigation Bar Fading In and Out

I've been struggling for hours trying different methods to achieve the desired outcome, but unfortunately, none of them have worked as expected. My goal is simple: I want the fixedbar to fade in when the scroll position exceeds the position of the ph ...

Using JavaScript to implement CSS3 with multiple background images

Is there a way to programmatically define multiple background images in CSS3 using JavaScript? While the common approach would be: var element = document.createElement( 'div' ); element.style.backgroundImage = "url('a.png') 0 100%, ur ...

I would like to mention a website without inserting a direct hyperlink, for example, in the Safari browser

Is there a way to prevent a website name from becoming a clickable link in Safari? In my marketing email, I am highlighting the websites of both my client and their competitor. When mentioning the competitor's site "sitename.com," I want to avoid cre ...

When scrolling the page, the Circle Mouse Follow feature will dynamically move with your cursor

Hey everyone! I'm currently working on implementing a mouse follow effect, but I'm facing an issue where the circle I've created moves along with the page when scrolling, instead of staying fixed to the mouse. Any suggestions or tips would b ...

Send data from a PHP form with various input types using JavaScript and AJAX

I need to submit a form with various fields, including multiples checkboxes selection and some hidden input fields via AJAX and then replace the HTML content with the response. I decided to use JavaScript/AJAX for this process, but did I make any mistakes? ...

What is the best method to transfer and incorporate essays and information onto my HTML page?

Here are some unique events and observances for the month of December: DECEMBER 1 World AIDS Day National Pie Day National Eat a Red Apple Day Bifocals at the Monitor Liberation Day Day With(out) Art Day Rosa Parks Day DECEMBER 2 International Day for th ...

Curved divs display outlines on more compact dimensions

Check out this relevant Codesandbox There seems to be a recurring issue in my application where rounded divs display edges when they are of smaller sizes. Refer to the image below for a visual representation. What could be causing this problem and how can ...

Implementing full-window mask when hovering over a div

I've been grappling with creating a mask that covers an image within a div, but I can't seem to get it to cover the entire area without leaving whitespace in the middle. I've tried various solutions to fix it, but nothing has worked so far. ...

Learning the ins and outs of HTML5 and CSS3

Does anyone have recommendations for high-quality HTML5 and CSS3 tutorials? ...

Is there a Joomla extension available that can display or conceal content upon clicking?

Looking to enhance my Joomla site by installing a plugin that allows me to toggle the visibility of content with a click, similar to how FAQ sections work on many websites. Question 1 (click here for the answer) { Details for question 1 go here } Questi ...

The functionality of jQuery's .hide method is not effective in this specific scenario

HTML section <div class="navigation-bar"></div> Jquery & JavaScript section function hideUserDiv(){ $('.ask-user').hide(); } var ask = '<div id="ask-user" style="block;position:absolute;height:auto;bottom:0;top ...

Using blending modes with gradient colors in an SVG design

I'm struggling to get my logo to change colors upon scrolling into a button with similar gradient colors, but I just can't seem to make it work. Can anyone lend me a hand? Thank you! Take a look at my Logo. I've attempted to add some styles ...

Guide to populating a dropdown list using an array in TypeScript

I'm working on a project where I have a dropdown menu in my HTML file and an array of objects in my TypeScript file that I am fetching from an API. What is the best approach for populating the dropdown with the data from the array? ...

Can CSS be used to generate these shadows?

Check out this image I made showcasing a board with an elongated shadow cast behind it. The intention is to emulate the look of the board leaning against a wall, resulting in a triangular shadow on either side. I'm curious if it's achievable to ...