WordPress 主题(或任何主题,实际上)的最大图像宽度

发布于 2024-09-18 23:04:00 字数 1054 浏览 4 评论 0 原文

在Word Press中,如果您上传图像并让它以100%显示:如果它超出其容器宽度,则主题将:

a)被破坏,弄乱页面布局

b)隐藏它的额外宽度无法显示

当然,这是针对非流体布局的。

这里提出的解决方案:

http://lorelle.wordpress.com/2006/10/07/the-battle- Between-image-width-and-column-width/

p img {
    padding: 0;
    max-width: 100%;
}
#header, #content, #footer, .widget {
    overflow: hidden;
}

这是做什么的,显然只是确保图像显示在嵌套对象宽度的 100%

并且 overflow:hidden 是为了让多余的位消失?

好吧,这不是我要找的。

我正在寻找一种方法(最好在CSS中)来做到这一点:

如果图像太大,使其成为可用宽度的100%;

如果图像不太大,则使其成为可用宽度

我一直在设置 来解决这个问题,但这会带来流体布局中的问题,例如放大的可能性图像。

编辑:嗯,显然, max-width 样式应该可以达到预期目的。但在 WordPress 的 Mystique 主题 用户 css 中它不起作用,我无法弄清楚为什么。主题本身就最大宽度采取的措施之间可能存在冲突。 y.estamine.net/main/wp-content/themes/mystique/style.css <- 我想在这里的某个地方。

In word press, if you upload an image, and let it display in 100%: if it exceeds its containers width, the theme will either:

a) be broken, messing up the layout of the page

or

b) hide the extra width it cant display

This is for a non-fluid layout, of course.

The solution presented here:

http://lorelle.wordpress.com/2006/10/07/the-battle-between-image-width-and-column-width/

p img {
    padding: 0;
    max-width: 100%;
}
#header, #content, #footer, .widget {
    overflow: hidden;
}

what this does, apparently is just making sure the image is displayed under 100% of the width of the objected where it's nested in

And the overflow: hidden is to make the extra bit disappear?

Well, this is not what i am looking for.

I am looking for a way (in css, preferably) to do this:

If image is too big, make it 100% of available width;

If image is not too big, make it its original size.

I've been setting <img width="100%" to solve this problem, but this will bring up problems in a fluid layout, such as the possibility of enlarged images.

edit: Well, apparently, the max-width style should work for the intended purpose. But in the Mystique theme user css of wordpress it's not working, and i cant' figure out why. Probably a conflict between measures taken by the theme itself regardig max-width. y.estamine.net/main/wp-content/themes/mystique/style.css <- somewhere here, i think.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

墨落成白 2024-09-25 23:04:01

最大内容宽度应在functions.php 中设置。下面的例子来自 Twentyten。这将防止大尺寸图像溢出。

 * Set the content width based on the theme's design and stylesheet.
 *
 * Used to set the width of images and content. Should be equal to the width the theme
 * is designed for, generally via the style.css stylesheet.
 */
if ( ! isset( $content_width ) )
    $content_width = 640;

The maximum content width should be set in functions.php. The example below is from Twentyten. This will prevent your large sized images from overflowing.

 * Set the content width based on the theme's design and stylesheet.
 *
 * Used to set the width of images and content. Should be equal to the width the theme
 * is designed for, generally via the style.css stylesheet.
 */
if ( ! isset( $content_width ) )
    $content_width = 640;
暖风昔人 2024-09-25 23:04:01

将 max-width 设置为最大值对我有用。例如

div {
    width: 500px;
    height: 500px;
    border: 2px solid black;
}
img {
    max-width: 500px;
    max-height: 500px;
}

Fiddle http://jsfiddle.net/t29yV/

将其设置为百分比也有效...所以你可能会发生其他事情。

在 IE7/Chrome/Firefox 中测试

Setting the max-width to a maximum value works for me. For example

div {
    width: 500px;
    height: 500px;
    border: 2px solid black;
}
img {
    max-width: 500px;
    max-height: 500px;
}

Fiddle http://jsfiddle.net/t29yV/

Setting it to a percentage works too... so you may have something else happening.

Tested in IE7/Chrome/Firefox

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文