简体   繁体   English

定位图像

[英]Positioning images

So, I'm trying to do something like this: 所以,我正在尝试做这样的事情:

在此处输入图片说明

The web page is supposed to look like a phone app, and it has to be responsive. 该网页应该看起来像电话应用程序,并且必须具有响应能力。 The problem is that I can't position the buttons right. 问题是我无法正确定位按钮。 They always move in relation to the 'tablet' whenever I'm re-sizing the browser window. 每当我调整浏览器窗口大小时,它们始终相对于“平板电脑”移动。 This is what I've tried (with only one button): 这是我尝试过的(只有一个按钮):

CSS CSS

img {
max-width: 100%;
}
#tabletBG {
width : 60%;
}
#buttons{
position:absolute;
width:10%;
left:40%;
top:12%;
}

HTML HTML

<div id="content">
    <div id="tablet">
        <img id="tabletBG" src="images/tablet.png" alt="tabletBG"></img>
        <div id="buttons">
            <img id="quienes" src="images/quienes.png" alt="quienes"></img>
        </div>
    </div>

</div>

I just want the buttons to stick to the tablet. 我只希望按钮贴在平板电脑上。 Even if i'm re-sizing the browser window. 即使我正在调整浏览器窗口的大小。 Is there an easier way of doing this? 有更简单的方法吗? Thanks. 谢谢。

Regarding your original question above: 关于上述原始问题:

Try setting the position of your content div to absolute , fixed , or relative . 尝试将content div的position设置为absolutefixedrelative

This will ensure that your absolutely positioned buttons div contained within it will use it as a reference point rather than referring its resizing/relocating to the window. 这将确保您包含在其中的绝对定位buttons div将用作参考点,而不是将其调整大小/重新定位指向窗口。

DEMO: http://jsbin.com/tixed/1/ 演示: http : //jsbin.com/tixed/1/

Regarding your comment below: 关于您的以下评论:

It works, but for an extent. 它有效,但在一定程度上。 There's a point that if you keep expanding the browser window, the tablet will keep expanding, but the button won't. 有一点是,如果您继续扩展浏览器窗口,平板电脑将继续扩展,但按钮不会扩展。 Here's a link . 这是一个链接

The problem there is that your image is only 96 pixels wide, and you've set a CSS rule for all img elements to have a max-width: 100% . 问题在于您的图像只有96像素宽,并且您已为所有img元素设置了CSS规则,以使其具有max-width: 100% Under these conditions, the image will expand only to the point of its original size (the default action, and not what you want), and only to the point of its containing element (by your CSS rule, and to no noticeable effect). 在这种情况下,图像将仅扩展到其原始大小的点(默认操作,而不是您想要的), 并且仅扩展到其包含元素的点(根据CSS规则,不会有明显的效果)。

To correct, ideally you would get a larger image. 要更正,理想情况下,您将获得更大的图像。 For a quick fix, change its rule to be simply width: 100% . 为了快速解决,请将其规则更改为width: 100% This will ensure the image always expands to the point of its containing element. 这将确保图像始终扩展到其包含元素的位置。

Yes, whenever you re-size your browser the images will change their alignment and this is a default behavior of browsers. 是的,每当您调整浏览器大小时,图像都会改变其对齐方式,这是浏览器的默认行为。 Only you can make this images to float. 只有您可以使此图像浮动。

Try this: 尝试这个:

img{
  float: left;
}

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

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