Ensure your div's absolute position is set to the right for a sticky effect

When I set the position of an absolute div like this:

left: 700px;

It does not move when I resize my browser window. How can I make it float to the right and move left when resizing the window?

To illustrate the issue, take a look at this site. Check out the image slider and the arrow to the right of it. Here is its style:

#slides .next,#slides .prev {
    top:165px;
    left:-20px;
    width:24px;
    height:43px;
    display:block;
    z-index:999;

    position: absolute;
}

#slides .next {
    left: 700px;
}

Now try resizing the window with that slider. The arrow will remain in the same position instead of moving left along with the slider background.

Attempts to use float: right; right: 0px; have not yielded results.

Answer №1

  • Eliminate the left: -20px; property from #slides .next, #slides .prev (you can transfer it to .prev)
  • Delete the left: 700px; style from .next
  • Introduce the right: 0 rule to .next.

By following these adjustments, your .next element will consistently position itself to the right of #slides (which is set as position: relative).

Answer №2

If you want to position the element using "right:###px" instead of left, you can do so. To ensure that it is positioned absolutely based on the right side of your content rather than the right side of the window, enclose it in a container:

<div style="position:relative; width:900px; height:90px; margin:10px auto;">
    <p>Some random content.</p>
    <div style="position:absolute; top:20px; left:20px;">Content positioned absolutely on the left</div>
    <div style="position:absolute; top:20px; right:20px;">Content positioned absolutely on the right</div>
</div>

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

Is there a more efficient approach to applying a basic function to multiple elements within a DIV and having it activate only upon a click event using jQuery?

This solution works, but I am looking for a more professional approach in order to adhere to the principle of "don't repeat yourself." $("document").ready(function(){ $(".child").each(function(index){ $(this).click(func ...

Cycle through the list and populate the table with the data

My attempt to clarify this explanation is my best, as articulating exactly what I am trying to achieve is quite challenging: Initially, I have a list of names: { "Items": [ { "Id": 0, "Name": "Robinson" }, ...

Guide to retrieving the primary key auto-increment value for the ID field in an SQL record using PHP Scripting

I am currently working on a multi-page web survey form and I have a PHP script called process.php that handles my responses on www.buythosecars.com. This script stores the responses in a MySQL table and then redirects the user to www.buythosecars.com/surve ...

Issue with Codepen: Enchanting colors that scroll

I am new to JavaScript and eager to learn the basics. I have been attempting to incorporate the code found at this link into my project, but I am struggling to get it to work properly. Can someone please assist me in identifying where I might be making a ...

Looking for a way to identify when a DOM element is resized as a result of web fonts loading asynchronously?

Within this div element lies text styled with a custom font via CSS's @font-face attribute. The issue arises when the font hasn't loaded yet, causing a delay in updating the font style of the text within the div. As a result, taking measurements ...

The click event does not point to the servlet (IDEA, java)

I am facing an issue where the command $.get('MyController1', function (responseText) is not sending to my servlet. I am using ajax and after clicking the button it should send to my servlet ('MyController1' or 'MyController2' ...

Should we consider using extra url query parameters as a legitimate method to avoid caching or enforce the updating of css/js files?

Is it acceptable to include extra URL query parameters in order to avoid caching or enforce the updating of CSS/JS files? /style.css?v=1 Or would it be preferable to rename the file/directory instead? /style.1.css I've heard that this could potent ...

Is there a way to arrange the outcomes in a single line?

I need help displaying my results in three rows side by side in React/JavaScript using flexbox. Since I only have one CardItem, I can't just copy and paste it three times as it would show the same result in each row. Is there a way to achieve this wit ...

Custom Bootstrap 3 Panel Organization

I'm intrigued by the layout shown in the image attached. My attempts to recreate it using a combination of columns and rows have been unsuccessful. Could it be that I'm going about this the wrong way? ...

The find function within $(this) is malfunctioning

I'm having issues with displaying/hiding content when clicking on a table row. Here is the simplified code snippet: HTML: <table> <tr onclick="showDetails()"> <td>Some text <br> <span class="hiddenC ...

Resizable dimensions for the dark mode switch

My latest project involves creating a toggle button for switching between light and dark themes using CSS, HTML, and JavaScript: id("theme-btn").addEventListener("change", function() { if (this.checked) { qs(".box").setAttribute('style', ...

Change the border color when summernote is in focus状态

My goal is to change the border color of the summernote div to a light blue when it is focused, and then set it back to neutral when it loses focus. To remove the shadow around the div, I used the following CSS code: div.note-editor.panel.panel-default { ...

Retrieve the value from another select element

Is there a way to create a function in pure JavaScript that changes the selected options in two select tags based on each other? For example, if I choose a French word in one select tag, the English equivalent automatically changes in the other select tag ...

How can I set a value using document.getElementById(idPopUPImage).innerHTML to create a static popup in Leaflet?

I added a leaflet map to my project which you can find on Codpen In the map, I've included a button key that displays an image in a popup when clicked. However, after closing the popup and reopening it, the image doesn't show unless I click the ...

Issue in insert.php file: stdClass::$variable property is undefined when using Ionic, Angular, and PHP together

There are three files. Once the submit button is clicked on the Ionic page, all inputs will be sent to the controller, which will then parse them to insert.php. The form input data is saved successfully when only using HTML (without Ionic content), however ...

Implementing a blur effect on a CSS loader

I have successfully implemented a loader feature where a loading animation is displayed upon clicking the submit button, indicating that the form submission is in progress. However, I am encountering an issue when trying to apply a blur effect to the entir ...

Verify if the input field is devoid of any content or not

I am planning to create a validation form using Vanilla JavaScript. However, I have encountered an issue. Specifically, I want to validate the 'entername' field first. If the user does not enter any letters in it, I would like to display the mess ...

What could be the underlying reason for the unusual behavior observed in this range polyfill implementation?

I am attempting to transform an HTML5 range input into a set of radio buttons. Each radio button corresponds to a value within the original range, with text displaying its value. However, I am encountering an issue where the last piece of text, meant to sh ...

Sending information to a website using Java

Looking to retrieve exam results from a web page, my program is designed to input the registration number and fetch the resulting data. However, I'm encountering an issue where the program returns the same input page rather than the desired result. Be ...

How to position two divs next to each other using CSS with just one adjustment

Is it possible to position two divs side by side, with one of them moving continuously up and down while containing an image? I attempted the following code: <div> <div style="margin:30px;width:100px;height:250px;position:relative;float:left; ...