In-line divs are known for their rebellious nature, refusing to conform to traditional

I'm in need of some assistance with taming my unruly HTML. It seems to be misbehaving lately.

The content area on the page I'm currently designing has a two-column layout. Instead of using separate containing divs for each column, I opted for a different approach to ensure proper alignment of certain "rows" within the columns.

My solution involves creating multiple "rows" with two inline divs per row - one for left content and one for right. Most of them are displaying correctly, but there seems to be an issue with the last row. It refuses to cooperate when I try to set its width.

Here's a sneak peek at the relevant HTML:

<div id="mainContainer">
    <div id="topBar"></div>  //occupies full width
    <div id="featured">                        //this "row" is working fine
        <div id="featuredVideos"></div>            //these two
        <div id="featuredLiterature"></div>        //are displayed inline
    </div>
    <div id="browseButtons">                   //the problematic "row"
        <div id="litBrowse"></div>                 //these two
        <div id="vidBrowse"></div>                 //are displayed inline
    </div>
</div>

At this point, what factors could lead to a div refusing to adhere to a specified width? Despite assigning a uniform width of 450px to every child div inside litbrowse and vidbrowse1, the issue persists. Surprisingly, all the content above it, with similar structure, is functioning properly. The only discernible dissimilarity might be the use of two floating divs in the row directly above the troublesome one.


For a better understanding, you can view a jsfiddle demonstrating the problem. The bottom two divs (Browse lit by category, browse vids by category) should be spaced apart, but they stubbornly refuse to adopt their designated 450px width.

Answer №1

The issue lies in how you are defining the .browseBtn as inline. Inline elements do not have width properties, only block level elements do.

Instead, using inline-block will achieve the desired result. It maintains an inline layout to display divs side by side while also allowing for width specification.

For more information, refer to http://jsfiddle.net/abtFr/2/

Answer №2

ANOTHER PERSPECTIVE - After reviewing responses, it has been suggested to use display: inline-block instead of display: inline. Keep in mind that inline-block is not fully compatible with IE7. However, compatibility can be achieved by adding

zoom:1;
*display: inline;

to the element utilizing inline-block. To make it compatible with IE6 as well, a specified height must be included. Add

_height: [yourheight]px;

The underscore will specifically target IE6.

Another solution is floating the elements left, which may require revisiting the initial response provided.

UPDATED NOTE - My initial response was submitted prior to viewing the linked jsFiddle; therefore, this response may not be entirely relevant.

In regards to your inquiry, when an element is floated, it is removed from its standard placement within the layout. For example, if a div is floated left inside another div, it will align to the far left of that container without influencing the dimensions of the container itself. This causes the container to act as if there are no additional divs nested inside.

To resolve this issue, consider inserting another (empty) div within the container after the floated divs, and assign the style "clear: both" to ensure proper alignment and sizing. Alternatively, applying the style "overflow: hidden" directly to the container can sometimes serve as a workaround, although it is considered a less conventional approach.

We hope these suggestions address your concerns; if not, further details may be necessary for a more tailored resolution.

Answer №3

While your div is present, the display property has been set to inline using the .browseBtn definition. This means it no longer functions as a block-element and ignores the width setting.

If you'd like to see the corrected version, check out this updated fiddle, although there may be unintended consequences.

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

The Bootstrap Navbar fails to function properly when viewed on mobile devices

As a newcomer to BOOTSTRAP 5 and web development in general, I am currently working on creating a simple website using it. I have added a navigation bar, but when I switch my browser to mobile mode, the dropdown menu doesn't work properly and all the ...

Loading Kendo JS on the client side proves to be rather time-consuming

Working on my project, I have encountered a problem with the kendo ui scheduler where the downloading of the kendo js and css files on the client side is causing slowness on our website. To address this issue, we are attempting to download the kendo js and ...

Is there a way to remove text from a div when the div width is reduced to 0?

Upon loading the page, my menu is initially set to a width of 0px. When an icon is clicked, a jQuery script smoothly animates the menu's width to fill the entire viewport, displaying all menu items (links) perfectly. The issue I'm facing is that ...

display a loading spinner for number input fields in HTML5

In my HTML5 project, I am currently utilizing a numeric control (input type="number"). The default behavior displays the spinner (up and down arrows) only on hover. Is there a way to make the spinner permanently visible using CSS or another method? ...

