简体   繁体   English

CSS Fluid Image问题

[英]CSS Fluid Image issue

My background of my site is responsive and works great.But I'm having issues with the images. 我的网站背景反应灵敏,效果很好。但是图片有问题。 I want them to look "fixed" as in the same position with the background no matter the resolution,. 无论分辨率如何,我都希望它们看起来与背景处于“固定”位置。 Example re-sizing the browser from 990px by 537px to 990px by 270px the image will look like it never moved because the width/height will expand or contract depending on the resolution of the browser. 将浏览器的大小从990px​​ x 537px调整为990px​​ x 270px的示例看起来像从未移动过,因为宽度/高度将根据浏览器的分辨率而扩大或缩小。

Good news I figured the CSS to make the WIDTH of the image fluid with the background! 好消息是,我发现CSS使背景的宽度变得流畅! Bad news is if I make height 100% or 14%, the height looks the same. 坏消息是,如果我将身高设为100%或14%,则身高看起来相同。 Is it true that I need to specificity my height? 我需要确定自己的身高吗? Why not width? 为什么不宽? How? 怎么样?

#block-imageblock-4{
    width:26%;
    height:14%;
     margin-top:7%;
     margin-bottom:1%;
    margin-left:37%;
    margin-right:36.5%;
        max-width:100%;
    max-height:100%;


}

SO my question is how would I show my image to look like its in the SAME position on the screen if my resolution is very large or very small? 所以我的问题是,如果我的分辨率很大或很小,如何在屏幕上的相同位置显示图像? Please provide a example and not just a link. 请提供一个示例,而不仅仅是一个链接。 Like I said I figured out to make the width of the image fluid, just not the height but if you have a better way please share. 就像我说过的那样,我想出了使图像的宽度可变的方法,但并不是使高度变宽,但是如果您有更好的方法,请分享。

I'm using Drupal to build my site FYI. 我正在使用Drupal构建我的站点供参考。

<---------------------------------------------EDIT----------------------------------------> <---------------------------------------------编辑--- ------------------------------------->

Here are two example of what I am talking about. 这是我所谈论的两个例子。 Please ignore all images BUT the image labeled IMAGE1. 请忽略所有图像,但标记为IMAGE1的图像。

CSS for Image1: Image1的CSS:

 #block-imageblock-4{
        width:26%;
        height:14%;
         margin-top:7%;
         margin-bottom:1%;
        margin-left:37%;
        margin-right:36.5%;
            max-width:100%;
        max-height:100%;


    }

First Image- Browser Resolution: 480px by 356px 第一张图片浏览器分辨率:480px x 356px

在此处输入图片说明

Second Image- Browser Resolution: 520px by 630px 第二张图片-浏览器分辨率:520px x 630px 在此处输入图片说明

the code in js fiddle: JSfiddle js小提琴中的代码: JSfiddle

Here is how I did it with CSS: 这是我使用CSS的方法:

html {
    background-color: black;
}

#master {
    position: relative;
}

#img {
    width: 23%;
    max-width: 120px;
    display: inline-block;
    background-color: red;
    position: absolute;
    bottom: 80%;
    height: 10%;
    max-height: 40px;
    margin-top: -80px;
    left: 50%;
    margin-left: -40px;
}

HTML: HTML:

<div id="master"> </div>
<div id="img"> </div>

You make an outer div ie master set it to relative position the image itself you give the properties i mentioned edit the width and height according to the image size you have, and edit margin-top and margin-left to offset it to fit it exactly to the position you wish, and it will all work fluidly, hope that helps. 您制作了一个外部div,即master将其设置为图像本身的相对位置,并赋予了我提到的属性,根据您拥有的图像大小编辑宽度和高度,并编辑margin-top和margin-left以使其完全匹配到您想要的位置,一切都会顺利进行,希望对您有所帮助。

as well as editing the bottom:X%; 以及编辑底部:X%; (percentage number in the X) to edit the position in the y-axis. (X中的百分数)以编辑y轴上的位置。

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

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