固定与绝对 [英] Fixed vs. absolute

查看:100
本文介绍了固定与绝对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我检查了网站,发现问题与我所寻找的问题很接近,但又不完全相同。

So I've checked the site and I've seen questions close to what I am looking for but not exactly the same.

我正试图找出答案如何定位元素,以便在滚动(上/下)时位置是固定的,但是在调整浏览器大小(左/右)时位置是绝对或相对。

I am trying to figure out how to position an element so that when scrolled (up / down) the position is fixed, but when the browser is resize (left / right) the position is absolute or relative.

基本上,我想从浏览器窗口的左上角放置一个元素(例如,占10%),并使其停留在滚动/窗口调整大小上。

Essentially I want to place an element 10% (for example) from the top left of the browser window and have it stay there on scroll /window resize.

推荐答案

即使浏览器滚动/调整大小,如果您想要的内容始终固定在某个位置,则可以针对CSS尝试尝试此操作

if what you want is always fixed in some position even if the browser is scrolled / resized, you may try this for your css

.fixedelement {
  position: fixed;
  top: 10%;
  left: 10%;
  width: 80%; /*my example*/
  height: 10%;
}

这篇关于固定与绝对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