简体   繁体   English

响应式网页设计不适用于图片

[英]Responsive web design not working for pictures

I'm trying to create responsive design webpage. 我正在尝试创建响应式设计网页。 it works well with my table and text (when I resize my browser, it resize automatically. but this does not happen to my picture. 它适用于我的表格和文本(当我调整浏览器大小时,它会自动调整大小。但这不会发生在我的图片上。

CSS file: CSS文件:

@media screen and (max-width: 999px) {
 .page {
    width: 720px;
 }
 .header {
    width:720px;
 }
 img{
    width: 720px;
 }
}

@media screen and (max-width: 719px) {
 .page {
    width: 100%;
 }
 .header {
    width:100%;
 }
 img {
    width: 100%;
 }
}

@media screen and (max-width: 479px) {
 .page {
    width: 98%;
 }
 .header{
    width: 98%;
 }
}

.page {
  width: 960px;
  background-color: #fff;
  margin: 20px auto 0 auto; 
  border: 1px solid #496077;
}

img {
  float: left;
  width: 48%;
  margin: 0 1%;
}

My .aspx file: 我的.aspx文件:

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">

    <h2>
        Welcome to ASP.NET!
    </h2>
    <p>
        To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">www.asp.net</a>.
    </p>
    <p>
        You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&amp;clcid=0x409"
            title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.
    </p>
    <table border = "1">
<tr>
<td><center>'''Learning Outcome'''</center></td>
<td><center>'''Achievement Methods'''</center></td>
</tr>

<tr>
<td>Realistic problem solving and learning to learn skills</td>
<td>
my text here
</td> 
</tr>

<tr>
<td>Managing a real-time project from initiation to rollout </td>
<td>
my text here
</td>
</tr>

<tr>
<td>Understanding banking industry processes & practices</td>
<td>
my text here
</td>
</tr>

<tr>
<td>Team Cohesiveness</td>
<td>
*my text here
</td>
</tr>


</table>

<div>
    <img src="http://files.g4tv.com/images/blog/2008/06/18/633493967095957891.jpg" class="img" alt="DOMO">
    <img src="http://files.g4tv.com/images/blog/2008/06/18/633493967095957891.jpg" class="img" alt="image">
</div>

My text is responsive but my pictures are not, see the example at jsfiddle: jsFiddle 我的文字很敏感,但我的图片不是,请参阅jsfiddle的例子: jsFiddle

If you already have media-query stuff in place (and if you want full control over your image sizes) I would use those pixel widths you provided for images, If you are really doing more like a fluid-grid than column-based and you would like to scale your img all the time when resizing, I would try to use: 如果你已经有媒体查询的东西(如果你想完全控制你的图像大小),我会使用你为图像提供的那些像素宽度,如果你真的做的更像流体网格而不是基于列,你我想在调整大小时一直扩展你的img,我会尝试使用:

img{
    max-width: 100%;    
    _width: 100%;
}

As a side note: when you are dealing with responsive design page you should consider swapping larger images to smaller (or hiding them) when moving from desktop towards a mobile - this is because network latency, scaling big images to fit smaller devices screens takes more loading time to your page than using alternative eg mobile layout images instead. 作为旁注:当您处理响应式设计页面时,您应该考虑在从桌面移动到移动设备时将较大的图像交换为较小的(或隐藏它们) - 这是因为网络延迟,缩放大图像以适应较小的设备屏幕需要更多加载时间到您的页面比使用替代例如移动布局图像。

Edit: 编辑:

You are specifying img styles outside of your media queries, so you are always overriding your previous if they are even set in place - you should always specify default styles at start of the css file then followed by media-query rules (because they are screen-width specific), also it seems that your media-query widths are very ad-hoc I would use following base for a starters: (mobile first approach). 您在媒体查询之外指定img样式 ,因此如果它们甚至设置到位,您总是覆盖以前的样式 - 您应该始终在css文件的开头指定默认样式,然后是媒体查询规则(因为它们是屏幕) - 特定的宽度),似乎你的媒体查询宽度非常特别我会使用以下基础为首发:(移动第一种方法)。

/* MOBILE PORTRAIT */
@media only screen and (min-width: 320px) {
/* your styles */
}

/* MOBILE LANDSCAPE */
@media only screen and (min-width: 480px) {
/* your styles */
}

/* SMALL TABLET */
@media only screen and (min-width: 600px) {
/* your styles */
}

/* TABLET/NETBOOK */
@media only screen and (min-width: 768px) { 
/* your styles */
}

/* LANDSCAPE TABLET/NETBOOK/LAPTOP */
@media only screen and (min-width: 1024px) { 
/* your styles */
}

/* DESKTOP */
@media only screen and (min-width: 1280px) { 
/* your styles */
}

/* WIDESCREEN */
/* Increased body size for legibility */
@media only screen and (min-width: 1400px) { 
 /* your styles */
}

If you had problems with your current file consider also fixing your html headers and providing more accurate info next time :).. designing responsive grid is not easy and there are multiple resources in network to get started when trying to do so. 如果您当前的文件有问题,请考虑修复您的html标题并在下次提供更准确的信息:) .. 设计响应式网格并不容易,并且在尝试这样做时,网络中有多个资源可供使用。 For example: http://fluidbaselinegrid.com/ and http://twitter.github.com/bootstrap/ inspect their code through and learn.. what comes to me, I'm not trying to invent wheel again, I just select ready made responsive design grids/frameworks as a base based on project I am currently working with. 例如: http//fluidbaselinegrid.com/http://twitter.github.com/bootstrap/检查他们的代码并学习..什么来找我,我不是想再发明轮子,我只是选择根据我目前正在合作的项目,将现成的响应式设计网格/框架作为基础。 Good luck, and sorry for the overkill answer! 祝你好运,对不起来的答案太过分了!

Make sure you set the fixed width to your images first. 确保首先为图像设置固定宽度。

<img src="image.png" width="100px"/>

and set the max-width to 100%. 并将最大宽度设置为100%。

img {max-width: 100%;}​

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

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