Creating a responsive design with dynamic width using HTML and CSS to handle overflow situations

Struggling to figure out how to achieve this in html, I would like the solution to be limited to just html + css. Javascript/jquery is being utilized on the site, yet I don't want my design to rely on javascript.

Section A contains a list of variable width items pulled from a database, ranging from 9em-15em wide. Section B also has overflowing text. My goal is for A to adjust its width based on content and for Section B to take up any remaining space available.

Is there a way to make this work? Any recommendations for books that could help me build a strong foundation in html+css would be appreciated!

---------------------------------------------
|          |^|                             |^|
|          | |                             | |
|          | |                             | |
|          | |                             | |
|    A     | |             B               | |
|          | |                             | |
|          | |                             | |
|          | |                             | |
|          | |                             | |
|          | |                             | |
|          |v|                             |v|
----------------------------------------------

The current setup I have causes issues when Section B overflows, resulting in "A" shrinking and the divs going onto two lines, which is not acceptable.

<div id="SectionA" style="float:left">
 <div>Just TEst data</div>
 <div>Just data</div>
 ...
 <div>Just data</div>
</div>
<div id="SectionB" style="float:left">
  <!-- A bunch of content here -->
</div>

Answer №1

Consider viewing it from a different perspective:

<div id="SectionB">
 <div id="SectionA">
  <div>Just Test data</div>
  <div>Only information</div>
  ...
  <div>Simply details</div>
 </div>
 <!-- Plenty of content goes here -->
</div>

div#SectionA {max-width:15em; float:left;}

div#SectionB {width:100%;}

This method is expected to function perfectly

Answer №2

    <div id="SectionX" style="float:right;width:auto;max-width:200px">
 <div>New Test information</div>
 <div>Updated data</div>
 ...
 <div>More updated data</div>
</div>
<div id="SectionY" style="float:right;width:auto;max-width:200px">
  <!-- Additional content goes here -->
</div>

Possibly this solution may be effective

Answer №3

<style>
#sectiona{
float:left;
overflow:auto}
#sectiona>div{
white-space:no-wrap}

</style>

<div id="sectiona" style="float:left">
 <div>This is only a test</div>
 <div>Just some random data</div>
 ...
 <div>More data here</div>
</div>
<div id="sectionb" style="float:left">
  <!-- There is a lot of content in this section -->
</div>

I believe this setup should be effective.

Although, your diagram indicates that the columns should have equal height which can be difficult to achieve with just css.

Answer №4

It appears that your approach might necessitate individual scrollbars for each section, reminiscent of frames in older versions of HTML. To achieve this, you would need a parent container div for both sections with fixed heights and set the height of both sections to 100%.

<style>
#frameset {
  background-color: lightBlue;
  position: absolute; /* my method for simulating frameset */
  bottom: 0; /* consider specifying height instead if not using absolute positioning */
  top: 0;
  left: 0; 
  right: 0;
}
#menu, width {
  width: auto;
  height: 100%;
}
#menu {
  background-color: bisque;
  max-width: 15em;
  float: left;
  overflow-y: scroll; /* can change to auto, but remember:
   scrollbar is inserted from inside. Content may require line breaks
     when scrollbar is added */
}
#content {
  overflow-y: auto;
}
</style>

<div id="frameset">
  <div id="menu">aaaaaaaaaaa</div>
  <div id="content">b</div>
</div>

Answer №5

Let me take a stab at this problem:

<!DOCTYPE html>
<head>
    <title>Testing Out Columns</title>
    <style type="text/css">
    #first { float: left; }
    #second { overflow: hidden; }
    </style>
</head>
<body>
<div id="first">
    <ul>
        <li>Here is</li>
        <li>Some content with varying widths</li>
        <li>to test</li>
        <li>things out</li>
    </ul>
</div>
<div id="second">
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod felis turpis, quis cursus est ullamcorper eget. Etiam mollis ultricies velit in convallis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Quisque finibus libero non sapien euismod tempor. Vestibulum posuere placerat odio ut efficitur. Aenean nec mi nulla. In hac habitasse platea dictumst. Integer pellentesque ornare urna sed congue. Suspendisse potenti. Ut pharetra bibendum lectus ut tempus. Donec sit amet felis quis sem faucibus eleifend vel ac mauris.</p>
    <p>Nam tincidunt viverra nunc, eget varius lacus scelerisque eget. Duis fermentum dapibus neque non hendrerit. Suspendisse potenti. Aliquam aliquet metus justo, sit amet lobortis orci scelerisque vitae. Fusce vestibulum pulvinar purus, sed tincidunt ipsum lobortis nec. Mauris mattis arcu sit amet nisi feugiat, ut sagittis tortor suscipit. Nullam molestie nibh magna, vitae vehicula elit consequat non. Nunc venenatis egestas enim, nec pellentesque tortor elementum nec. Proin eu dui a tortor placerat porttitor interdum sit amet ligula.</p>
</div>
</body>
</html>

This should do the trick. The #first section floats to the left without a specified width, allowing its content to define the width. The #second section doesn't overlap with the first one thanks to overflow: hidden. Just keep in mind that this method may not be compatible with IE versions older than 7.

Answer №6

To achieve the desired layout, applying CSS is essential.

.a {

float: left;

}

