Display the overflow content even when the parent element has the overflow property set to

Currently, I'm working on a slider for images that includes titles overlaping the boundaries of the images. To achieve this effect, I have created a wrapper div positioned at the center of the page using

position: relative;margin: 0 auto;
. This wrapper has a width of 500 pixels and hidden overflow.

Within the wrapper, there is an image wrapper with double width. Inside the image wrapper, there are two divs containing titles for each image. These divs have a width of 500 each, and they are positioned next to each other using float:left. The titles inside them are given a 'margin-left: -10px;' property, absolute position, and overflow: visible; in order to allow the titles to overflow by 10 pixels outside the wrapper.

I am wondering if there is a way to accomplish this effect successfully?

Below is an example code:

Html:

<div id="wrap">
<div id="imgwrap">
    <div id="imgbox" class="firstimg">>
        <div id="imgtitle">
             <h3>Title here</h3>

        </div>
    </div>
    <div id="imgbox" class="secondimg">>
        <div id="imgtitle">
             <h3>Title here</h3>

        </div>
    </div>
</div>
</div>

JS:

jQuery(document).ready(function ($) {
$("#imgwrap").mouseleave(function () {
    $(this).find('#imgbox').stop().css('marginLeft', '0');
    $(".secondimg").find('#imgtitle').stop().css('marginLeft', '0');
}).mouseenter(function () {
    $(this).find('#imgbox').animate({
        marginLeft: '-500px',
    }, 1000);
    $(".secondimg").find('#imgtitle').animate({
        marginLeft: '-10px',
    }, 1000);
});
});

CSS:

#wrap {
width: 500px;
position: relative;
margin: 0 auto;
overflow:hidden;
}
#imgwrap {
overflow:hidden;
background: red;
height: 500px;
width:200%;
position: relative;
}
#imgbox {
float:left;
height: 250px;
width: 500px;
overflow: visible;
position:relative;
top:20%
}
.firstimg {
background: blue;
}
.secondimg {
background: green;
}
#imgtitle {
background: black;
width: auto;
position: absolute;
overflow: visible;
bottom:0;
}
.firstimg #imgtitle {
margin-left: -10px;
}

h3 {
font-size:20pt;
line-height: 0em;    
color:white;
padding: 0 80px 0px 10px;
}

Link to Fiddle

Answer №1

To enhance the appearance of your #wrap, include padding-left:10px.

Delete overflow:hidden from your #imgWrap style.

Make changes to this portion of your JavaScript code:

$(this).find('#imgbox').animate({
        marginLeft: '**-510px**',
    }, 1000);

Check out the JFiddle link for a demo: http://jsfiddle.net/k3cPK/7/

Answer №2

By setting the width property to auto, the div.imgtitle element will expand to accommodate its content. To limit the width to 150px and prevent line breaks, you can explicitly specify a width of 150px and add a white-space: nowrap style rule.

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

Get the div to occupy the rest of the available height

I am facing a challenge with two divs on my webpage. The bottom one contains content that expands the highest. The page is set to 100% height and width using the CSS property position: absolute. <style> body, html { height:100%, width:100% } ...

What could have caused the issues with my validation in cakephp3.4.13?

Every time I try to enter a value, it keeps saying 'This value is already in use' even though it's not yet in the database. Occasionally, it displays a message saying "This field cannot be left empty." public function validationDefault(Val ...

HTML DOCTYPE causing havoc with my CSS styling

When using the materialize framework, I've noticed that adding <!DOCTYPE html> causes my CSS to not be recognized. However, everything works fine without <!DOCTYPE html>. Any suggestions on how to resolve this issue? Update : <?ph ...

Challenge with scroll function in Internet Explorer JavaScript

