Stop div from exceeding the page boundaries

Here's my current dilemma:

I have a simple css3 tooltip-menu that is hidden by default and appears on mouseover. It has a fixed width and is positioned absolutely to the right (with an arrow in the middle pointing to the hovered element). The issue I'm facing is that when viewing the menu on smaller windows, a horizontal scrollbar appears after hovering over the element. How can I prevent this? Is there a way to make the menu box appear on the left side in such situations?

The code for my existing menu is straightforward:

<ul><li>Hover me 
<ul><li>Hovered element</li>
<li>Hovered element 2</li></ul>
</ul>

And the CSS looks something like this:

ul > li > ul {display:none}
ul > li:hover > ul {display:block}

In addition to other styles. Is there a jQuery script or CSS trick available to address this issue?

Answer №1

Exciting news! I've finally discovered a solution using PURE CSS. By utilizing the word-wrap property, you can easily achieve your desired outcome. Below is the revised CSS code:

ul > li > ul {
    display:none;
}
ul > li:hover > ul {
    margin-left:-15px;
    word-wrap: break-word;    
    display:block;
}

See it in action here:http://jsfiddle.net/p7wzv57j/

Answer №2

One important step is to utilize Media Queries in your CSS. By determining the screen size where the behavior occurs, you can then adjust the settings accordingly.

Here is an example:

Your regular CSS definition :

.reframe {
 //Your Settings
}


@media screen and (min-width: 760px) {
    .reframe { //your new settings }
}

Answer №3

In a similar scenario that I experienced, the messages were generated through JavaScript. To address this issue, I utilized the element's offset at the time of inception to determine its distance from the right side of the screen. Subsequently, I assigned it a unique class with distinct styling.

If JavaScript is not an option, one potential solution could involve utilizing media queries for global modifications. Creating separate classes like .left and .right could allow for explicit customization based on positioning.

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

How can the spacing between Angular Material's mat-card-content and mat-card-actions be adjusted?

I am creating a mat card layout where there are two separate cards within the main card's content section. However, when I add a button for the actions section of the main card, there is no spacing between these two sections. How can I create a vertic ...

Ensure that the textbox remains valid when the reset button is clicked in Bootstrap

After implementing the code for bootstrap textbox and textarea, I encountered an issue when using the reset button. When entering an invalid shop name followed by a valid address and clicking on the Reset button, it resets the form. However, if I then only ...

HTML: Align DIV contents next to each other without any overlap

Below are three boxes displayed. Boxes 1 and 3 appear fine, but in box 2 the text content is overlapping. The issue lies with the <div> having the class .vertical_center.grade_info which has a specific margin-left of 100px, causing the overlap. I ne ...

Navigating through a table using jQuery to find a specific element

There are form input elements within an HTML table structured like this: <table> <thead> .... </thead> <tr> <td><input type="text" name="n_time" id="5030c9261eca0" value="2012" /></td> ...

jQuery - Strip the parent of its class

How do I take off a parent's class? Link to jsfiddle here const panels = document.querySelectorAll('.panel'); const titles = document.querySelectorAll('.section-titles'); panels.forEach(panel => { panel.addEventListener(&apo ...

Troubleshooting a Problem with AngularJS $.ajax

Oops! Looks like there's an issue with the XMLHttpRequest. The URL is returning a preflight error with HTTP status code 404. I encountered this error message. Any thoughts on how to resolve it? var settings = { "async": true, "crossDomain": ...

Tips for centering elements in an image caption

I need some help with separating an image and text within an image caption from each other. Currently, they are overlapping and I want them to be distinct. I attempted using inner div elements for the text and image separately, but it caused issues by brea ...

Changing the width of an HTML table does not produce any noticeable results

I attempted to create a striped table with 5 columns. The desired column sizes are: 10% width --- 10% width --- 40% width --- 20% width --- 20% width However, my current code is not achieving the correct widths (the 'description' column does n ...

Safari Displaying Error Message "Unhandled Promise Rejection: [object DOMError]" While Playing MP4 Video

I am facing an issue with playing a group of MP4 videos on hover in a container. You can view a demonstration by clicking the link below: While this functionality works smoothly in Chrome, it seems to be causing problems in Safari. Upon hovering, the vide ...

HTML elements generated dynamically do not possess any jQuery properties

I have implemented a draggable list of Div elements using jQuery. Here is the code: <div id="external-events"> <h4>List Of Staffs</h4> <div class="external-event" data-id="1">Name</div> //Draggab ...

Showing a confirmation message to the user upon clicking outside of a specific section

On my webpage, I have a section for creating content, as well as a top bar and sidebar with internal links (both controlled by ng controllers). I am looking to implement a confirmation message that will appear if the user tries to leave the page while in t ...

Can CKEditor be integrated with Mutation Observer? If so, how can this be achieved?

Trying to detect changes in the current CKEditor content. The goal is to identify which element's content has been modified when a user writes multiple paragraphs. Not well-versed in JavaScript or jQuery, but managed to come up with this code after s ...

Obtain the total by adding values from additional radio buttons selected

Need assistance with summing values from multiple radio inputs dynamically. Want to calculate the total price ('$res' variable) after checking them. Despite trying to change 'settype' to int, it didn't work out as expected. Any hel ...

show tab focus outline only

In search of a straightforward and effective method for focusable elements to display an outline only when the tab key is pressed, without showing it when using a mouse in React applications. (looking for something similar to :focus-visible that function ...

The execution of jQuery code from PHP using $.ajax is not functioning properly

I am attempting to run a jQuery code from a PHP page using AJAX. Modify the HTML of div.error Here is the code (Let me know if there is a simpler method): - no $.load HTML/jQuery: jquery.js already loaded <input type='text' id='test&a ...

What is the process for selecting and accessing a DOM element?

Looking to utilize jQuery selector for accessing deep within the DOM. HTML <table> ...more here <tr> <td class="foo bar clickable"> <div> <div class="number">111</div> //Trying to retrieve "111" ...

Bootstrap 4 - positioning link element to align with heading in card header

I'm currently utilizing Bootstrap 4+ to design a card that features a collapsible card-body, triggered by a link located in the card-header. <div class="card text-left mb-3 mt-3"> <div class="card-header p-3"> <h4>Where should ...

Model is disregarding media queries

Using LESS for CSS compilation, I have encountered an issue with the media query in my code. Specifically, I am attempting to apply different styles for mobile devices but they are not being rendered as expected. #main-wrap header #hdr-nav nav { width: ...

Confused by navigating with php

I've been attempting to convert this link into a PHP foreach loop without any success, and I'm new to Stack Overflow. I've used an array to generate the code, but I am uncertain of how to transform this code into a foreach loop. <ul class ...

"Step-by-step guide on positioning a video in the center over another

I am designing a landing page and I want to incorporate a background video with a centrally aligned logo on top of the video. My goal is for the center of the logo to always align with the center of the background image, regardless of how the page responds ...