0

I have an element in my Web Page <div class="col-md-12"></div>. Currently it is maintaining width of parent element. But if I apply position: fixed; on <div class="col-md-12"></div> it's width increases.

How to keep previous width with position: fixed; ?

1
  • 2
    "position: fixed" elements do not have a parent, they are considered out of the page flow. You could explicitly state a width, or you could use "position: absolute" to position the element relative to the parent. Depends on your use case. Commented Nov 15, 2022 at 8:27

2 Answers 2

2

set width to inherit so the child gets the width of the parent

width: inherit;
Sign up to request clarification or add additional context in comments.

Comments

1

The CSS specification requires that position:fixed be anchored to the viewport, not the containing positioned element.

Other way to do it is :- To set parent element position: relative; and child element position: absolute;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.