Slider caption glitching out

I am encountering an issue with the caption I added to my slider. When I scale the page, the height becomes inconsistent. It seems like the caption is not in an absolute position on the page. Strangely, when I try to position it absolutely, it disappears?

Here is the code snippet:

<div style="height: 500px;">
<div class="callbacks_container">
      <ul class="rslides" id="slider4">
       <li><img src="img/businessbig.jpg" alt="">

       <p class="caption">Welcome to Ashley Tate
            <br />
        Thank you for visiting our website – whether you are considering buying or selling your business, we are here to assist you.
            <br />
    Experience is key in business sales, and the core team at Ashley Tate has over thirty years of experience in business sales and acquisitions.
            <br />
        Our approach to business sales is unique; we aim to provide professional advice and guidance based on a deep understanding of the sales process and the market. </p>

       </li>

      <!--<li><img src="img/cateringbig.jpg" alt=""></li>
      <li><img src="img/nurseriesbig.jpg" alt=""></li>-->
    </ul>
</div>
 </div> 

Here is the CSS code:

.caption {
  display: block;
  position: absolute;
  z-index: 2;
  font-size: 20px;
  text-shadow: none;
  color: #fff;
  background: #000;
  background: rgba(255,255,255, .8);
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 20px;
  margin: 0;
  margin-top: -400px;
  float: left;
 }

When the media queries are applied, the caption appears fine on smaller screens but ends up being pushed under the image on larger screens.

Answer №1

Without viewing the entirety of your code, it can be challenging to determine the exact issue. Typically, this error occurs when the parent element lacks the position: relative setting.

For an absolutely positioned element to display correctly, it must be relative to a parent element. To resolve this issue, consider adding position: relative to the li element.

Answer №2

To enhance the responsiveness of your design, incorporate @media (media queries) and introduce .caption. Experiment with altering properties like padding: 10px 20px; or margin-top: -400px; within your media queries. It may be necessary to adjust the positioning depending on the screen size, allowing for dynamic repositioning.

Another factor to consider, as pointed out by @Stuart, is that surrounding elements may have conflicting position: values, causing interference with the placement of your .caption element.

Wishing you success in resolving these issues!

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

Modify the content within the <h2> Tag that needs updating with JavaScript

Looking for guidance on how to update the text within an HTML element using JavaScript. Any suggestions? The current setup is as follows: <h2 id="something">Text I want to change.</h2> I attempted to achieve this with: document.getElemen ...

Utilizing Conditional HTML/CSS for Enhanced Outlook Emails on Office 365

One interesting feature of Microsoft Outlook is its support for conditional CSS, allowing developers to create markup and styling that is specifically designed to render on Outlook. Despite the claims, I found that the following snippet, intended to be hid ...

Incorrect use of the jQuery .height() method

I am working on creating a responsive div with a sloped edge that needs to adjust according to the screen size. I have successfully maintained a consistent angle across all screen sizes, but I am facing an issue where the height calculation for $('#sl ...

How can I create a Bootstrap 4 navigation menu that toggles on the left side but keeps the button on the right

Is it possible to create a collapsible bootstrap 4 navigation with the toggle button on the left side while also having action buttons on the right side that are not part of the collapsible menu? How can I prevent the navbar-collapse menu from pushing down ...

What is the determined method for calculating the pixel size of an SVG image?

Did you know that the Stackoverflow logo is actually an <a> element with a SVG image as its background? #hlogo a { text-indent: -999em; display: block; width: 200px; height: 50px; background-image: url("img/sprites.png?v=c4222387 ...

Is it possible to close the menu by clicking outside a div or letting it disappear on mouseout after a set period of time?

When visiting a website, you may notice menus that display sub-menus when hovered over. These menus and sub-menus are created using div elements, with the sub-menus hidden initially using style.display = none; The issue arises when a sub-menu is opened an ...

Enhancing the appearance of an Angular.js application

On the same page, there are two buttons - one for buying and one for selling. It appears that both buttons share the same HTML instance. This creates a problem when trying to style them individually using classes, ids, or other HTML-targeted selectors, as ...

The synchronization issue between ng-class and animation

I'm experiencing a strange issue with ng-class and suspect that it may be related to a race condition. Here is the example on Plunker: example Below is the relevant JavaScript code: self.slideLeft = function() { if (self.end_index < se ...

choose from the list of options that appear above the control

It's strange, but no matter how simple the example is - whether it's regular HTML or Bootstrap - the option list always appears on top of the select control itself. I have no idea why this is happening. Can someone help me with this issue? Here ...

JavaScript Radio Buttons

Below are the different radiobuttons: Apple <input type="radio" id="one" name="apple" data-price="10" value="light"/> Light <input type="radio" id="two" name="apple" data-price="20" value="dark" /> Dark <input type="text" id="appleqty" name ...

What is causing the div element to act as a container?

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="95f7fafae1e6e1e7f4e5d5a1bba3bba5">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-B0v ...

What is the method for ensuring that a GreaseMonkey script impacts elements on a page prior to their appearance?

I'm currently working on a project that requires hiding images on a specific website while still displaying the alt text. Initially, I tried to achieve this using Stylish on Firefox and posted the following question: How to force an image's alt ...

Is there a method to track the progress of webpage loading?

I am working on a website built with static HTML pages. My goal is to implement a full-screen loading status complete with a progress bar that indicates the page's load progress, including all images and external assets. Once the page has fully loaded ...

Troubleshooting Issues with ASP.NET MVC5 CRUD Validation Inside Modal

My modal validation is functioning correctly, however, I am experiencing an issue where the form always returns valid()=false resulting in not hitting the Controller Method. I have attempted to use the unobtrusive.parse method for validation and it works ...

What might be the reason for the misaligned positioning of the ThreeJS canvas when the browser window is resized?

My goal is to perfectly align a ThreeJS canvas (with a blue background and yellow text) within the transparent cut-out of the green image. So far, everything is working fine, but I've noticed that resizing the browser window or zooming causes the canv ...

Obtaining your CSGO inventory via Steam API using jsonp: A step-by-step guide

Hey there! I'm currently facing an issue while trying to access a player's CSGO inventory using Valve's API. Unfortunately, I keep running into the error message stating that no 'access-control-allow-origin' header is present on th ...

guide on utilizing the Thingspeak API with jQuery AJAX

I am attempting to call the Thingspeak REST API and display the value on an HTML page. However, I am encountering an issue where the value is showing as undefined. Here is the code snippet I am using: <script type="text/javascript"> $(document) ...

Tips for maintaining a loading screen for longer than 4 seconds?

I want to maintain the loading screen for a minimum of 4 seconds. However, the timer at the end does not seem to be functioning as expected. Here is the code snippet I am using: window.addEventListener("load", () => { const preload = document.querySe ...

What is the best way to preserve the updated sequence of a list that can be re-ordered?

I've been tasked with making a re-orderable list for my apprenticeship project. After incorporating drag and drop functionality using Jquery UI, I managed to display the index of each item. However, saving the new order back to the database has prov ...

Enhance each category changing with jQuery page transitions

Is there a way to add page transitions based on category names and quantities in PHP? For example, when clicking on the "office" category, can a popup overlay be displayed with the category name and quantity while the content loads? The focus is on creat ...