Understanding the process of extracting HTML tags from an RSS feed using Python

I am looking for a way to create a plain text readout of an RSS feed using a small utility. Below is the code I have: #!/usr/bin/python # /usr/lib/xscreensaver/phosphor -scale 3 -program 'python newsfeed.py | tee /dev/stderr | festival --tts' ...

Replacing HTML text with JSON data can be easily achieved by using JavaScript

After receiving data from an API and converting it into JSON format, I encountered difficulty when attempting to change a selected element in HTML. Every time I tried to do so, I either got 'undefined' or 'Object Object' as the output. ...

Whenever I attempt to display certain HTML files in Django, I encounter an error message stating: "NoReverseMatch at / Reverse for 'it_languages' not found."

Every time I attempt to display a HTML file in my Django project, an error pops up preventing me from accessing the localhost page. The exact error message I receive is: The error is: NoReverseMatch at / Reverse for 'it_languages' not found. &apo ...

Change the Bootstrap components according to the size of the screen

Is there a built-in Bootstrap feature to change an element's class based on screen size? I'm working on a webpage with scrollable card elements. On desktop, the cards are arranged horizontally, but on mobile they are stacked vertically, requirin ...

Refresh the content of a webpage in AngularJS without the need to fully reload the entire page

Within my controller and view files, I have content that is sourced from various places, including API calls. For instance, I have information retrieved from the database where users can update certain details like their last name. After submitting the up ...

Can cells be divided in a Material UI table?

Is there a way to split a cell in a Material UI table?I am aware that I can create a component to achieve this, but I'm wondering if there is another approach that I may not be aware of. Splitting a cell means having two values separated by a line wit ...

The inefficiency of invoking Jquery on elements that do not exist for the purpose of caching

What is the impact if JQuery attempts to access elements that do not exist? Will there be any significant CPU overhead other than script loading? Does it matter if this is done for a class or an id? For optimization purposes and to minimize simultaneous c ...

The email validation UI dialog is failing to display any dialog

<html> <head> <link rel="stylesheet" href="//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css"> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"& ...

The appearance of my website appears differently depending on the resolution

Just recently, I began exploring the world of HTML/CSS/JS and created a handy tool for my personal use. However, I encountered an issue when viewing it on different resolutions which caused some elements to look distorted. The tool I made allows me to inp ...

What is the best way to navigate my Page while my Dialog Component is displayed?

Is there a way to enable scrolling on the background when a dialog component opens up? By default, scrolling is disabled when the dialog appears. How can we allow scrolling in the background? Here is the code snippet: import React, { useState } from &apos ...

Searching for a specific text within a column and displaying only the matching parts

My current dataframe has the following structure: RandomCol raw blah <div style="line-height:174%;text-align:left;font-size:9pt;"><font style="font-family:inherit;font-size:9pt;font-style:italic;font-weight:bold;">We ...

Custom field data in WordPress

I'm having difficulty formatting the prices of certain products using a custom field (unit_price). The value is 3.2, but the code only displays 3 because it doesn't recognize commas or dots. Is there a way to display the full value? any assistanc ...

A miniature triangle-shaped bubble crafted with 1px of CSS3 styling

Currently, I am experimenting with CSS3 and creating bubble shapes. However, I have encountered an issue. I am trying to create a triangle with a 1px border, but the result is a thicker triangle than desired. You can view my code on this fiddle : FIDDLE ...

When the jquery loop fails to function

I need to dynamically add a class to a specific tag using jQuery depending on an if condition. Here's the code snippet: if ($(".asp:contains('Home')")) { $("ul.nav-pills a:contains('Home')"). parent().addClass('active ...

When using a custom selection color to highlight underlined text, the underline becomes invisible

I am currently working on a website where I want to customize the text selection color. ::selection { background-color:#00ffff; } However, there seems to be an issue in this specific situation: p::after { content:"Try selecting the above elemen ...

The image appears fuzzy until you hover over it and it transforms into a larger size

Encountering a strange issue with using the zoom property on an image during hover state. The image seems to be blurry before and after the scale transition, but surprisingly sharp during the actual transition. Any tips on how to prevent this blurriness in ...