简体   繁体   English

如何使图像与Web浏览器窗口的大小成比例缩放?

[英]How do I make images scale proportionally to the resizing of a web browser window?

My problem is as followed. 我的问题如下。 When I resize my browser window the middle image drops below 2 others which are beside it. 当我调整浏览器窗口的大小时,中间图像会降到旁边的其他2个图像以下。

  1. Image of it while working: Working website image 工作时的图像工作中的网站图像
  2. Image of it when browser is made smaller: Broken Website Image 缩小浏览器时的图像损坏的网站图像
  3. The same happens with smaller monitors and my code is bellow: 在较小的显示器上也会发生同样的情况,下面是我的代码:

HTML: HTML Code HTML: HTML代码

CSS:

.content {
padding-top:50px;
text-align: center;
}
.samp{
float: left;
width: 188px;
height: 356px;
margin-top: 50px;
margin-right: 0px;
margin-bottom: 5px;
margin-left: 320px;
}
.multiv{
float: left;
width: 247px;
height: 431px;
margin-top: 100px;
margin-right: 0px;
margin-bottom: 5px;
margin-left: 60px;
}
.minecraft{
float: right;
width: 234px;
height: 327px;
margin-top: 73px;
margin-right: 280px;
margin-bottom: 5px;
margin-left: 0px;
}

There are 3 images I just want them to stay in one place which is in the middle area and resize with the browser. 我只希望它们保留在中间区域的一个位置中并通过浏览器调整大小的3张图像。

change your code with this, bro... 改变你的代码,兄弟...

 .content {
    padding-top:50px;
    text-align: center;
    white-space: nowrap;
}

.samp, .minecraft, .multiv{
    vertical-align: top;
    display: inline-block;
}

.samp{
width: 247px;
margin-top: 50px;
margin-right: 0px;
margin-bottom: 5px;
margin-left: 320px;
}
.multiv{
width: 247px;
height: 431px;
margin-top: 100px;
margin-right: 0px;
margin-bottom: 5px;
margin-left: 60px;
}
.minecraft{
width: 234px;
height: 327px;
margin-top: 73px;
margin-right: 280px;
margin-bottom: 5px;
margin-left: 0px;
}

it'll give you a solid wrapper with no shifting, and you could tweak it from there :F 它会为您提供坚实的包装器,且不会移位,您可以从那里进行调整:F

Dont use float , simply use width:33.3% , and height:auto 不要使用float,只需使用width:33.3%height:auto

Example: 例:

http://fiddle.jshell.net/Ft3p4/ http://fiddle.jshell.net/Ft3p4/

You can do something along the lines of relative and absolute positioning and blocks with percentage based widths. 您可以沿着relativeabsolute定位以及带有基于百分比的宽度的块进行操作。

Result: http://jsfiddle.net/3mAh3/2/ 结果: http : //jsfiddle.net/3mAh3/2/

I gave it all a wrapper ( .collection class) and styled all div s using that class, can resize it to pretty much anything and it will also overlap nicely thanks to z-index 我给了它所有包装器( .collection类),并使用该类设置了所有div的样式,可以将其调整为几乎所有内容的大小,并且由于z-index ,它也可以很好地重叠

HTML 的HTML

<div class="content">
<div class="collection">
  <div class="samp">
    <a href="index.html"><img src="http://therealmgaming.com/images/samp.png" /></a>
  </div>
  <div class="multiv">
    <a href="index.html"><img src="http://therealmgaming.com/images/multiv.png" /></a>
  </div>
  <div class="minecraft">
    <a href="index.html"><img src="http://therealmgaming.com/images/minecraft.png" /></a>
  </div>
</div>
</div>

CSS: CSS:

 .content {
    padding-top: 50px;
    text-align: center;
 }
 .collection {
    position: relative;
    width: 100%;
 }
 .collection div {
    position: absolute;
    width: 33%;
 }
 .multiv {
    top: 50px;
    left: 33%;
    z-index: 2;
 }
 .samp {
    left: 0;
    z-index: 1;
 }
 .minecraft {
    top: 30px;
    right: 0;
    z-index: 1;
 }

You can safely remove .collection and add the styles to .content depending on the other content in .content , but then don't forget to change .collection div to .content div as well. 您可以安全地删除.collection并添加样式.content取决于其他内容.content ,但这时别忘了改变.collection div.content div为好。

Example: http://jsfiddle.net/3mAh3/4/ 示例: http//jsfiddle.net/3mAh3/4/

Or better: http://jsfiddle.net/3mAh3/5/ 或更好: http : //jsfiddle.net/3mAh3/5/

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

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