Avoid stretching the div to the edge of the screen

In the table on my page, I have implemented a feature using CSS to display additional information in a popup div. This works well when there is limited text, but if there is extensive text in the table, it extends beyond the screen width and becomes difficult to read. Unfortunately, I cannot share the actual content for security reasons, but I have uploaded an obfuscated image of it on Imgur.

https://i.sstatic.net/ghm89.png

/* version 2 */

a.memberinfo {
  color: #000;
  text-decoration: none;
}
a.memberinfo b {
  display: none;
}
a.memberinfo:hover {
  border: 0;
  position: relative;
  z-index: 500;
  text-decoration: none;
  border-color: #000;
}
a.memberinfo:hover b {
  display: block;
  position: absolute;
  top: 20px;
  left: -25px;
  padding: 5px;
  font-weight: normal;
  color: #000;
  border: 1px solid #000;
  background: #ffffee;
}
<a class="memberinfo" href="#">Info
    <b>
    <em class="outer"></em>
    <em class="inner"></em>
    
    <table>
    <thead>
    <tr>
    <th nowrap>
    Name
    </th>
    <th nowrap>
    Send
    </th>
    <th nowrap>
    Receive
    </th>
    <th>
    Interval
    </th>
    <th>
    Timeout
    </th>
    <th>
    Type
    </th>
    </tr>
    </thead>
    <tbody>
    
    <tr>
    <td nowrap>
    Name
    </td>
    <td nowrap>
    Send data ...
    </td>
    <td nowrap>
    Receive data
    </td>
    <td nowrap>
    1
    </td>
    <td nowrap>
    1
    </td>
    <td nowrap>
    TTYPE_HTTP
    </td>
    </tr>
    </tbody>
    </table>
    </b>
</a>

Edit, here's a fiddle that shows the problem: http://jsfiddle.net/xp2xfbw6

I want the popup div to expand only up to the edge of the screen without overflowing. If further expansion is necessary, I prefer it to expand towards the left instead of the right. I do not want to wrap the text for readability purposes.

I hope this explanation clarifies the issue. Please let me know if anything is unclear, and I will provide more details.

Thank you for your help!

Answer №1

If the suggested answer from Scor3keeper for your needs is within your specifications, that may be the preferable solution. However, here is a more intricate approach that could potentially cater even more precisely to your requirements.

Awhile back, I encountered a similar situation where I needed a text box to appear vertically centered and in line with a clicked vertically stacked list element. If the text inside the textbox extended beyond the desired area, it had to be repositioned so that its top or bottom aligned with the last list element.

To address this, I implemented a solution using javascript/jquery:

$('div.myclass').click(function() {
        // JavaScript logic
    });

It's possible to adapt this method to work horizontally as well, but keep in mind that it won't resolve issues related to the div exceeding the width of the browser window.

Answer №2

To prevent a table from extending beyond its bounds, consider setting a min/max-width on the div container and using overflow-x:auto to add a horizontal scroll bar.

Another option is to format the table to display vertically instead of horizontally.

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

Show the output of JQuery in the text input area

Can anyone help me figure out how to display the value of #response in an input field instead of a div? I've tried using the code below, but it didn't work: <div id="response"></div> I attempted to use an input field like this, ...

Looking to tilt text at an angle inside a box? CSS can help achieve that effect!

Hey there, is it possible to achieve this with CSS or JavaScript? I require it for a Birt report. ...

The execution of jQuery was hindered due to the implementation of PHP include

Having an issue with jQuery not working in index.php when including the file header.php. The nav sidebar is included, but clicking the chevron does not trigger anything. It only works when I directly include header_user.php without checking the UserType in ...

Guide on triggering a function with the Enter key in Angular 9

A button on my Angular component currently triggers a method with a (click) event, but I also want the same method to be triggered if the user presses the enter key in the input box. This gives the user flexibility. Below is the HTML code for the input an ...

Is there a way to use ajax to dynamically monitor the presence of a file in real-time?

Is there a way to automatically observe the status of a file using ajax without having to manually refresh it with a button? ...

Incorporating HTML/PHP elements into JQuery

I am currently working on a website project for a manufacturing company that involves PHP, HTML, CSS, and JQuery. My goal is to create a seamless user experience where they can easily contact sales representatives for quotes and other information by clicki ...

Encountered an issue when executing python manage.py migrate and python manage.py runserver

form.py This is the form section. from django.contrib.auth.models import User from security_app.models import UserProfileInfo from django import forms class UserForm(forms.ModelForm): password = forms.CharField(widget=forms.PasswordInput()) ...

Having a newline between HTML elements can disrupt the structure of an HTML layout

It's common knowledge that in html, a newline between elements is treated as space. However, I find it quite alarming when working on responsive layouts. For instance, take a look at this example where the expected and correct behavior is achieved on ...

What are the available choices for constructing HTML based on an ajax response?

Are there any alternatives or libraries available for constructing html from an ajax response? Currently, I am taking the json data received, creating the html as a string, and using a jQuery function to insert it into the DOM. However, I believe there mu ...

What could be the reason for JavaScript delaying the execution of DOM statements until a variable is true?

Today I've been tackling numerous bugs, but there's one particularly tricky bug that has me stumped. The snippet of code below pertains to a basic logon page. Currently, the only valid username is 'admin' and the corresponding password ...

Unable to generate a navigation panel using HTML/CSS and jQuery

I recently completed the basic courses in HTML/CSS, JavaScript, jQuery, and PHP on Codecademy. I'm currently working on creating a website using HTML/CSS and jQuery in Codecademy's codebits. However, I'm facing some issues with my navigation ...

Webpack 4 Failing to Properly Render Select Tag

I am encountering an issue with a basic select element that is not displaying correctly due to Webpack. The screenshot below illustrates the final rendered page source, where the closing tag for the select element has been incorrectly positioned before the ...

Unforeseen Firefox Problem Arises with display: table CSS Property

The ultimate visual aim is to create a horizontal menu with links that can span multiple lines but are all vertically centered. In modern browsers, this effect can be achieved using CSS with the display: table property. Here is an example of how it can be ...

Modifying CSS post-rendering to accommodate right-to-left or left-to-right text orientation

I have a unique single-page JavaScript website that retrieves text from a web request in JSON format. The direction of the text (RTL or LTR) is only determined once the response is received. Is there a method to re-render the page after receiving the res ...

Arranging buttons that are generated dynamically in a vertical alignment

Currently, I am in the process of creating a webpage for various items, and everything is going well so far. However, I have encountered an issue while attempting to vertically align the buttons that I am generating using JavaScript within the document. I ...

JQuery fails to remove the "display:hidden" attribute

List of methods I attempted: Utilizing .removeClass and addClass functions Applying show() and hide() methods Modifying the CSS properties Initially, I confirmed that my script contains onLoad. Furthermore, all other elements are functioning correctly. D ...

Enhance your image viewing experience with a React component that smoothly zooms in on images without distorting their dimensions, all with

After searching extensively for a solution, I have been unable to find one that works. My current setup involves using React with Bootstrap. I am in need of a stateless functional component that can take an image path as input and return an img element. Th ...

What is the method for passing an element in Angular2 Typescript binding?

Is there a way to retrieve the specific HTML dom element passed through a binding in Angular? I'm having trouble figuring it out, so here is the relevant code snippet: donut-chart.html <div class="donut-chart" (donut)="$element"> ...

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]?$" ...

What is the method for obtaining the div ID's from this form?

This is the scenario I am working on: my app takes the text inputted by the user and exports it to a specific website that contains similar elements. For example, if the user enters a title in the app and clicks a button, the app will transfer that value t ...