CSS 图像放置方式取决于屏幕分辨率

发布于 2024-12-05 01:05:38 字数 489 浏览 2 评论 0原文

如果您导航到 http://magee.darkslidedesign.com,您将在 jQuery Slides 的主页上看到图像。幻灯片的两侧都有一个“上一页”和“下一页”按钮。

我将这些图像放置在以下 CSS 中的某个位置...

#slides .next,#slides .prev {
    position:absolute;
    margin-top: -215px;
    width:24px;
    height:43px;
    display:block;
    border: 0;
}

#slides .next {
    margin-left: 827px;
}

如果一个人的分辨率较低或较高,我需要一些帮助来尝试找出使这些箭头保持在 1600x900 分辨率的同一位置的最佳方法。

帮助?

If you navigate to http://magee.darkslidedesign.com you will see images on the main page in jQuery Slides. On either side of the slide, there is a "previous" and "next" button.

I have these images placed in a certain location in the following CSS...

#slides .next,#slides .prev {
    position:absolute;
    margin-top: -215px;
    width:24px;
    height:43px;
    display:block;
    border: 0;
}

#slides .next {
    margin-left: 827px;
}

I need some help trying to figure out the best way to have these arrows stay at the same spot they are in 1600x900 resolution if a person has lower or higher resolution.

Help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

腻橙味 2024-12-12 01:05:38

嗯...布局有点时髦...你可以做的一件事是删除 .prev 上的 margin-left: 100px;,删除 margin- .next 上的 left: 827px,将 right:0px; 添加到 .next,最后添加 position:relative到60% 宽的容器,用于容纳幻灯片 div。您可能还想将 min-width: 750px; 放置到同一个 60% 宽的 div 中。

如果您始终希望它们保持在同一位置,请为 60% 宽的 div 指定 800px 左右的固定宽度 (width:800px)。

Hm... the layout is kinda funky... one thing you can do is remove margin-left: 100px; on .prev, remove the margin-left: 827px on .next, add right:0px; to .next, and lastly add position:relative to the 60% wide container that holds the slides div. You may also want to put a min-width: 750px; to that same 60% wide div.

if you always want them to stay in the same spot, give the 60% wide div a fixed width of 800px or so (width:800px).

泪之魂 2024-12-12 01:05:38

修复这个问题非常困难,因为 html 代码首先是无效的。另外,在箭头上设置绝对位置并不是明智之举,因为它开始非常依赖于标题......而它应该仅依赖于滑块本身。看来当你改变位置时:absolute;在#slides .next,#slides .prev 内,滑块将停止正常工作。感觉就像滑块被放置在 .prev 所在的任何位置。所以 .prev 就像一个占位符。

基于这些原因,我坚信,仅从 CSS 的角度无法解决这个问题。我建议优化您的 HTML,使其有效。并且可能使用不同的滑块。因为,通常将箭头放在滑块外部看起来像这样:

<style>
#hero_wrapper {float: left; border: 1px dotted blue; padding: 0px 60px;}
    #hero_images {border: 1px dotted red; width: 500px; height: 300px;}
    #hero_prev,
    #hero_next {position: relative; margin-top: 110px; padding: 20px; font-size: 30px; font-weight: bold; border: 1px dotted green; /* #hreo_next special: */ float: left; margin-left: -60px;}
    #hero_next {float: right; margin-right: -60px;}
</style>
<div id="hero_wrapper">
    <div id="hero_prev"><</div>
    <div id="hero_next">></div>
    <div id="hero_images"></div>
</div>

[ 查看输出 ]

很抱歉,我无法给您具体的答案,但我希望当您了解基本概念有多么简单时..您会重新考虑使用该滑块(因为我假设滑块 DOM 结构不是最佳选择。)此外,从技术上讲,您只需找到一个具有独立箭头的滑块(我个人喜欢 jQuery Orbit 插件)并简单地使用我的滑块结构的基本概念。因为,在这种情况下,您只需使 #hero_images 滑动并将 prev 和 next 函数挂接到箭头上,瞧!

一些提示:

  • 正如我在上面的评论中提到的,您的菜单图像应该位于精灵中,因此白色背景不会在翻转时显示。
  • xhtml 中的元标记应以 / 结束。
  • 此外,谷歌分析强烈建议将其代码放在页脚的 之前。
  • 在现代网站开发中,没有人想要图像边框。如果他们这样做,那么他们无论如何都会手动设置它(.someimg {border: 1px Solid black;})。因此要避免无效的xhtml,然后在顶部添加预定义的img值你的 css: img {border: 0px;}
  • 另外你还有一些其他的非标准属性。 使用验证器!
  • 通常在滑块中,图像被放入 ul 列表中。

It is very difficult to fix this as the html code is not valid as a first thing. Also, having position absolute on your arrows is not a wise thing to do, as it starts to very dependent of the header..while it should be depending on only the slider itself. It appears that when you change the position: absolute; inside #slides .next,#slides .prev, then the the slider stops working correctly. It almost feels, like the slider is being put wherever .prev sits. So the .prev is like a placeholder.

Based on those reasons, I strongly believe, that you cannot fix this problem from CSS point of view only. I recommend to optimize your HTML, make it valid. And possible use a different slider. Because, usually placing the arrows outside the slider looks something like this:

<style>
#hero_wrapper {float: left; border: 1px dotted blue; padding: 0px 60px;}
    #hero_images {border: 1px dotted red; width: 500px; height: 300px;}
    #hero_prev,
    #hero_next {position: relative; margin-top: 110px; padding: 20px; font-size: 30px; font-weight: bold; border: 1px dotted green; /* #hreo_next special: */ float: left; margin-left: -60px;}
    #hero_next {float: right; margin-right: -60px;}
</style>
<div id="hero_wrapper">
    <div id="hero_prev"><</div>
    <div id="hero_next">></div>
    <div id="hero_images"></div>
</div>

[ View output ]

I'm sorry that I cannot give you concrete answers, but I hope that when you understand how easy the basic concept is.. you will reconsider using that slider (as I'm assuming that the sliders DOM structure is not optimal.) Also, technically you simply find a slider that has stand-alone arrows (I personally like the jQuery Orbit Plugin) and simply use my basic concept of the slider structure. Because, in that case you only need to make the #hero_images slide and hook the prev and next functions to the arrows, and voila!

Some pointers:

  • As I mentioned in the comment above, your menu images should be in a sprite, so the white background wouldn't get displayed on rollover.
  • Meta tags should be ended with / in xhtml.
  • Also google analytics strongly recommends to put their code before </body> in the footer.
  • In modern website development nobody wants borders for images. And if they do, then they will set it manually anyways (.someimg {border: 1px solid black;}). So to avoid non-valid xhtml, then add predefined img value on the top of your css: img {border: 0px;}
  • Also you got some other non-standard attributes. Use a validator!
  • Normally in a slider the images are put inside a ul list..
苹果你个爱泡泡 2024-12-12 01:05:38

尝试这样的事情:

#slides {
    position:relative;
}

#slides .next,#slides .prev {
    position:absolute;
    top:30px; // use this instead of margins, of course change the value
    left: -30px // Try with this
    width:24px;
    height:43px;
    display:block;
    border: 0;
}

#slides .next {
    right: -30px; // Change the value
}

Try something like this :

#slides {
    position:relative;
}

#slides .next,#slides .prev {
    position:absolute;
    top:30px; // use this instead of margins, of course change the value
    left: -30px // Try with this
    width:24px;
    height:43px;
    display:block;
    border: 0;
}

#slides .next {
    right: -30px; // Change the value
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文