When we apply position:fixed
to an element, it\'s taken out of the normal flow of the document, therefore it doesn\'t respect it\'s parent\'s element width.
Are the
As someone already suggest, using plain javascript (without jquery):
const parentElement = document.querySelector('.parent-element');
const fixedElement = document.querySelector('.fixed-element');
window.addEventListener('load', changeFixedElementWidth);
window.addEventListener('resize', changeFixedElementWidth);
function changeFixedElementWidth() {
const parentElementWidth = parentElement.getBoundingClientRect().width;
fixedElement.style.width = parentElementWidth + 'px';
}