The horizontal scroll feature is dysfunctional when attempting to allocate cell space based on a percentage

I want to display two sections of text that take up the full width of the screen and resize automatically when the screen size changes.

Currently, I am using percentage widths to achieve this. However, when the text inside a section exceeds the available width, it no longer follows the allocated percentage.

For example, if I remove the white-space: nowrap, the sections display correctly with percentages but do not show scrollbars and wrap the text instead.

Using fixed pixel widths works fine, but since my application window is resizable, I need the content to resize for different displays.

The desired effect is:

  • Text should not wrap but be horizontally scrollable
  • The sections should occupy the screen width based on percentages (35%, 65%)

How can I achieve this?

.Area {
  white-space: nowrap;
  overflow-x: scroll;
  overflow-y: scroll;
  border: 1px solid;
  height: 50px;
  font-family: "Courier New", Courier, monospace
}
html, body {
  height: 100%;
  font-family: Arial, Helvetica, sans-serif
}
<table width="100%">
  <tr>
    <td style="width:35%;">
      <div class="Area" id="Area1">
        hello friends this is cell 1 line 1<br>
        hello friends this is cell 1 line 2<br>
        hello friends this is cell 1 line 3<br>
      </div>
    </td>
    <td style="width:65%;">
      <div class="Area" id="Area2">
        hello friends this is cell 2 line 1<br>
        hello friends this is cell 2 line 2<br>
        hello friends this is cell 2 line 3<br>
      </div>
    </td>
  </tr>
</table>

Answer №1

Make sure to include table-layout:fixed in your table CSS so that the table size remains fixed and does not resize based on its content:

table {table-layout:fixed;}
.Area {
  width:100%;
  white-space: nowrap;
  overflow-x: scroll;
  overflow-y: scroll;
  border: 1px solid;
  height: 50px;
  font-family: "Courier New", Courier, monospace
}
html, body {
  height: 100%;
  font-family: Arial, Helvetica, sans-serif
}
<table width="100%">
  <tr>
    <td style="width:35%;">
      <div class="Area" id="Area1">
        hello friends this is cell 1 line 1<br>
        hello friends this is cell 1 line 2<br>
        hello friends this is cell 1 line 3<br>
      </div>
    </td>
    <td style="width:65%;">
      <div class="Area" id="Area2">
        hello friends this is cell 2 line 1<br>
        hello friends this is cell 2 line 2<br>
        hello friends this is cell 2 line 3<br>
      </div>
    </td>
  </tr>
</table>

For further details, visit: https://developer.mozilla.org/en-US/docs/Web/CSS/table-layout

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

Header reference differs from the document referrer

this is the request header: GET / HTTP/1.1 Host: localhost:3002 Connection: keep-alive sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="96", "Google Chrome";v="96" sec-ch-ua-mobile: ?0 User-Agent: ...

Is there a way to arrange the components of my form so that the questions are positioned on the left side and the choices are displayed on the right

As I am creating a form, my goal is to align the information within it in a way that places the questions on the left side and the options on the right. I have experimented with utilizing IDs, centering them, and adjusting their positioning from left to r ...

Removing the gridlines in a Linechart using Apexcharts

I am experiencing issues with the grid and Nodata options on my Apexchart line chart. noData: { text: none , align: 'center', verticalAlign: 'middle', offsetX: 0, offsetY: 0, style: { color: undefined, fontSize: &apo ...

CSS: When using the float: right property, the container does not grow to

I'm having trouble with expanding the comment body that is floated to the right, as my container doesn't expand along with it. Any tips on how I can resolve this issue? For a clearer understanding, please refer to this link: http://jsfiddle.net/ ...

Prevent the row height from fluctuating following the fadeOut() effect

Currently, I am facing an issue with two elements on my page: .start_over_button and .speed_buttons. In CSS, the .start_over_button is set to display: none, and in my JavaScript code, I have it so that when .speed_buttons are clicked, they fade out and the ...

What is the best way to restrict the border to just one element?

I've configured my navigation bar using a list with li elements. To give it a rounded appearance, I applied a border-radius to the background. Now, I'm looking to remove the border-left specifically from the home element. Below are the code snipp ...

Managing the placement of the expanded autocomplete input in Material-UI

Whenever I use the autocomplete fields on my website, I've observed an interesting behavior. When I select multiple options, the height of the input increases significantly, causing everything below it to shift downward like this. Is there a way to m ...

Resizing tables dynamically using HTML and JavaScript

I am attempting to reproduce the functionality demonstrated in this example When dealing with a large table, I want it to resize to display 10 entries and paginate them accordingly. The only thing I require is the pagination feature without the search bar ...

The droplist functionality in jQuery does not seem to be functioning properly within an ASP.NET MVC 5

After adding an external theme to my project and writing a script for listing data in a dropdown list on a separate page, I encountered an issue where the script works on other pages but not on the Layout theme page. HomeController Note: The partial view ...

CSS/React JS: I wish for the input fields to maintain focus even after entering values

I'm working with a confirmation code that is made up of 6 digits. I've noticed that when I click on an input field, it becomes focused and underlined in blue. However, as soon as I start typing in the next input field, the blue underline disappe ...

Element width shrinks inside container query

Can you explain why using container-type: inline-size renders the span normally but collapses the button? <span style="container-type: inline-size; outline: 1px solid blue;"> This is a span </span> <button style="container-type: inli ...

Is there a streamlined approach to reducing the code for an Angular Bootstrap card with a fixed length and height?

Is there a more efficient way to distribute a fixed number of cards with fixed dimensions in three rows? Currently, I am manually coding all 33 cards spread across 3 rows - 11 cards per row. Please excuse any mistakes in my code as I am still a beginner a ...

Utilizing a hidden file-input, IE10 is able to transmit a FormData object via ajax

I'm encountering difficulties when trying to send a form that includes a display:none file-input via ajax. It works fine in Chrome (46.0.2490.71), but not in IE10 (10.0.9200.17492). I've tried various solutions without success, and it's cruc ...

Adjusting the size of the jQuery window in Google Chrome

I'm encountering an issue with resizing a menu. The code I have works fine on all browsers except Chrome. Describing this problem in words is tough, so I'll provide some screenshots to better illustrate the issue. This is how my menu appears in ...

I am experiencing issues with the ng-dropdown-multiselect library and it is not functioning

Check out this awesome library for creating dropdown menus using angularjs and twitter-bootstrap-3 at: . I am trying to implement the examples provided. In my html, I have: <div ng-dropdown-multiselect="" options="stringData" selected-model="stringMod ...

My HTML file seems to be ignoring the styles in my CSS file. What could be causing this issue?

I've started incorporating bootstrap 5 into my html page. Below is the code snippet: <link rel="stylesheet" src="/main_styles.css"> <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" cla ...

Eliminate the cushioning on a single item

I'm currently working on a website and running into a small issue. The main page has a background with a white body in the center, containing padding for the text to prevent it from being right at the border. #content { width: 900px; overflow: h ...

GET requests will not be allowed

Having an unusual issue where the GET parameters are not being passed properly. <!DOCTYPE html> <html> <body> <?php var_dump($_GET); var_dump($_POST); ?> <form action="test.php?ds=1" m ...

Issue with the Styled Components Color Picker display

For the past 6 months, I have been using VSCode with React and Styled Components without any issues. However, recently I encountered a problem where the color picker would not show up when using CSS properties related to color. Usually, a quick reload or r ...

What is the best way to stack text boxes vertically in CSS/HTML?

How can I arrange these textboxes so that .textbox appears at the top, followed by textbox1 below? CSS .textbox { border: 1px solid #848484; -moz-border-radius-topleft: 30px; -webkit-border-top-left-radius: 30px; border-top-left-radius: ...