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

Send form data without reloading the page and connect it to a JavaScript script

I've designed a system that reveals values based on a specific input selection. Below is the main form where users can enter model numbers and press enter: <form> <input type="text" name="ModNum" id="ModelNumber" pattern="^PIV13RT[23]?$" ...

How to Place a Button Halfway Out of an Angular 5 Material Dialog

Is there a way to place a close button on the top right corner of a dialog box, partially inside and outside the dialog like shown in this image: I attempted using absolute positioning to achieve this, but that solution is not ideal. I want to position t ...

Angular Script Linking

Hello there! I am currently attempting to add an HTML tag to my response message, but for some reason it isn't working as expected. Here is a snippet of my controller code (in case the API indicates that the account doesn't exist - see this scr ...

Ensure the following elements remain in place once an element has been concealed

Imagine a scenario where three elements are present in an HTML file, with one element (specifically the middle one, .div2) hidden from view. The goal is to reveal this hidden element (.div2) and hide the first element (.div1) upon clicking a button using j ...

The HTML document is having trouble establishing a connection with socketio

I currently hold an HTML file within my local file system, presented as follows: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Example of a Minimal Working File</title> ...

Having Trouble Adding a CSS File to Your Django Project? Can't Seem to Get it

I am feeling exhausted trying to solve this problem and now I am in desperate need of help. I have been attempting to add a main.css file to my Django project so that I can handle the CSS myself. I have watched numerous tutorials, but most have crashed m ...

What causes Firefox (Mobile) to zoom out of my webpage?

After launching my webpage on Google Chrome mobile (android), everything loads perfectly. However, when trying to access the site using Firefox mobile (android), most pages load in a zoomed-out view. The issue is resolved by opening the drop-down menu, but ...

Displaying a loading screen while a jQuery ajax request is in progress

Currently, I am attempting to display a loading div while waiting for an ajax call to finish. Despite experimenting with various methods, I have not been able to consistently achieve the desired outcome. In my present code, everything functions properly o ...

Utilize jQuery to export HTML or JSON data to an Excel spreadsheet

I am looking for a way to export json or html data to an excel sheet using only html and jquery, without involving any server code. I have found some fiddles that allow me to download the excel sheet successfully, but unfortunately, none of them work in In ...

Issue with the back-to-top button arises when smooth-scrolling feature is activated

This Back To Top Button code that I discovered online is quite effective on my website. // Defining a variable for the button element. const scrollToTopButton = document.getElementById('js-top'); // Creating a function to display our scroll-to- ...

I am currently working on creating a timer and I am looking to position these three buttons in a circular formation

I want to create a stopwatch with 3 responsive buttons arranged in a circular layout. I have successfully built a responsive circle and now need help adding the buttons inside the circle next to the timer. To view the code, click here: https://jsfiddle.ne ...

Tips on how to position a expanding textarea in line with buttons

I need assistance with aligning a textarea that is growing to the left, and action buttons positioned on the right side of the textarea. My goal is to have the action buttons aligned at the bottom, level with the expanding text area. Here is the code snip ...

Obtaining the width of a child table using Jquery

I have a question that might seem simple, but I can't figure it out. How can I use jQuery to get the width of a table that is a child of a div with the class "test"? <div class="test"> <div id="one"> </div> <table> <thead&g ...

error being triggered due to relative positioning

On my webpage, I have a set of buttons located at the bottom. When I first open the page, all the buttons are displayed properly. However, sometimes the first three buttons become hidden mysteriously and the layout changes. I am puzzled as to what could be ...

Using CSS to disable an image map in conjunction with dynamically adjusting CSS styling

On the desktop version of the website, there is an imagemap implemented. However, when the site transitions into tablet or mobile view, the imagemap should be disabled to allow for a simpler navigation area to be displayed. I attempted to use the following ...

When scrolling, dynamically change the background color by adding a class

I am looking to achieve a scroll effect where the color of the menu buttons changes. Perhaps by adding a class when scrolling and hitting the element? Each menu button and corresponding div has a unique ID. Can anyone suggest what JavaScript code I should ...

Creating a lively JQ plot and saving it within an HTML file from a .aspx page using C# .net

I am currently in the process of developing a web-based application using Bootstrap. My goal is to save a .aspx page as an HTML file within my application. Upon writing the code: using System; using System.Collections.Generic; using System.Linq; using S ...

"Ensure that the data in the div is being updated accurately via AJAX in ASP.NET MVC

I'm currently using a div element to display data on page load through AJAX calls. $(document).ready(function () { email_update(); }); function email_update() { $.ajax({ url: '@Url.Action("EmailsList", "Questions")', ...

How can I place text on top of an image with a filter using Bootstrap?

I am facing a challenge of overlaying text on an image with a tinted background color and opacity. While working with Bootstrap 4, I suspect that some classes might be conflicting with each other. This is my current setup: Index.cshtml: <div class=" ...

Optimizing Angular for search engines: step-by-step guide

Regarding Angular SEO, I have a question about setting meta tags in the constructors of .ts files. I have implemented the following code: //To set the page title this.titleServ.setTitle("PAGE TITLE") //To set the meta description this.meta.addTag ...