是否可以使元素相对于某些特殊元素的位置绝对?我谈论的不仅仅是众所周知的相对/绝对优惠。假设这个嵌套 div 包含#a > #b > #c > #d前一个的每个子元素。现在是否可以使 c 的位置相对于 a 为绝对位置,而 d 的位置相对于 b 为绝对位置?或者甚至可能相对于某个不是该元素父元素的元素。有在任何地方讨论过吗?我想如果当前版本中没有的话,应该在未来版本的 css 中添加它。
父级具有百分比宽度。我正在寻找一种简单的方法来保持子 div:.wrp位于其父级的中心:.contr即使它溢出父级甚至溢出页面。我尝试过绝对定位,但它在这里似乎不起作用。
例子:
有想法吗?
body {
overflow: hidden;
padding: 5%;
text-align: center;
}
.contr { /* << contr = Container */
width: 40%;
height: 95%;
background-color: #eee;
}
.wrp { /* << wrp = Wrapper */
width: 5rem;
height: 5rem;
margin: auto;
background-color: #bbb;
opacity: 0.75;
}
.expand {
animation-name: expand;
animation-duration: 4s;
animation-iteration-count: infinite;
}
@keyframes expand {
50% {
width: 30rem;
}
}Run Code Online (Sandbox Code Playgroud)
<head>
<style>
@import url( 'https://necolas.github.io/normalize.css/latest/normalize.css' );
* {
box-sizing: border-box;
outline: …Run Code Online (Sandbox Code Playgroud)我是 Flexbox 新手,我的问题如下:
\n\n我的导航上有一个子菜单,绝对定位并使用弹性盒。
\n\n在 Chrome / Firefox 中一切正常,没有测试 Safari。
\n\nIE11 正在显示我的子菜单,但它的子元素溢出(这破坏了我的:hover)。
在 IE 中检查此 codepen 以查看问题(简化版本):
\n\nhttps://codepen.io/CamilleVerrier/pen/GvLojN
\n\n我尝试了 StackOverflow 或 CanIUse 中建议的很多内容,例如单独设置 flex 属性:
\n\nul.sub-menu li {\n flex-grow:0;\n flex-shrink:1;\n flex-basis:0px;\n}\nRun Code Online (Sandbox Code Playgroud)\n\n但这似乎不起作用。
\n\n在我的测试过程中,我发现如果删除position:absolute,一切都会恢复正常(但我的菜单显然会损坏)。
那么...是返回 inline-block 还是 float 的解决方案?(请不要啊哈哈)
\n\n谢谢 !(抱歉我的英语)
\n\nul.sub-menu li {\n flex-grow:0;\n flex-shrink:1;\n flex-basis:0px;\n}\nRun Code Online (Sandbox Code Playgroud)\r\n/* General styles */\r\n\r\nbody {\r\n background: tomato;\r\n font-size: 1.2rem;\r\n font-weight: bold\r\n}\r\n\r\na {\r\n color: black;\r\n text-decoration: …Run Code Online (Sandbox Code Playgroud)请参阅这个jsfiddle。
我想要<div>带有innerText“嗨!” 始终出现在其包含父级的可见部分的底部/右侧。它不应随其父级的内容一起滚动。
HTML:
<table>
<thead>
<tr>
<th style="width: 90%">Header 1</th>
<th style="width: 10%">Header 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div id="flex-div">
<div class="flex-item">1</div>
<div class="flex-item">2</div>
<div class="flex-item">3</div>
<div class="sticky-bottom-right">Hi!</div>
</div>
</td>
<td>more</td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
CSS:
table {
table-layout: fixed;
width: 100%;
}
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
#flex-div {
display: flex;
justify-content: space-between;
overflow: auto;
positiom: relative;
}
.flex-item {
background-color: beige;
border: 1px solid blue; …Run Code Online (Sandbox Code Playgroud) 我正在开发一个移动网站,angular-material该网站在页面上使用固定页脚。页脚始终存在并固定在底部。一切都运转良好。但是,当我滚动页面并且浏览器地址栏隐藏时,主体高度也会发生变化。结果是固定页脚也向上移动。
这是页脚的CSS如下:
.mobile-ui .footer-mobile{
position: fixed;
bottom: 0;
width: 100%;
z-index: 3;
left: 0;
right: 0;
}
Run Code Online (Sandbox Code Playgroud)
页脚有可能保持固定吗?
我不想强迫地址栏隐藏或保持固定。
我将固定位置模态放置在相对定位的元素内,没有转换且带有溢出:自动。
问题是,当父级溢出时,模式的背景不会覆盖滚动条 - 请查看所附图片的示例。
滚动条也应该被半透明的黑色背景覆盖,但由于某种原因它没有被覆盖。有谁知道为什么,和/或我如何解决这个问题?
我想避免对模式容器使用绝对定位,因为它可以是任何任意层次结构中的嵌套元素。
这是我的 .modal-container 类的 css,其中包括背景。
.modal-container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,.5);
opacity: 1;
transition: all .1s;
display: flex;
z-index: 200;
justify-content: center;
align-items: center;}
Run Code Online (Sandbox Code Playgroud) 我正在开发一个 Ionic 4 应用程序,并且在他们的类中遇到了一个固定位置页脚的奇怪问题.scroll-content。我可以在没有 Ionic 的情况下重现这个问题,所以我从更一般的意义上问这个问题:
我有一个容器元素(在我的例子中由 Ionic 提供),其中包含:
.scroll-content {
overflow-y: scroll;
position: absolute;
contain: layout size style;
}
Run Code Online (Sandbox Code Playgroud)
再加上一些顶部/底部/左/右值来定位它,它们不会影响问题。
它里面的内容比这个容器高,导致容器滚动,还有一个我用 粘起来的页脚position: fixed。
但是,除非我从属性中删除“布局”值,否则页脚的行为根本不像是粘性的contain。
.scroll-content {
overflow-y: scroll;
position: absolute;
contain: layout size style;
}
Run Code Online (Sandbox Code Playgroud)
let layout = true;
const container = document.querySelector('.scroll-content');
document.getElementById('toggleLayout').addEventListener('click', (e) => {
layout = !layout;
if(layout) container.style.contain = 'size style layout';
else container.style.contain = 'size style';
e.target.innerHTML = `layout: ${layout}`;
});Run Code Online (Sandbox Code Playgroud)
.scroll-content {
contain: layout size style;
left: …Run Code Online (Sandbox Code Playgroud)我希望 的高度<img>是100%其父级的高度,同时按比例缩放 的宽度<img>。<img>当具有绝对位置并且按预期工作时,这很容易做到。
*, *:before, *:after { box-sizing: border-box;}
body { margin: 0; }
.hero {
border: 2px solid red;
position: relative;
min-height: 360px;
}
.content {
/* Simulate content height */
/* height: 500px; */
}
.background {
border: 2px solid #2EA800;
}
img {
border: 2px solid #0083FF;
position: absolute;
top: 0;
right: 0;
height: 100%;
}Run Code Online (Sandbox Code Playgroud)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Example 1</title>
</head> …Run Code Online (Sandbox Code Playgroud)我正在尝试制作一个与标题重叠并在滚动时粘在窗口顶部的导航栏。
它将在滚动时开始top: 45px并停留在top: 0。
我的第一个方法是在事件上使用 JS 设置position: fixed; top: 45px并更改值scroll。但 Firefox 给了我关于这篇文章中讨论的“异步平移”的警告。
我已经能够通过一些 CSS 技巧来做到这一点,但我想知道是否有更简单的 CSS 方法或有效的 JS 方法来做到这一点(不发出警告)。
body {
position: relative;
height: 100%;
width: 100%;
background-color: grey;
overflow-x: hidden;
margin: 0;
}
.container {
position: absolute;
top: 0;
left: -1px;
width: 1px;
bottom: 0;
padding-top: 45px;
overflow: visible;
}
nav {
position: sticky;
top: 0;
transform: translateX(-50%);
margin-left: 50vw;
width: 300px;
height: 70px; …Run Code Online (Sandbox Code Playgroud)我有一个固定位置的工具提示,适用于除 Safari 之外的所有浏览器。在 safari 中,工具提示被父级容器切断,该容器具有以下属性overflow: scroll
关于如何解决这个问题有什么想法吗?
这是它应该是什么样子的屏幕截图:
这是它在 Safari 上的样子:
这些是工具提示的属性:
.announcement {
position: fixed;
width: 3.1rem;
height: 3.1rem;
background-image: url("./../assets/icons/announcement-alert-right.svg");
background-size: cover;
margin: 0 0 0 -2.8rem;
z-index: 1;
&:hover {
margin: -3.6rem 0 0 -14.8rem;
width: 15.3rem;
height: 6.7rem;
background-image: url("./../assets/icons/announcement-profile.svg");
}
@media screen and (max-width: $desktop) {
display: none;
}
}
Run Code Online (Sandbox Code Playgroud)
这是家长的观点:
.profile {
position: fixed;
z-index: map-get($zindex, sidebar);
right: 0;
width: 15%;
height: 100%;
transition: 0.5s;
padding: 3rem;
box-shadow: 0 1.5rem 3rem $color-shadow;
background-color: …Run Code Online (Sandbox Code Playgroud) css-position ×10
css ×9
html ×5
android ×1
background ×1
css-contain ×1
firefox ×1
fixed ×1
flexbox ×1
image ×1
javascript ×1
modal-dialog ×1
safari ×1
sticky ×1