Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
254 views
in Technique[技术] by (71.8m points)

css - Absolute positioning vs relative parent: any workaround?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You would need JavaScript for that. You could try adding a css class to the element with document.queryselector('.your-element-class').classList.add('some-class') that overrides position relative with something like this:

.some-class { 
  position: absolute;
  top: 15%;
  left: 15%;
  z-index: XX; /* for example '2' or '99' if needed */
}

On closing the element, use classList.remove(...) to remove the overriding CSS class, and your element will jump back into the regular HTML flow. Consider how to handle scrolling. You can prevent vertical scroll while the some-class is active by adding vertical-scroll-y: hidden; or you could use position:fixed; instead so the element doesn't move when scrolling the rest of the content.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...