Tips for containing a wide table within a smaller div in CSS

I am trying to fix the position of a TR element when scrolling down, but I am facing an issue where the fixed TR is overflowing and going out of the table.

I have created a container with a fixed width, but I cannot seem to get the table to only display within the width of the container.

This is a basic example. Can anyone help me with this?

body{
  height: 900px;
}

.fixedhead{
  background:red;
  position:fixed;
  top: 0px;
}

.container{
  width: 100px;
  overflow-x: hidden;
}
.container.blue{
  background: blue;
}
<div class="container">
  <div class="fixedhead">
    <table>
      <tr>
        <td>Some very long text here,</td>
        <td>bigger than the container div</td>
        <td>but it should only show as much as the container div</td>
        <td>and still be fixed to the top</td>
        <td>bla</td>
        <td>bla</td>
        <td>bla</td>
        <td>bla</td>
        <td>bla</td>
      </tr>
     </table>
    </div>
  </div>
<br>
<hr>
<br>
<div class="container blue">
it should only show up to here
</div>

Thank you all

Answer №1

To make sure everything fits, be sure to include the width property for elements with the class of .fixedhead. Additionally, add overflow-x:auto to ensure proper scrolling functionality.

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

Maximizing the worth of itemtype using jQuery: A guide

My goal is to include an 'itemtype' attribute in the body tag, body.page-body.ng-scope.device-lg(itemscope='', itemtype='') I attempted the following method $('body').add(itemtype='t1'); Unfortunately, ...

Using Html to differentiate input based on type

Looking for input on the code snippet below: <table class="details-table" *ngIf="animal && animaldata"> <tr *ngFor="let attribute of animaldata.Attributes"> <td class="details-property">{{ attribute.AttributeLabel }}& ...

Troubleshooting: jQuery.load function not functioning properly within ASP.NET MVC

I'm facing an issue with my code setup. Currently, I have the following components in different files: @Html.Raw(File.ReadAllText(Server.MapPath("~/Views/Home/index.html"))) This is included in my Razor file. <li><a href="#">Personal Re ...

Pass information from JavaScript to PHP using Ajax without any need for converting data types

I have a JavaScript object that I need to send to PHP using AJAX. I want to ensure that the data types in the object are preserved when sending it, such as NULL remaining as NULL and boolean values as booleans. Here is what I have tried: var js_object = ...

What is the best way to incorporate buttons for minimizing, maximizing, and closing a div element through javascript/jquery?

Is there a way to incorporate minimize, maximize, and close buttons into a div using javascript/jquery? Seeking a simpler solution if possible. ...

Adding data to a mysql database using JSON format

My goal is to seamlessly insert records using JSON into a MySQL database and have the system instantly display the new data without the need to refresh the page. Below is the code I am currently using: In Part 1, the script retrieves two values from a fo ...

A fresh inquiry: jQuery custom plugin callback

Many individuals inquire about plug-ins and callbacks, and after reading numerous posts on the topic, I have managed to create a simple hide/show accordion type plugin for FAQs. While I am pleased with its functionality, as I continue to learn, some aspe ...

Cease the use of jQuery animations

My JavaScript code snippet looks like this: $.get("/<page>.php", "userid='.$userid.'&"+status, function(data){ $("#status").show("fast").html(data).delay(4000).hide("fast"); }); On a page with multiple links triggering thi ...

How can I capture the submission form response from a "different domain"?

Currently, I am dealing with a unique situation where I need to submit a form and receive the response from the submission. This response will determine my next steps as I have to execute some additional logic based on it. The challenge in my case is that ...

Validation errors are nowhere to be found post ajax submission of a rails form

My form validations stopped working when using ajax-rails. Upon submitting an empty form that should trigger validation, it seems like the validation rules are not being applied and the backend log indicates that the empty form was posted. Strangely, every ...

What is the difference between handling ongoing responses in jQuery.ajax using "success:" and ".done"?

After spending a few weeks working with jQuery and AJAX, I stumbled upon two distinct ways to 'continue' the script post call completion: success: and .done. The jQuery documentation provides a summary as follows: .done(): Description: Add handl ...

Need help speeding up website load times?

My website is loading incredibly slow, even though it has minimal content. I suspect that the high number of images and JavaScript elements on the page are contributing to this issue. Is there a method available to diagnose what exactly is causing the ext ...

Sending multiple forms at once with a single submission

I've been racking my brain trying to determine the feasibility of a particular task. I am currently utilizing zen-cart as my shopping cart software, but what I really want to achieve is creating a hardcoded page featuring a list of 7-9 products. Each ...

What are some techniques for highlighting the significance of specific items within an unorganized list?

My goal is to utilize semantic markup to highlight the importance or priority of each item. Let me illustrate what I mean with an example. <ul itemscope itemtype="http://schema.org/ItemList"> <h2 itemprop="name">Wish List</h2><br&g ...

Issue with CakePHP 2 failing to detect an uploaded file through ajax communication

I'm facing a challenge trying to transfer a file from a view to a controller using Ajax in CakePHP 2.10.7. In my view, I have the following input: <div id="staff-bg-image-container"> <!-- Image uploading box resides here. --> </div ...

Hovering over the Star Rating component will cause all previous stars to be filled

I'm in the process of creating a Star Rating component for our website using Angular 11. I've managed to render the 5 stars based on the current rating value, but I'm having trouble getting the hover styling just right. Basically, if I have ...

Troubleshooting problem with width in CSS for Apple iPhones

Managing a website at has presented a curious challenge. While it displays properly on Android devices, the UI appears distorted on Apple products. Specifically, below the slider, where two images are supposed to be shown horizontally, there seems to be ...

Using jQuery to enable the form again once the file response is received

Currently, I have a situation using an ASP.NET MVC form where the report is returned as a File(...) result. This causes the browser to stay on the current page once the file download is initiated. To enhance this process with jQuery, my goal is to disable ...

Detecting when a specific element triggers a key press event

Hello everyone, As a newcomer to jQuery, I have a question regarding the key press event: Within DIV 1 area Inside DIV 2 area In DIV 3 area Unlike the click event, determining which element triggered the keypress event is chall ...

Element does not cross both explicit and implicit columns

When working in a grid container with only 1 column and 1 row, if there is an implicit column in the first row, how can an element in the second row (as shown by the green column in the example) span across both the explicit and implicit columns? I appreci ...