English 中文(简体)
如何使一幅巨大的图像上的文字在所有决议上都处于适当的位置?
原标题:How to keep text over a huge image in proper position on all resolutions?

在我的内页上,我有一个非常大的高度和宽度图像,以适应所有分辨率(宽度超过4000px),我将其设置如下:

#source-image {
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

然后,我添加了一些文字 上面的图像 与这些样式属性:

.description {
    position:absolute;
    top:510px;  
    left:23px;
    width:340px
}

在我的15.6英寸的笔记本电脑上,

""https://i.sstatic.net/BwwV4.png" alt="此处输入图像描述"/ >

然而,当我室友在他的高分辨率监视器上看到这个描述时,他并没有站在“正确”的位置上。 当然,我理解为什么会发生这种情况。

""https://i.sstatic.net/Uxpky.png" alt="此处的内置图像描述"/ >

My question is how can I keep dynamically the proper position of the description text in all resolutions? Thank you very much.

最佳回答

设置底部的距离, 而不是顶部的距离。 或者将其设置为% 。

EDIT: I ve adapted one of my experiments into an example: http://dabblet.com/gist/2787061 The position of the description is set relative to the bottom and the left of the image container (the image is filling its entire container).

在第一种情况下,图像容器的left bottom 之间的距离以px形式固定。

第二种情况是,它们位于%,在调整浏览器窗口的大小时发生变化。

基本上说来,玩花招的规矩是

figcaption {
    bottom: 5px;
    left: 23px;
        /* more rules here */
}

在拳头框中(固定距离, px) 和

figcaption.perc {
    left: 10%;
    bottom: 17%;
}

第二种情况(百分比)。

Also, please note that you don t need position: absolute or to set the top and the left properties for the image. However, you do need to set position:relative on the parent of the description box.


要填满屏幕 horizontally 图像,您需要具备以下图像: margin:0; pading:0; width:100%; margin:0; 在图表元素上。我编辑了我的示例以反映这些变化: http://dabblet.com/gist/27929

要小心,原因有二:一,这会扭曲图像,在调整浏览器窗口大小时会使图像看起来丑陋,二,如果您需要图像下面的某些内容,您需要给外元素 < code> 定位: 绝对 并设置其 < code> 顶部: 100\\\ / code > 。这两个方面都可以在链接的示例中看到。如果您不需要,您只需删除图像下面的内容。

问题回答

使用 < code> position: relal; 用于覆盖图像的 div 和 position: absolute; 用于文本 div

请设定百分比

检查水平中心设置的示例 - 描述框,

将第一个设置位置相对相对设置为折叠 Div

.description {
    position:absolute;
    top:510px;  
    left:50%;
    width:340px;
    margin:0 0 0 -170px
}




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签