Dynamic content displayed within adjacent div elements

I am currently working on a project where I am dynamically generating an outline by creating panels and labels in ASP.NET. Each node in the outline is defined by an outline number and outline text, which are obtained from a database that defines the relationship between children and parent nodes to create the outline tree structure. For each entry in the outline, I want the left div to display the outline number, and the right div to display the outline text.

The left div should have a specific minimum width, like 50px, and should expand if necessary to accommodate larger outline numbers. Sometimes the outline number might be "Section VI.", so all outline number divs should be the width of the largest required to support the largest outline number.

The right div should wrap the text if the container or window constraints prevent the text from appearing on a single line.

*--------------Window or container----------------*
|Part I.    A small amount of outline text.       |
|   Section. I  A larger amount of text is here   |
|               showing text wrapping in its own  |
|               block.                            |
|Part II.   More text here with a little wrapping |
|           going on.                             |
|Part III.  A little bit more text.               |

I have tried various combinations, but since I am new to using divs, constructing layouts has been a challenge. Most of the methods I have found are very specific to a particular layout and not easily adaptable to other designs, or they rely on specific sizes for the divs.

Since I am generating this dynamically, I do not know the amount of text that will be displayed until runtime. Therefore, using fixed sizes and absolute positioning is not a feasible option unless I perform extensive calculations and string measurements, which I am unsure how reliable that would be. I am concerned that there may be inconsistencies between the measurements done by .NET and how browsers actually render the text.

While this is not a critical requirement, using fixed sizes would prevent the text from filling new space when resizing the outer container or window. Additionally, reducing the size of the container or window may not allow the text to wrap appropriately and could result in the creation of a scroll bar instead.

Currently, I have a panel for the outline number containing a label assigned a CSS class, a separate panel for the outline text with its own CSS class, and both are placed into a panel with a dynamically set left margin based on the indentation. I can replicate almost anything shown in HTML markup using divs, but it is important to consider that the content is driven by the database and does not have a predetermined width.

If you believe that creating a two-column table for each entry is a better approach, I would appreciate hearing your opinion.

As an attempt, I explored a few different approaches:

http://www.alistapart.com/articles/holygrail/

However, I encountered issues where the outline number would wrap or overlap the other div depending on adjustments made. Ideally, the left column should expand to accommodate the content, and it should not wrap or overlap other text. It is acceptable for the indentation to vary slightly for unique cases where the outline number is too long.

Another challenge I faced was determining the font used, as it is defined in a .css file. During page load, I am uncertain how to ascertain the font to accurately measure the rendered width of the string.

One of the last methods I experimented with involved the outline number wrapping and overlapping the content to the right:

<div id="container">  
  <div id="center" class="column">Application Information blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah </div>
  <div id="left" class="column">Part VVVVVVVVVVVV.</div>
</div>

#container {
  padding-left: 50px;   /* LC width */  
}

#center {
  width: 100%;  
  position: relative;
  float: left;
}

#left 
{
  position: relative;
  float: left;

  width: 50px;          /* LC width */
  right: 50px;          /* LC width */
  margin-left: -100%;
}

Answer №1

In situations like this, I would suggest avoiding the use of divs.

Instead, consider using nested <dl>'s

<dl>
  <dt>Part I</dt>
  <dd>A brief outline of the text.
    <dl>
      <dt>Section I</dt>
      <dd> More detailed text is displayed here
           with its own block formatting.</dd>
    </dl>
  </dd>
  <dt>Part II</dt>
  <dd>Additional text with some formatting.</dd>
  <dt>Part III.</dt>
  <dd>A bit more text.</dd>
</dl>

This will give you default styling similar to what you desire. To achieve a side-by-side layout, you may need to add the following CSS:

dt { float: left; clear: left; }

This CSS will align the dt's (titles) to the left and allow the dd's to float to the right without interfering with other dt's.

Additional Note:

After revisiting this, I have refined the CSS to demonstrate the versatility of the <dl> element.

CSS:

dt { float: left; clear: left; margin-right: 10px; font-weight: bold; }
dd { margin: 0; padding: 0; overflow: hidden; }

HTML:

<dl>
  <dt>Part I</dt>
  <dd>A brief outline of the text.
    <dl>
      <dt>Section I</dt>
      <dd> More detailed text is displayed here
           with its own block formatting.</dd>
    </dl>
  </dd>
  <dt>Part II</dt>
  <dd>Additional text with some formatting.</dd>
  <dt>Part III.</dt>
  <dd>A bit more text.</dd>
</dl>

I have enhanced the style of the <dt>'s for better readability. The zero margin and padding on the <dd> elements, along with overflow: hidden, prevent layout issues at smaller sizes and ensure the text does not wrap under the <dt>.

View this jsFiddle for immediate visual results.

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

Using Xpath to target elements based on attributes and retrieving the values of another attribute

I am trying to extract the datetime attribute value from each li element that contains an attribute type with the value of standard. However, my current code is resulting in an error. Here is the snippet: <li datetime="2019-06-03T14:45" offset="-135" t ...

"Troubleshooting a Stream Problem with the JSON HTTP Module

I have a custom HTTP Module that I utilize to sanitize the JSON response from my web service. This is particularly useful when making cross-domain JSON web service calls from JavaScript. You can check out an example of this implementation at this link. Th ...

Creating a dynamic CSS height for a div in Angular CLI V12 with variables

Exploring Angular development is a new venture for me, and I could use some guidance on how to achieve a variable CSS height in Angular CLI V12. Let me simplify my query by presenting it as follows: I have three boxes displayed below. Visual representatio ...

Difficulties encountered when trying to store a checkbox array data into a database

Within my application, I am faced with the task of extracting checkbox items from a list and storing them in my database. Currently, I am assembling these items into an array by iterating through the options, adding a checkbox before each one, and assignin ...

"JavaScript that doesn't rely on a specific browser

Why does this code behave differently across browsers? What modifications are needed to ensure consistent behavior in all of them? In Firefox, it functions correctly, using the URL /some/path/?searchedText=sometext. However, in IE, nothing happens when cli ...

Consecutive pair of JavaScript date picker functions

My issue involves setting up a java script calendar date picker. Here are my input fields and related java scripts: <input type="text" class="text date" maxlength="12" name="customerServiceAccountForm:fromDateInput" id="customerServiceAccountForm:from ...

I keep receiving an error message that says "The MIME type 'application/json' is not executable." Can anyone explain why this is happening?

Encountering an issue because the MIME type of this file ('application/json') is non-executable and strict MIME type checking is turned on. I am working on incorporating a map into a website and have obtained a JSON file containing coordinates. ...

In a remarkable design with an array of buttons and an individual div assigned to each, a fascinating functionality unfolds. Whenever a

https://i.stack.imgur.com/emhsT.png When I click on the first "Respond" button, I want the adjacent text box to disappear. Currently, if I click on the first "Respond" button, both text boxes will disappear instead of just the first one. $('.comment ...

Adjust the width of Google chart to 100% automatically when the page is resized in Angular version 4 or higher

My application has numerous responsive wrappers on the site, each predefined from an API and containing a Google chart. The problem is that when the page initially loads, the charts are rendered at a specific size, and resizing the window only affects the ...

Using node.js to submit a form and upload an image

Seeking some assistance as a newcomer to node. I am trying to achieve a task without the use of any other frameworks like Express. Here is the scenario: I have created a form where users can upload photos to a server running on a node. The form contains t ...

Set the first link in a menu to be highlighted as active using jquery

In order to mark the first link in my menu as active, I need it to have specific CSS settings applied. Using jQuery to add these settings to every link when clicked on makes it a bit tricky (simple menu = clicking changes color). So, I want the first link ...

How can you identify dynamically created elements within an AngularJS directive?

I have a directive where I need to target specific DOM elements, some of which are dynamically generated in an ng-repeat loop. If I try to select them directly, I only get the static elements. However, if I delay the selection by, let's say, 500ms, I ...

Transforming a traditional HTML/CSS/JS website into a cutting-edge React application using Tailwind CSS styling

I have a unique website template complete with HTML, CSS, and all necessary assets. Now, I am looking to develop a React JS application using this template. Firstly, I am wondering: Since I typically use Tailwind CSS for my other projects, would it be mo ...

use two separate keys for grouping in JavaScript

My current approach involves using the reduce method to organize the data based on the Id of each query. var data = [ {Id: "552", valor: "50.00", Descricao: "Fraldas", }, {Id: "552", valor: "35.00", Descricao: "Creme", }, {Id: "545", valor: "2 ...

An adaptive Bootstrap grid that collapses and changes based on screen dimensions

Currently, I am in the process of creating a collapsible grid using Bootstrap to display details for each item: If you would like to see a visual representation of the concept, click here. To assist in my project, I have been referring to a helpful threa ...

What could be preventing my HTML replacement assignment from functioning properly?

Whenever a choice is made, I want to substitute the current content with different content. My current attempt is to update the content from "HuckFinn" to "Tom Sawyer will be added later" when the user selects "Tom Sawyer" from the drop-down menu. However, ...

Tips for preloading a small placeholder image before the main content is loaded

After browsing , I noticed an interesting image loading style. The website initially shows a patterned image before revealing the actual content. This method creates visually appealing content while waiting for the entire webpage to load. Upon inspecting ...

I desire to share the JSON information and receive the corresponding response data

<!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> </head> ...

Tips for ensuring a functioning dropdown menu while maintaining a fixed navigation bar position

I am facing an issue with my navigation bar. I have set the position to fixed to keep it at the top, but this is causing the drop-down functionality to stop working. Please advise on where I should move the position fixed property so that my nav bar remai ...

Styling a playbook using CSS Grid management techniques

Exciting to create a playbook layout style, here's how it goes: Name: Text starting here - unique style #1 text that moves to a new line with a different look - unique style #2 more text continuing on another new line ...