Display button outside of container by utilizing absolute positioning

My objective is to design a comment button that appears next to the text when highlighted and remains fixed in place next to it as the page is scrolled.

I have noticed that the button only appears within the padding and not the margin. How can I adjust the positioning of the button so that it appears within the margin while maintaining its position relative to its container, ensuring that it stays aligned with the text upon scrolling?

Referencing the screenshot attached, you can observe how the button (located at the top right) is concealed by the margin but visible within the padding area.


.grader-content-toggle {
    overflow-y: scroll;
    position: relative;
    max-height: calc(100vh - 155px);
    padding-right: 25px;
    padding-left: 25px;
}

.comment-button {
   display: inline-block;
   position: absolute;
   right: -60px;
   top: 0px;
   background: white;
   width: 45px;
   height: 45px;
   border-radius: 50%;
   box-shadow: 0 2px 4px -2px rgba(0, 0, 0, 0.05);
   cursor: pointer;

   svg {
      position: absolute;
      top: 0;
      right: 0;
      left: 0;
      bottom: 0;
      margin: auto;
   }
}

Answer №1

Although the code you've provided is limited, I'll proceed with an answer as there is enough information to identify the issue.

The main problem lies in the fact that you have set the overflow property to hide content. Mixing overflow-y:scroll with overflow-x:visible will not work properly.

To resolve this issue, you can either:

  1. Adjust the left padding of the element
  2. Introduce another wrapper so that the button is positioned outside the container with hidden overflow.

Answer №2

Change the .comment-button position value to fixed instead of absolute

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

What is the method for modifying the button text to read "No Sign Ups!" once the alert box has been dismissed?

Seeking guidance in jQuery as I aim to modify the text of the "Sign Up Now" button post closing the alert box. I'm contemplating creating a function that triggers once the alert box shuts down, but my attempts so far have been fruitless. Any assistanc ...

Overlap in Bootstrap 4 Sections

I'm facing an issue with two sections on my website. They are properly separated until a certain size, https://i.sstatic.net/e52t2.png, but when the size is reduced, they start to overlap https://i.sstatic.net/aMtHr.png. Below is a snippet of my code: ...

Stop a looping animation keyframe in CSS and make it animate back to the beginning

I am facing an issue with a looping animation that rotates a square. Whenever I remove the class responsible for the animation, the square immediately returns to its initial position. My objective is to animate the square back to the starting position upo ...

Do you have any tips on incorporating a sinking hover effect to an image or link?

Custom Arrow Icon I Want to Add Animation To I have designed an arrow icon image that functions as a link. It is positioned on top of a background image. When the user hovers over the arrow, I would like to implement a "sink" effect similar to the example ...

Is the sound persistently playing on every single page?

Can an mp3 continue playing from where it left off when you switch to another page on the same site? I'm feeling lost and not sure how to tackle this. Still learning HTML, CSS, etc. Any thoughts or tips would be greatly appreciated. Thank you! ...

Adjusting div container width for better layout

My website is designed with a 640px page-width for mobile devices, like so: html, body { width: 640px; padding: 25px; margin-left: auto; margin-right: auto; } All elements have the same margin on both sides and a padding of 25px. While th ...

Issue with cdk-virtual-scroll-viewport: Scroll function malfunctioning when using navigation up/down button

While utilizing cdk-virtual-scroll-viewport within my mat-autocomplete, I have noticed that scrolling works perfectly when using the mouse but does not function properly when pressing the keydown button. Expected Behavior: The list should automatically sc ...

Tips for expanding Bootstrap 5 text area within tabbed interfaces

I am struggling to properly position a text area within a tab and have it stretch both horizontally and vertically within the card body. Despite trying to use d-flex and align-self-stretch, the tab content div does not seem to respond as expected. My att ...

Tips for effortlessly enlarging an element

When you click on "#sidebarnav>li", the following happens: 1) The second child of it - <ul> element will expand and its class toggles between "collapse" and "collapse in". 2) "#sidebarnav>li" will receive the "active" class. 3) The "aria-ex ...

The div's background height doesn't adjust according to the content in my project, and I'm struggling to fix it

On industrukt.pl/dev/ap/barbara.html, I am struggling to make the background color of the article section extend 100% of the photos. Currently, I have set a constant height value, but this solution is not ideal. When the browser window is resized to mobile ...

Firefox animation causes text to flash intermittently

I am looking to create a slide animation using CSS and AngularJS. I have made progress with this example: JSFiddle. The animation works smoothly on Chrome, but on Firefox, the text shakes and flickers slightly during the animation. I am struggling to pinpo ...

How can you ensure your CSS code is functional across various browsers?

I have been exploring CSS and HTML for about a week now, but I am facing a challenge that has me stuck for the past thirty minutes. The issue lies in adapting this code to work smoothly across different browsers. While it aligns images in a row of four per ...

Ways to implement CSS with javascript

I'm using PHP to retrieve data from my database and then leveraging Javascript to enable users to add it. However, I am facing challenges in making a div change its background color and apply borders. <div class="displayedItems"></div> &l ...

I'm trying to create a customer slider using the codes provided, but unfortunately, I'm encountering some issues

I'm having trouble creating a slider that pulls all slider data from the database. Here are my codes, but the output is looking strange. I've attached a screenshot of the slider as well. I've tried everything, but I can't seem to figure ...

Creating a stationary menu on the header that overlaps both the header and content on mobile browsers

I'm currently in the process of developing a website, but I've hit a snag that I can't seem to figure out. You can view the website at . I'm focusing on mobile-first design, so for the best view, try shrinking the browser screen. When ...

Selection box and interactive buttons similar to those found in Gmail

Looking to achieve these effects for <option> and <button> using CSS and JavaScript. Any suggestions on how to do this? ...

Panes designed with a vertical header that remains fixed while scrolling

I've encountered a challenge in HTML/CSS with my desired setup. I am looking for: A header panel that remains fixed at the top of the page, stretching to fill the available width while also having a minimum width; A content section that can be scrol ...

Iterating through two classes in a Javascript loop

Hello, I'm facing a small obstacle that I'm hoping to overcome using JavaScript/jquery. Essentially, I have multiple div classes and I want to create a loop that adds a class to specific divs without manually assigning an id to each one. The goal ...

Make a <div> element that has a fixed size, but allows for scrolling text inside

I have tried searching the forum for a solution to my problem, but haven't found one yet. I am trying to create two "divs" with fixed height and internal scrolling. However, whenever I add text inside one of them, its height increases accordingly. Wha ...

"Discover the simplicity of customizing Bootstrap 5 with an easy-to-use online tool

When I was using Bootstrap 3, there was a convenient tool that allowed me to customize which features I wanted in the minified CSS/JS files to improve loading time. Now, as I delve into the documentation for Bootstrap 5, I find myself struggling to unders ...