Here is the code snippet I am working with: var lastScrollTop = 0; window.addEventListener("scroll", function(){ var st = window.pageYOffset || document.documentElement.scrollTop; if (st > lastScrollTop){ $('.sticky').addClass('insi ...

Exploring ways to extract an element from a newly opened window and set a value using JavaScript

I have been successfully using web_browser.document.getElementById() for the login screen, but I am encountering an issue when trying to use it after logging in and opening a new window. Can someone please assist me with this problem? Below is the code t ...

Organizing a collection of clothing sizes with a mix of different measurements using JavaScript

If I have an array like this: $arr = ['xl', 's', '1', '10', '3', 'xs', 'm', '3T', 'xxl', 'xxs', 'one size']; I aim to arrange the array in this o ...

transmitting information via submission with the help of colorbox ajax

HTML <div class="cus_input"> <form id="category_form" method="GET" action="<?php echo base_url(); ?>welcome/find/" > <input type="text" id="category_input" name="q" placeholder=" Find Category"/> <a type="su ...

The multi.js library is not causing the <select> to refresh appropriately after an AJAX request

I have integrated a multi-select feature to my Django form using the multi.js library for enhanced visual representation. Additionally, I am utilizing the Django Bootstrap Modal Forms package to enable users to add new options seamlessly without page refre ...

Ways to effectively shut down the jQuery context menu

I'm having trouble with a jQuery context menu that won't close when I want it to. Here are the functions I have set up: function openContextMenu(event) { event.preventDefault(); $("#custom-menu") .css({ top: eve ...

Is there a way to use Jquery to determine if a parent div contains a scroll

I'm trying to find a jQuery example that checks if any parent div has a scroll bar, but I can't seem to locate a helpful one. Here is the code snippet I am working with: <div> <div class="heading"> <div class="visit ...

Customize the color of the Formik Field type="time" to match your desired color scheme

Currently, I have a time picker component that is integrated with Formik: <Field type="time" name="end_time" disabled={editState} value={endTime} style={{ Width: "3vw" }} onChange={(e) => { setEndTime(e.t ...

Most efficient method for using jQuery to load content and populate form fields

My current process involves utilizing jQuery to send a post request to a page that responds with a JSON Array. Within this method, I call another function/Controller which displays an HTML form after loading it via get request. Subsequently, the form field ...

Efficiently determine optimal menu item dimensions using CSS automatically

Is it possible to automatically position menu items using CSS so that the position is recalculated when the menu item text changes? Currently, I have a menu created with ul li's and I am using padding for positioning. However, if the text becomes long ...

"Although Highcharts' parsed drilldown is not displaying on the page, it is visible in the

I successfully created a column chart using Highcharts 4 with jQuery 1.9.1 by parsing a CSV file. The page loads with the chart displayed, but when I click on a bar, nothing happens. Upon checking the console in IE11, I can see that the arrays are being ge ...

browsing the dropdown when it loses focus

My form includes a date of birth field displayed in 3 dropdowns for Month, Date, and Year. I am currently trying to validate these dropdowns based on their classes rather than individual IDs. Previously, validations were done based on the ID for each of th ...

Safari is displaying CSS in a completely unique way

Working on my very first webpage using just HTML and CSS has been an interesting experience. After creating the first 2 pages and checking in Chrome and IE, I decided to test in Firefox and Safari. To my surprise, Safari rendered my CSS differently than e ...

Oops! NullInjectorError: R3InjectorError(AppModule)[Number -> Number -> Number]: It looks like we forgot to provide a Number provider

I'm feeling a bit confused by the current situation. The application was functioning smoothly until I returned to work on it and started encountering this error. Surprisingly, my Compiler isn't flagging any errors, and as far as I can tell, there ...

Creating multiple divs with input fields dynamically using JavaScript is a useful skill to have

I need to generate 3 input text boxes for gathering user input on names and email addresses. These inputs must be created dynamically, meaning that as the user clicks on the email input field, a new line with all three elements should be generated. Below i ...

Having trouble setting the CSS width to 100%

Is there a way to assert the CSS width of an element in NightwatchJS to be 100% without hard-coding the value? Currently, when I attempt to do so, it fails and reports that the width is 196px. The specific error message is as follows: Testing if element ...

Is there a way to modify node attributes in the tick function of a d3 force-directed graph?

When working with a force directed graph, I am tasked with creating either circle or square nodes based on the group they belong to. The node creation process involves: const node = svg .append('g') .attr('stroke', &apo ...