The content in b will wrap around a element.

Allow the width to adjust automatically based on the data retrieved from the database.

Ensure that the height is controlled to prevent b from dropping below a.

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

Creating a linear video playback system

Having an issue with my code in Chrome where auto play is enabled, but the video won't play. I have a loop set up to play each video one after the other, but first things first - how do I get this video to start playing? If there's a pre-made so ...

Establish a background image that can be scrolled

Currently, I am working on a project and have created a fiddle that can be accessed here: https://jsfiddle.net/0g3u8452/1/ The image I am using is 1920x4000, and I want it to span the full width of the screen similar to setting background-size ...

Tips for showcasing an image partially with primefaces/jsf

Looking to display just a single icon from a sprite image? Here is how you can do it using jsf/primefaces: If you tried the code below but ended up displaying the complete image, try adjusting the background-position values: <p:graphicImage value="/re ...

Using CSS to ensure that the cards have consistent heights when using both React and Bootstrap

I am currently working with Bootstrap 4 in React. I have encountered an issue where the card for Item 1 is shorter than that of Item 2, and I would like both cards to have the same height. Additionally, I anticipate adding more cards at the bottom in the ...

Is there a way to make an HTML link target the same as JavaScript window.opener?

Within my project, the main page is where users log in and access the primary tables. Additionally, there are numerous supplementary pages that open in separate windows. Once the login session times out, it is essential to restrict user access to any cont ...

The backdrop moving in a reverse direction

I recently made a tweak to this code that successfully moves the background in the opposite direction of the scroll. However, there is now an issue where it leaves a blank space at the top, even when the background is set to repeat. The change I made was s ...

Utilizing fab-icons with CDN in Next.js version 13.4

Currently, I am working with the latest version of Next.js (13.4) and I would like to incorporate a single Icon into my project using Font Awesome CDN to avoid increasing the overall app size. However, when I include the following code snippet in my layou ...

React js web application facing excessive content problem

I am encountering an overflow issue with the styles sheet I'm using on mobile and tablet views, but it works fine on desktop view. Can anyone provide a solution to this problem? I am developing a ReactJS web app hosted on Firebase. When I include fewe ...

How can I incorporate a custom icon into the <i> tag in HTML like Bootstrap does with its icons?

When working with Bootstrap, you can easily add an icon using the following syntax: <i class="bi bi-arrow-right-square-fill fs-1"></i> One great feature is that you can adjust the size of the icon by simply adding the fs-1 class. If ...

Struggling to access your account on the Django website?

I'm having trouble creating a login page in Django. I have completed the views, HTML, and everything, but the problem is that when I try to log in, it doesn't work. After some debugging, I found that the user value is None, but I don't under ...

Retrieve items from the parent row of selected checkboxes

Within my table, I have the following row. <tr class="data_rows" ng-repeat='d in t2'> <td class="tds"> <input class='checkBoxInput' type='checkbox' onchange='keepCount(this)'></td> &l ...

Tips for displaying the initial slide when a tab is loaded on a multi-tab webpage

I have a total of four tabs, with the first tab containing a slideshow. On page load, I am successfully triggering the first tab, but for some reason, the first slide in the slideshow within that tab is displaying a blank image. I'm struggling to find ...

Learn how to troubleshoot and resolve a bug in the mobile Chrome browser that pertains to the position fixed feature

On the mobile version of Firefox, everything works perfectly. However, there seems to be a bug in Chrome with the fixed positioning. When scrolling, the header should change from absolute to fixed and the height should go from 65 to 35 pixels. Unfortunatel ...

Include a parent class within the style tags in your CSS code

Currently, I am facing an issue with a web application that I am developing. On the left side of the page, there is an editable area, and on the right side, there is a live preview. The live preview area contains an HTML file with specific fields that can ...

Craft a Flawlessly Repeating Sound Experience - Online

I'm facing a challenge in creating a flawless loop of an audio file. However, all the methods I've tried so far have resulted in a noticeable gap between the end and the start. Here are the approaches I experimented with: The first approach inv ...

Issue with rendering Html Element on FireFox compared to Chrome

Having some trouble with an individual component (a simple dropzone) while testing on Firefox. It seems to work fine on Chrome, and the CSS looks good. Css .container { position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); wi ...

Struggling to make JavaScript read JSON data from an HTML file

I am currently working on developing a word search game using django. One of the tasks I need to accomplish is checking whether the entered word exists in a dictionary. To achieve this, I have been converting a python dictionary into JSON format with json. ...

Design a Logo-aligned Header using Bootstrap 4 for a professional and sleek look

I'm attempting to design a header using bootstrap 4 that resembles the image shown https://i.sstatic.net/MFVZU.png. However, I'm encountering several issues with this method. The main problem is that the logo is not properly centered in the middl ...

Styling menus with CSS

I'm struggling with a CSS issue while attempting to add a 1px solid black line after each element in my drop-down table menu. The current appearance of my menu is causing some trouble. What I desire for it to look like involves applying border: 1px s ...

What is the best way to create divs that can close and hide themselves when clicked from inside the div itself?

I have a situation in my code where clicking a link reveals a div, and then the same link must be clicked again to hide it. However, I want to modify this so that any link within the div can also hide it when clicked. I currently have eight divs set up lik ...