【问题标题】:Absolute positioned image in responsive design响应式设计中的绝对定位图像
【发布时间】:2014-06-24 06:49:05
【问题描述】:

我需要一些帮助。

我目前正在开发一个响应式网站。
将发布指向该网站 psd 图像的链接,以便您了解
它应该是什么样的。

Link to the site itself
该站点的宽度为 1200 像素,当您缩放站点时,您会看到船什么也不做

现在解决问题。

问题出在这艘船上,这个 img 是 1019x1732 并且是绝对定位的。并且需要这样做,因为我必须使用 z-index 才能将其定位在其他一些 div 之上,因为它相当大。
我试图把它作为背景图像和一个带有相对 div 的 img 标签。但什么也没发生。

如果我的问题难以理解,我表示感谢。很难向其他人解释问题,它总是在我的脑海中更有意义。
这是我的代码:

我的html

<div id="wrapperHero">

        <div id="hero">

            <p>The "Banarly Group" has been operating<br>
                in Nigerian, Gabonese and Cameroon waters<br>
                since 1995.
            </p>
            <div id="circle">
                <p>a fleet of<br> 
                    <span class="number">24</span><span class="trawler">trawlers</p>
            </div>
        </div>
        <div id="boat">
            <img src="img/BAN_herofg.png" alt="boat">
        </div>

    </div>

我的 CSS:

#wrapperHero {
width: 100%;
background-image: url(../img/BAN_herobg.png);
background-repeat: repeat-x;
min-height: 795px;
margin-top: -23px;}

#hero {
max-width: 1200px;
width: 100%;
height: 100%;
margin: 0 auto;}

#boat {
background-image: url(../img/BAN_herofg.png);
background-repeat: no-repeat;
position: absolute;
height: 100%;
width: 100%;
z-index: 1;
right: -6%;
top: 240px;}

#circle {
border-radius: 50%;
width: 18.3333%;
min-height: 220px;
background-color: #fff;
background-color: rgba(255,255,255,0.2);
float: right;
margin: -230px 21.6666% 0 0;}

1

【问题讨论】:

  • 你没有解释你的问题,只是解释了网站是如何工作的。
  • 好吧,我的错,哈哈,问题是船不顺,只是站在角落里
  • 在某个视口大小甚至消失后,我尝试通过将图像放在一个相对的 div 中来解决这个问题,这确实使图像移动,但仅在某个视口大小之后。
  • 非常感谢大家。为了快速响应和快速回答。我对这个含糊不清的问题表示感谢。

标签: html css image positioning absolute


【解决方案1】:

如果我的问题是正确的,您应该这样做: 从#boat 中删除background-image 属性 在里面创建&lt;img src="img/BAN_herofg"&gt;max-width: 100% 设置为&lt;img&gt;

希望这能解决您的问题。

【讨论】:

    【解决方案2】:

    您可以将 background-size , background-position-x 与不同的媒体一起使用 :)

     #boat {
     background-size: 590px;
     background-position-x: 79px;
    }
    
     @media (min-width: 450px) and (max-width: 960px) {
         #boat {background-size: //use different size;
         background-position-x://use different size;}
    }
    

    【讨论】:

    • 我会试试这个。 background-size 和 min-max-width 需要以 % 为单位还是以 px 为单位。
    • 不一定,但如果你想也可以,这完全取决于你的需要:)
    【解决方案3】:

    使用 css 媒体查询来解决您的问题...

    例如:

      @media (min-width: 600px) and (max-width: 800px) {
      html { background: red; }
      }
    

    【讨论】:

    • 是的,我也想过这个问题,但是我会为每个屏幕尺寸进行媒体查询吗,因为在我的屏幕上,船在正确的位置,但在老板屏幕上更大,船是更多在右边
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-20
    • 2019-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多