Is there a substitute for using CSS divs with display:table?

<div id="wr">
    <div id="con">
        <div id="unknownWidth">some box with unknown width</div>
    </div>
    <div id="knownWidth"></div>
</div>

#wr {
    width:300px;
    height:100px;
    border:1px solid red;
    margin:50px;
}
#knownWidth {
    width:100px;
    height:30px;
    margin:0px auto;    
    border:1px solid gray;
}
#unknownWidth{
    height:30px;
    margin:0px auto;    
    border:1px solid blue;
}

Check out this fiddle: http://jsfiddle.net/7EsMR/

Is it feasible to bypass utilizing display:table on the container of unknown width and sustain the same functionality that it provides?

It needs to be compatible with IE7, but not IE6. :D

Desired outcome: http://jsfiddle.net/7EsMR/1/

Appreciate your help ;)

Answer №1

To center the child element, you can employ a mix of using display: inline on the child itself and applying text-align: center to its parent:

Explore this example on JSFiddle

Answer №3

You might consider this approach:

#wr {
    width:300px;
    height:100px;
    border:1px solid red;
    margin:50px;
    text-align: center; 
}
#knownWidth {
    width:100px;
    height:30px;
    margin:0px auto;    
    border:1px solid gray;
}
#unknownWidth{
    display:inline-block;
    height:30px;
    border:1px solid blue;
}

This solution should be compatible with IE7 as it supports inline-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

HTML 5 drag-and-drop functionality

Looking to create a sidebar with draggable menu items, but need to prevent them from being dropped into the wrong places! Take a look at the code snippet below: <div class="sidebar" ondrop="drop(event)" ondragover="allowDrop(event)"> <div c ...

Enhance user experience by turning the entire card into a clickable element through targeting the <a> tag nested

I need to make the entire card clickable to go to a specific link, but I can't wrap the card with an anchor tag. Is there a way to target the anchor tag within the card and trigger it when the user clicks anywhere on the card using jquery? Desired ou ...

Guide on triggering a button click event to display an alert message with jQuery

I'm having trouble getting the alert message to appear. The rest of my jQuery code is functioning properly, so I assume I linked the library correctly. Could the placement of the code in the document be causing the issue? Here's the HTML: <b ...

How to retrieve the time duration in minutes between a start and end time in JavaScript to

I have conducted a thorough search on Stack Overflow and other platforms but could not find an answer to my specific question. While I did come across posts related to this topic, they did not address the issue I am facing. Problem: My challenge involves ...

Tips for visually conveying the values of x and y using SVG symbols

I recently came across a blog post discussing the use of SVG symbols for icons, which inspired me to create representations of symbols using svg files. The original svgs I used had properties like x, y, height and width. However, when I tried adding these ...

When you use JQuery to click on list items, you will be able to generate numerous results

There is a list item in the following format: https://i.sstatic.net/HMIEf.jpg HTML <ul> <li id="nav-menu-item-7" class="menu-element"> <a href="google.com">TEST 2</a> <ul> <li id="nav-menu ...

Issue with custom checkbox not changing when bootstrap collapse occurs

I've been searching for a solution and experimenting with different methods, but I just can't seem to make it work. Below is a CodePen example that showcases a custom checkbox with a toggle function to show/hide a div when checked, along with a ...

Modifying the background color using highcharts.js

I am attempting to customize the background colors of a highcharts scatter plot. While I can easily change the color of a specific section using the code provided, my goal is to apply multiple colors to different ranges within the same plot. Specifically, ...

What is the best way to customize global styles in nextJS?

What's the best approach to override CSS rules from my global.css file for specific pages within my website? ...

Tips for arranging images in a horizontal layout using FlatList in React Native

Is there a way to display feed images horizontally instead of vertically in FlatList? I've tried wrapping the images in a view with flex-direction set to row, as well as adding horizontal={true} to the FlatList, but nothing seems to work. Any suggesti ...

Achieving perfect alignment both horizontally and vertically using CSS3's viewport height of 100%

I'm trying to utilize CSS3's Viewport Height to create a fullscreen section with a height of 100vh. However, I am encountering difficulties in centering elements both horizontally and vertically within the section. My goal is to have an image and ...

Angularjs: Adding Negative and Positive Numbers

How can I extract negative numbers and positive numbers separately from JSON data obtained from the server using the $http.get method? One of the fields in the data is called Credits, which contains both negative and positive values. Can anyone help me wit ...

Filtering HTML tables to display only one instance of each value

I have a 300x11(rowXcolumn) html table that I wanted to filter like Excel or Google Sheets's filter. Upon researching, I came across the code below on a website. While it works as desired, there is an issue where it displays the same value multiple ti ...

Utilizing CSS to print specific columns on a separate page at regular intervals

I am facing a challenge with printing a very large HTML table, which is dynamic in the sense that the number of rows and columns can vary. When printing, the rows that exceed the page length are automatically continued on the next page. However, I also nee ...

Centering loaders within elements of an unordered list

I am working on a navbar that uses Bootstrap 3 and AngularJS. Within this navbar, I have an unordered list with li elements. Below is a snippet of my navbar: https://i.stack.imgur.com/o75Lp.png This is the code for my navbar: <div class="navbar-head ...

Adapting software for use with Panasonic Viera

We are in the process of transferring our current HTML/JavaScript/CSS application to the Panasonic platform. Our current setup involves using JavaScript for generating HTML and CSS for styling the application. The programming language used in the Panasoni ...

tap into adhesive, translucent screen

I designed a webpage with an iframe at the bottom that I set to be transparent so that overlapped elements are visible. However, I encountered an issue where the links beneath the iframe were not clickable unless I disabled pointer-events for the iframe. ...

I'm attempting to use Bootstrap to align my divs, but unfortunately, it doesn't seem to be working as I had hoped

I've been attempting to align divs using bootstrap, but I'm encountering issues. I prefer not to use a table for this purpose and have experimented with the table tag, but would rather achieve alignment with divs and bootstrap. My familiarity ...

Animate as you scroll down and as you scroll back up

Trying to animate a set of buttons from a relative position to a fixed position on each scroll by. HTML <div class="menu"> <button class="button"></button> <button class="button"></button> </div> CSS .button ...

Is it possible to use XPath to target an element that does not have a distinctive id

Currently, I am experimenting with Selenium and trying out new things. I attempted to create a program that automatically clicks the 'Like' button on YouTube using XPath. However, I realized that the XPath I used is incorrect. Can someone please ...