马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
- <div class="content">
- <img src="src\assets\404_images\xxmLogo.png" alt="">
- <div class="frosted-glass">
- <p>This is a frosted glass effect.</p>
- </div>
- </div>
复制代码- .frosted-glass {
- position: absolute;
- top: 10vh;
- left: 0;
- right: 0;
- margin: auto;
- width: fit-content;
- background: rgba(0, 0, 0, 0.3);
- font-size: 28px;
- color: #fff;
- border-radius: 40px;
- padding: 8px 28px;
- backdrop-filter: blur(10px);
- }
- .content {
- position: relative;
- width: 800px;
- height: 800px;
- }
- img {
- width: 100%;
- height: 100%;
- }
复制代码 效果图:
fit-content 是 CSS 中用于动态调解元素宽度或高度的一个值。它根据内容的尺寸和容器的可用空间来盘算元素的巨细。fit-content 告急用于相应式筹划场景下,当你渴望元素尺寸根据内容自顺应,但又不超出特定限定时。
fit-content 可以用于 width、height、max-width 和 max-height 等属性。
fit-content 盘算出的宽度便是内容所需的最小宽度,除非被容器的束缚条件(如最大宽度或可用空间)限定。
拓展
margin: 0 auto; 不能使 .frosted-glass 元素程度居中的缘故原由是元素的 position: absolute; 属性使其离开了文档流。在这种环境下,margin: 0 auto; 无法正常工作,由于绝对定位元素不受通例的主动边距影响。
方法一:利用 left: 0; right: 0; 团结 margin: auto;
方法二:利用 left: 50%; 团结 transform: translate(-50%);
|