简体   繁体   English

不应该移动的div?

[英]Divs moving around when they should not?

I'm making a website for a project I'm involved in and I can't figure out why some of my divs are moving around when resizing the page while others aren't.我正在为我参与的项目创建一个网站,但我无法弄清楚为什么我的一些 div 在调整页面大小时会四处移动,而另一些却没有。 I'm fairly new to both HTML and CSS so it might be something very basic but I can't figure out what it is.我对 HTML 和 CSS 都很陌生,所以它可能是非常基本的东西,但我不知道它是什么。 I think I've given all of my divs proper sizing, this is my code.我想我已经给了我所有的 div 适当的大小,这是我的代码。

CODE代码

 .wrapper { position: relative; }.bakgrund { /*background-image: url("img/bakgrund.png");*/ background-image: url("https://dummyimage.com/1400x1400/000000/fff"); height: 1400px; width: 1400px; position: absolute; }.logo { /*background-image: url("img/logo1.png");*/ background-image: url("https://dummyimage.com/821x1082/d415d4/fff"); height: 1082px; width: 821px; top: -180px; right: 15%; position: absolute; }.nav { left: 670px; top: 450px; position: absolute; }.undertitel { right: 630px; top: 500px; position: absolute; }
 <div class="wrapper"> <div class="bakgrund"></div> <div class="logo"></div> <div class="nav"> <a href="index.html">Hem</a> <a href="kluringar.html">Kluringar</a> </div> <div class="undertitel"> <p>"Många är kallade, få är utvalda"</p> </div> </div>

When I open the HTML-document and resize the browser window both the div 'logo', 'undertitel' and 'bakgrund' moves with the page, while 'navbar' kind of stays in the same place, why is that?当我打开 HTML 文档并调整浏览器 window 的大小时,div 'logo'、'undertitle' 和 'bakgrund' 都随着页面移动,而 'navbar' 则停留在同一个地方,这是为什么呢?

becouse u set position:absolute with right:15% it will adjust with screen width other div do not have right property因为你设置position:absolute with right:15%它将随着屏幕宽度调整其他 div 没有right属性

read for more info阅读更多信息

https://www.w3schools.com/cssref/pr_class_position.asp https://www.w3schools.com/cssref/pr_class_position.asp

https://www.freecodecamp.org/news/how-to-understand-css-position-absolute-once-and-for-all-b71ca10cd3fd/ https://www.freecodecamp.org/news/how-to-understand-css-position-absolute-once-and-for-all-b71ca10cd3fd/

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM