简体   繁体   English

调整浏览器大小时元素正在移动

[英]elements are moving when resizing browser

So here is my site live as of two weeks ago. 因此,这是两个星期前我的网站上线了。

http://zissoukeys.com/WNM249FINAL-/sk1.html http://zissoukeys.com/WNM249FINAL-/sk1.html

The problem I am having is that the axe button on the right and my navigation bar are moving separately from the rest of my elements when resizing the browser window and I'm trying to fix this. 我遇到的问题是,在调整浏览器窗口大小时,右侧的ax按钮和导航栏正在与其余元素分开移动,而我正在尝试解决此问题。 I either want them to all be fixed, or for them to all move together when resizing the browser. 我要么希望它们全部修复,要么让它们在调整浏览器大小时一起移动。

I've been looking online and can't figure this out. 我一直在网上寻找,无法解决。 If I try putting them all in one block then everything gets thrown askew and my buttons are not clickable any longer. 如果我尝试将它们全部放在一个块中,则所有内容都会歪斜,并且按钮不再可单击。

I'm a novice to css and html. 我是CSS和HTML的新手。 But I'm trying to learn here and figure out what I'm doing wrong. 但是我想在这里学习,弄清楚我做错了什么。 Any help would be highly appreciated. 任何帮助将不胜感激。 Thanks. 谢谢。

As mentioned in the comments, the elements that are moving are either placed using percentages that are relative to their container or floated, such as the axe, which pins it to the right side and moves as that side moves. 如评论中所述,要移动的元素要么使用相对于其容器的百分比放置,要么浮动(例如斧头),将其固定在右侧并随着该侧移动而移动。

The center div does not move because it's at a fixed position. 中心div由于处于固定位置而不会移动。 If you want that to also expand and collapse to make room for the other elements, in a fluid way, you will have to make its width as a percentage rather than a px value. 如果您还希望它可以扩展和折叠以为其他元素留出空间,则必须以一种可变的方式使其宽度作为百分比而不是px值。

Now things start getting complicated because the contents of that center div will eventually shrink and pile on top of each other. 现在事情开始变得复杂,因为该中心div的内容最终将缩小并堆积在彼此的顶部。 Thus the problems of fluid/responsive web development but also makes your question a little too broad to answer completely. 因此,流畅/响应式Web开发的问题还会使您的问题过于广泛而无法完全回答。

CSS positioning is a powerful tool, but should not be used in this manner. CSS定位是一个功能强大的工具,但不应以这种方式使用。 Reorder your HTML so that you don't need to absolutely position everything. 重新排列您的HTML,以便您不必绝对定位所有内容。 Then use margins to position the axe buttons properly. 然后使用边距正确定位斧头按钮。

I'd suggest something like the following: 我建议类似以下内容:

HTML: HTML:

   <nav>  
   <leftaxe>
   <rightaxe>
   <box>

CSS: CSS:

/* remove position:absolute and left, right, top, bottom styles */
.leftaxe, .rightaxe { margin:302px auto 0; }

There will likely be other CSS adjustments to make, but this should get you on a better track. 可能还会进行其他CSS调整,但这将使您步入更好的轨道。 Happy Coding. 编码愉快。

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

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