wordpress 如何将wordpress图像调整为固定高度和自动宽度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18088247/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to resize wordpress image to fixed height and auto width
提问by Rokas
I have a WP slider with costum img sizes (fixed width and height) and i need that they would scale to fixed 330px height, and auto width. how to achieve this?
我有一个带有 costum img 大小(固定宽度和高度)的 WP 滑块,我需要它们可以缩放到固定的 330px 高度和自动宽度。如何实现这一目标?
thank you in advance!
先感谢您!
回答by Rokas
As this was specific wordpress question and I found an answed, i will share it. When you add custom image size to functions.php, add 9999 to width and hardCrop to false.
由于这是特定的 wordpress 问题,我找到了一个答案,我将分享它。在向functions.php 添加自定义图像大小时,将9999 添加到width 并将hardCrop 添加到false。
add_image_size('slider-thumb-alt', 9999, YOUR_FIXED_HEIGT, false);
回答by Ben Racicot
First when importing them via the media manager you can define the native size. Otherwise you will have to hard code them like @Dan Grossman mentioned. We need more info. Site link and slider name?
首先,当通过媒体管理器导入它们时,您可以定义本机大小。否则你将不得不像@Dan Grossman 提到的那样对它们进行硬编码。我们需要更多信息。站点链接和滑块名称?
回答by Dan Grossman
<img src="http://www.example.com/image.jpg" height="330" />
回答by Ian
It sounds like you already have a pretty decent idea of what you need. Use css to do this.
听起来您已经很清楚自己需要什么。使用 css 来做到这一点。
For example:
例如:
<img src="http://www.example.com/image.jpg" class="image_class"/>
<style>
.image_class{
width: auto;
height:330px;
</style>
You'll want to target based on class (rather than all images with img{...}
). I haven't used WP Slider, but I'm assuming that it will add a custom class to images in the slider. If so just use your in-browser developer tools, or view source, to see what class is being added to these images, then create the css like the above.
您将希望基于类(而不是所有带有 的图像img{...}
)进行定位。我没有使用过 WP Slider,但我假设它会为滑块中的图像添加一个自定义类。如果是这样,只需使用您的浏览器内开发工具或查看源代码,查看添加到这些图像的类,然后像上面一样创建 css。