The child div extends outside its parent div when using inline-block with the nowrap property

.containerdiv{
white-space: nowrap;
}

.childdiv{
display : inline-block;
}

<div class="containerdiv">
   <div id="child1" class="childdiv"></div>
   <div id="child2" class="childdiv></div>
</div>

I have set the CSS above to prevent the child divs from wrapping. However, I am facing an issue where "child2" is exceeding the width of its parent container due to varying widths specified in "child1". How can I make sure that "child2" does not exceed the maximum width of the parent container without calculating and manually setting the value? Your assistance is greatly appreciated. Thank you.

Answer №1

If you're aiming for maximum happiness, consider using the inline-block property and keep your fingers crossed for good luck.

However, be wary that if the content is too wide, it may force the inline-block element onto the next line.

POTENTIAL SOLUTIONS

#containerdiv {overflow:auto;}/*implementing the clear fix*/
#containerdiv>div {float:left; width:50%;}

In this setup, both elements occupy 50% of the container and any overflow issues are resolved with the auto clear fix.

You can also use inline-block at 50%, but be sure to eliminate any horizontal white space.

<div><div></div></div>

This method works effectively because there are no spaces between the elements.

<div>
<div></div><!--
--><div></div>
</div>

The above snippet functions well due to the comments removing the unwanted whitespace.

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

Tips for customizing the appearance of Google's "save to drive" button

I am currently integrating Google's save to drive API into a project and I'm interested in customizing the button provided. Despite the documentation suggesting that an element can be created and overlaid on top of the button for styling, I haven ...

Accordion Box glitch detected in Firefox browser

I have been working on a JavaScript function that controls a slide up/down box. However, I've encountered some issues with Firefox as the box only opens and closes once before failing to work properly again. Upon further investigation, it seems that F ...

Display the computed items whenever they change to prevent any duplicates from appearing

I am attempting to display items in a table each time the item list changes. I have created a function and a computed property, but I am unsure if I have implemented them correctly. Function(){ When a new value is received: changeList.push(item); } N ...

Tips for effectively showcasing div elements

https://jsfiddle.net/qz8hL574/1/ for (var key in table) { if (table.hasOwnProperty(key)) { $('<div class="element"></div>').appendTo('#list'); document.getElementsByClassName("element")[key].innerHTML = ...

The Heroku application is rendering with different CSS and positioning compared to the local development environment

My locally hosted site has correct CSS and positioning, but once deployed to Heroku, it appears to lose some of its CSS styles. I am using the MERN Stack for this project. I suspect that the issue may be related to my node_modules, even though I have them ...

The utilization of Server.Execute leads to inaccurate HTML rendering exclusively on IE9

Issue - I am encountering a problem with the rendering of a page in different versions of Internet Explorer. The page contains multiple nested div elements, and when calling server.execute within one of the child divs, the output is being displayed incons ...

What other choice do we have instead of using Angular's DomSanitizer for bypassing security and trusting HTML content?

Encountering XSS vulnerabilities while working with the IT security team during the build process. The (this.res) contains the code for embedding a video with script tags to play the video and its content. Any suggestions for an alternative solution are gr ...

Blocking Cross-Origin Requests - Interfering with .net Web API and JavaScript AJAX

My current project involves implementing Ajax to capture a submit event and then send the form elements formatted as JSON to an asp.net Web API 2. I am using the latest version of Firefox with the ad blocker disabled, and there is SSL on both the origin an ...

What is the best way to create a two-step animated progress bar using CSS animations?

Is it possible to create a two-step progress bar animation where the red bar transitions to yellow in the middle, followed by another yellow bar moving to the end? I attempted using "display: none" in the progressbar2 class, but it disappears at the start ...

Utilizing Semantic UI Grid to distribute columns and fill in blank spaces

I'm a beginner in semantic UI and I'm struggling to understand how to adjust the columns to fill in the blank space correctly. Can someone please explain how to do this? By the way, I am using the `<div class="ui grid"> <div class="fou ...

Javascript unable to update the DOM

I've been working on a project to prototype a simple functionality using JavaScript for learning purposes. However, I've encountered an issue where the contents within the <p> tag are not updating, and I'm currently stuck. Here's ...

Enable clickable elements positioned behind an iframe

I am currently working on integrating a third-party chatbot into my web application using an iframe in ASP.NET MVC. Like with any chatbot, a button is provided to start a chat (located on the right-hand side below the screen). When this button is clicked, ...

Received this unexpected error message upon reloading the page in a ReactJS application: SyntaxError: Unexpected token '<'

Every time I refresh the page, I encounter the error Uncaught SyntaxError: Unexpected token '<'. This error originates from a top-level component named <Navbar /> that I included in App.js. Oddly enough, the issue only arises upon refres ...

Various Plus/Minus Containers

One issue I am facing is that when using multiple counters on the same page, my - and + buttons to decrease or increase the number in a text box do not function properly. The script provided below works for one counter. How can I modify this code so that ...

Displaying numerous images/items in a Bootstrap 2.3 carousel

I have been working on a PHP-based website that utilizes Twitter Bootstrap 2.0. Currently, I am retrieving user information from a MySQL database and attempting to display them in separate frames or items within a carousel instead of all at once using a wh ...

Step-by-step guide on arranging/placing/styling two div elements next to each other

I'm facing an issue with my CSS and HTML. I can't seem to get the 2 footer items to display on the same line. Is there a problem with how I've structured my divs and styles? Any suggestions for improving the code are greatly appreciated. I& ...

Enable the text to wrap around an interactive object that the user can freely manipulate

Looking for a solution where I can have a floating div that can be moved up and down using javascript while the text wraps around it seamlessly. Similar to how an object positioned in a word document behaves, I want the text to flow around the div both ab ...

I'd like to display just two names from a list at a time and have the option to click on a button to reveal the next two names, unfortunately, there

I am trying to modify my code so that it only displays the first 2 items in an array initially, and then on clicking a button, the next 2 names are displayed until the end. However, the code I have written seems to have a bug. Can you help me correct this ...

Executing jQuery code when reaching a specific moment in an HTML video

I wanted to modify the video playback so that it would loop a specific portion of the video continuously while still allowing the full video to be played. For example, if the video is 30 seconds long and I want to play 5-second segment starting at 10 seco ...

Clicking on a checkbox and subsequently removing validation through jquery

Situation : When the 'I am Fresher' checkbox is selected, I want to hide the 'Experience field', but still keep its validation visible so that my form cannot be submitted. My Requirement : When the 'I am fresher' checkbox is ...