简体   繁体   English

根据宽高比更改图像的宽度

[英]Change the width of the images according to aspect ratio

I am building a comic reading website. 我正在建立一个漫画阅读网站。 I got a problem with displaying images. 我在显示图像方面遇到了问题。 Most of my images are having the aspect ratio of 2/3. 我的大多数图像都具有2/3的宽高比。 Means 1000x1500. 意味着1000x1500。 So I am displaying them with below css rules. 所以我用下面的css规则显示它们。 But there are some images like double page images. 但是有一些像双页图像的图像。 So when the css rule max-width=728px is applied this 4/3 raito image can't read anything. 因此,当应用css规则max-width=728px时,这个4/3 raito图像无法读取任何内容。 So basically I want to change the css rule for max-width=728px when the user came across to 4/3 ratio images. 所以基本上我想在用户遇到4/3比例图像时更改max-width=728px的css规则。 Css rule max_width=728px still have to apply the 2/3 ratio images but when the ratio changes to 4/3 it has to be max-width=1250px . Css规则max_width=728px仍然必须应用2/3比率图像,但当比率变为4/3时,它必须是max-width=1250px What do i need to do for solving this? 我需要做些什么来解决这个问题? It is related to css or need some javascript. 它与css或需要一些javascript有关。 This manga website has this future I think. 我认为这个漫画网站有这个未来。 Double page images are displaying width of ~1300 and when i shrink the browser its javascript updating the width and height. 双页图像显示宽度〜1300,当我收缩浏览器时,它的javascript更新宽度和高度。

Example: http://www.mangaeden.com/en/en-manga/berserk/344/17/ My website: http://mangabozok.com/oku/Berserk/346/5 示例: http//www.mangaeden.com/en/en-manga/berserk/344/17/我的网站: http//mangabozok.com/oku/Berserk/346/5

HTML: HTML:

<div class="gnc02">
<img src="paths">
</div>

CSS: CSS:

.gnc02 img {
     display:block;
     margin:auto;
     max-width: 728px;
     height: auto;
}
.gnc02 {
    max-width: 728px;
    display:block;
    margin:auto;
}

.gnc02 img {
    max-width: 100%;
    float:left;
}

You can try the following style: 您可以尝试以下样式:

.gnc02 img
{
    display: block;
    margin: auto;
    max-width: 1250px;
    max-height: 1092px;
}

For the 2:3 images, the max-height applies and restricts the width to 728 pixels. 对于2:3图像,应用max-height并将宽度限制为728像素。 For the 4:3 images, the max-width applies and restricts the width to 1250 pixels. 对于4:3图像, max-width适用并将宽度限制为1250像素。

 .gnc02 img { display: block; margin: auto; max-width: 1250px; max-height: 1092px; } 
 <div class="gnc02"> <img src="http://cdn.mangaeden.com/mangasimg/82/82018e71734a3893bc60f2e3a5df4520b1343c862ef09e3c7b30fd1d.jpg" /> </div> <br/> <div class="gnc02"> <img src="http://cdn.mangaeden.com/mangasimg/d6/d6afc1d18c0c08d6129f121a3531f47933d8fdbccca0ea7f78ed10e8.jpg" /> </div> 

Note: when running the code snippet, you should switch to "Full page" mode. 注意:运行代码段时,应切换到“整页”模式。

try this 试试这个

 .gnc02 { width: 99% !important; display:block; margin:auto; } .gnc02 img { max-width: 100%; } 
 <div class="gnc02"> <img src="http://cdn.mangaeden.com/mangasimg/82/82018e71734a3893bc60f2e3a5df4520b1343c862ef09e3c7b30fd1d.jpg" /> </div> 

this code is used for responsive designing. 此代码用于响应式设计。 I think this may help you in any type of image or the size of the image. 我认为这可以帮助您处理任何类型的图像或图像的大小。

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

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