简体   繁体   English

如何在页面顶部插入DIV元素并向下滑动具有绝对顶部的其他元素:0 css styles

[英]How to insert DIV element at the top of the page and slide down other elements that have absolute top:0 css styles

I have web site with very complicated elements structure and CSS styles where many elements have position:absolute and top:0 styles applied. I have web site with very complicated elements structure and CSS styles where many elements have position:absolute and top:0 styles applied.

There are many divs one inside others and so on (I inherited this web from former owner)其他里面有很多 div 等等(我从前所有者那里继承了这个 web)

Is it somehow possible to insert div element in top of the page and slide down all other elements without need for changing others CSS styles?是否可以在页面顶部插入 div 元素并向下滑动所有其他元素而无需更改其他元素 CSS styles? Some kind of inserting header with some text that would "override" other styles...某种插入 header 的一些文本会“覆盖”其他 styles...

You can use a little bit of javascript to get the height of the element you want to be at the top, and then move the others down based on that height, like so您可以使用一点 javascript 来获取您想要位于顶部的元素的高度,然后根据该高度将其他元素向下移动,就像这样

 $(function() { var item = $(".item"); var itemHeight = item.outerHeight(); $(".middle").css({ "top": itemHeight + "px" }); $(".bottom").css({ "top": itemHeight * 2 + "px" }); });
 body { margin: 0; } main { height: 100vh; min-height: 500px; width: 100%; background: DarkOrchid; }.top, .middle, .bottom { height: 100px; width: 85%; position: absolute; top: 0; left: 50%; transform: translateX(-50%); display: flex; justify-content: center; align-items: center; color: #fff; font-family: sans-serif; }.top { background: goldenrod; }.middle { background: royalblue; }.bottom { background: tomato; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <main> <div class="top item">this is the top one</div> <div class="middle item">this is the middle</div> <div class="bottom item">this is the bottom one</div> </main>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 div中的绝对元素不会出现在其他元素之上 - Absolute element inside div won't appear on top of other elements jQuery slideDown() - 绝对定位div从页面顶部向下滑动,需要从页面上的特定区域滑动 - 如何? - jQuery slideDown() - absolute positioned div sliding down from top of page, need to slide from specific area on page - how? 如何在网页的其他所有元素之上创建div - How to make a div on top of every other element of a web page 如何在不依赖页面中使用的结构/样式的情况下,在页面上的每个其他元素之上呈现元素? - How to render an element on top of every other element on page without depending on the structure/styles used in the page? 如何下推页面并在顶部附加div? - How to push page down and append a div at top? 尝试使用 - 顶部定位和jquery动画在点击时使div向下和向上滑动 - trying to make a div slide down and up from top of page using - top positioning and jquery animate upon click 如何在其他 div 之上排列 svg 元素? - How to arrange svg elements on top of other div? 其他元素之上的CSS元素 - CSS Elements on top of other elements 如何将div与绝对位置垂直对齐在一起? - How to vertically align a div with absolute position on top of each other? 如何仅使用 CSS 将 Div 修复到页面顶部 - How to fix a Div to top of page with CSS only
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM