What is the best way to create a transparent div with display:inline-block property?

Is there a way to handle dynamic content width without resorting to using min-width? Check out my jsFiddle for an example. Case 1 demonstrates the desired outcome regardless of content width, while Case 2 shows what happens when the content is too short.

#container {
    width:200px;
}
#div1 {
    display:inline-block;
}
#div2 {
    display:inline-block;
}
#div3 {
    clear:both;
    display:inline-block;
}

You can view the jsfiddle here.

Answer №1

If you want to handle different browser versions, one option is to utilize the display: table-cell property:

#container {
    width:200px;
    background-color: #ddd;
}
#div1 {
    display:table-cell;
}
#div2 {
    display:table-cell;
}
#div3 {
    display:inline-block;
}

You can also achieve the desired layout by manipulating floats:

#container {
    width: 200px;
    background-color: #ddd;
}
#div1 {
    float: left;
}
#div2 {
    float: left;
}
#div3 {
    clear: both;
    float: left;
    background-color: yellow;
}

Check out this link for an example using the table-cell method, and this link for an example using floats.

Answer №2

Is it necessary for the content div to be displayed as an inline-block? Transforming the content div into a block level element could potentially resolve this issue.

display: block;

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

Manage numerous canvas animations

Is there a way to interact with an already drawn Canvas animation? I am attempting to create 3 distinct tracks that can be controlled by a "Start" and "Stop" button. However, when I click the Start button on the first canvas, it triggers the last canvas in ...

Using plain JavaScript (without JQuery) to specify the AJAX content type

I have been working on form submission using AJAX with plain JavaScript, without any external libraries. However, I encountered an issue where the PHP doesn't seem to parse the data correctly when I try to parse the form. After doing some research o ...

Design of web pages, Cascading Style Sheets

I want to add another table next to my dataGrid, floating to the left of it. Like this representation in the main div: | | | | A | B | | | | Here, A represents the current dataGrid containing all user information, and B will be the ...

Employing the GET method to retrieve the values of two text inputs

I'm struggling to retrieve the values from two text input fields: <form action="search.php"> <input type="text" name="q1"> <input type="text" name="q2" > <input type="submit" name="submit" value="Search" /> </form> On t ...

Issue with Font-Awesome icons failing to display properly when using the BootstrapCDN

Trying to integrate Font-Awesome icon fonts using the BootstrapCDN link with what seems like the latest version: <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet"> The link has been added to the <hea ...

It is not possible to trigger an input click programmatically on iOS versions older than 12

Encountering a challenge in triggering the opening of a file dialogue on older iOS devices, particularly those running iOS 12. The approach involves utilizing the React-Dropzone package to establish a dropzone for files with an added functionality to tap ...

What is the best way to prevent the content within a div from being obscured by a sticky element affixed to the bottom of the div?

I am struggling with ensuring that the content in my wrapper does not get cut off by the "view more" div attached to the bottom. The default wrapper cuts off the children, and even when expanded, the issue persists due to CSS problems. In React, the gener ...

I have expanded the CSSStyleDeclaration prototype, how do I access the 'parent' property?

I have developed some custom methods for CSSStyleDeclaration and implement them like this: A_OBJECT.style.method() ; The code structure is quite simple: CSSStyleDeclaration.prototype.method = function () { x = this.left; ..... etc } Here's my que ...

Issues with the proper display of Bootstrap 4 in Django are causing problems

I am currently in the process of setting up Django to work with Bootstrap. Despite my efforts, I can't seem to get it functioning correctly and I'm unsure of where I may be making a mistake. Initially, I am just trying to display a panel. You can ...

Issue with uneven spacing on both ends of the screen on mobile devices

I have successfully used a <div style="margin:0 auto; "> tag with the specified property, working perfectly. However, I added another <div> above and set the float as follows: .gallery-div{ background:url(images/gallery-bg.png) repeat-y; ...

Angular JS Tab Application: A Unique Way to Organize

I am in the process of developing an AngularJS application that includes tabs and dynamic content corresponding to each tab. My goal is to retrieve the content from a JSON file structured as follows: [ { "title": "Hello", "text": "Hi, my name is ...

Develop a gallery similar to YouTube or Vimeo

Is there a way to display a collection of SWF movies in a single DIV, with one SWF already set as the default? Something like a photo gallery but for SWFs. I would like to implement this using JQuery. Any suggestions or tips on how to achieve this? ...

Logging client side errors to the server with AngularJS exclusively

Hey there, I'm a beginner in angularjs and I am trying to figure out how to create a client-side error/exception logger (.log/.js) file that sends data to the server using only angularjs. I prefer not to use jquery for this particular task. Any assis ...

Change the color of the status bar icon in cordova to create the opposite effect

Looking to modify the color of the icons and fonts on my status bar. Similar to the design on Soundcloud... I was able to change the background to white, but now the icons blend in because they are also white Example of Soundcloud's status bar Statu ...

Unable to view Bootstrap Icons in Gulp 4

I recently integrated the new bootstrap icons npm package into my project using Gulp 4, the latest version. Everything was installed successfully and was working smoothly. However, I encountered an issue when trying to declare the icon in my index.html fi ...

Chosen selection is yielding tag instead of text value

Having an issue with my bootstrap select element <select id="createAxiomSelect" class="form-select"> <option selected vale="true">True</option> <option value="false">False</ ...

The :hover pseudo-class in CSS is not functioning properly in Internet Explorer version 7

I've been struggling with the :hover pseudo-class in CSS. This is how I'm using it: tr.lightRow:hover { color:red } Everything works perfectly in Safari and Firefox, but unfortunately it's not functioning in IE7. Any suggestions or tr ...

Employing Modernizr along with jQuery for Animation in Cases when CSS3 Transitions are Absent

Can Modernizr and jQuery be combined to create a transition effect similar to CSS3 if it's not supported? My current approach looks like this... <div class="hoverable"> <p>This div changes both width and height on hover</p> </di ...

Unable to modify the focus outline for .custom-control-input within Bootstrap 4

After spending countless hours attempting to change the focus outline color of the custom bootstrap controls, I have hit a roadblock. Changing the background is a breeze with: .custom-control-input:checked~.custom-control-indicator { background-color: re ...

What is the most efficient method to use JavaScript to conceal unnecessary options?

I'm working with an HTML select element that has multiple options, and I need to be able to hide and show specific options as needed. Here's an example of my HTML code: <select> <option value="0">A</option> <option value="1" ...