Some content...
I have a positioned div whose content can be too long so scrollbars appear (overflow:auto set). It functions as a dialog box in an ajax app. I want to fix a clo
I achieved to have an element with a fixed position (wiewport) but relative to the width of its parent.
I just had to wrap my fixed element and give the parent a width 100%. At the same time, the wrapped fixed element and the parent are in a div which width changes depending on the page, containing the content of the website. With this approach I can have the fixed element always at the same distance of the content, depending on the width of this one. In my case this was a 'to top' button, always showing at 15px from the bottom and 15px right from the content.
https://codepen.io/rafaqf/pen/MNqWKB
Some content...
.content {
width: 600px; /*change this width to play with the top element*/
background-color: wheat;
height: 9999px;
margin: auto;
padding: 20px;
}
.top-wrapper {
width: 100%;
display: flex;
justify-content: flex-end;
z-index: 9;
.top {
display: flex;
align-items: center;
justify-content: center;
width: 60px;
height: 60px;
border-radius: 100%;
background-color: yellowgreen;
position: fixed;
bottom: 20px;
margin-left: 100px;
cursor: pointer;
&:hover {
opacity: .6;
}
}
}