php - Styles.php 有条件的 PHP/CSS 在 IE 9 中不工作

标签 php html css wordpress background-image

我有一个使用此代码调用的 style.php 设置:

<?php include (TEMPLATEPATH . '/includes/css/styles.php');?>

此样式表包含此代码:

<?php $thumb_id = get_post_thumbnail_id();
$thumb_url_array = wp_get_attachment_image_src($thumb_id, 'title-image', true);
$thumb_url = $thumb_url_array[0]; ?>

<style>

/* GET FEATURED IMAGE FOR TITLE BACKGROUND */
.titlearea {
<?php if(has_post_thumbnail()): ?>
background: linear-gradient(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.6)), url('<?php echo $thumb_url ?>');
<?php else: ?>
background: url('http://www.example.com/wp-content/themes/my-custom-theme/includes/images/services-top.jpg');
<?php endif; ?>
background-size: cover;
background-position: 50% 0;
}
</style>

它应该寻找帖子缩略图(我使用 Wordpress)并将其显示为背景图片(如果有的话),如果页面没有缩略图则它应该回退到默认值(services-top.jpg)。

此代码在 Chome 和 Firefox 中运行良好,但 IE9 仅显示白色背景,甚至没有注册后备默认图像。

有人知道为什么这不起作用吗?

谢谢

最佳答案

PHP 在服务器上运行。你的问题是 IE9 不支持 linear-gradient。引用 this answer :

The best cross-browser solution is

background: #fff;
background: -moz-linear-gradient(#fff, #000);
background: -webkit-linear-gradient(#fff, #000);
background: -o-linear-gradient(#fff, #000);
background: -ms-linear-gradient(#fff, #000);/*For IE10*/
background: linear-gradient(#fff, #000);
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#ffffff', endColorstr='#000000');/*For IE7-8-9*/ 
height: 1%;/*For IE7*/

关于php - Styles.php 有条件的 PHP/CSS 在 IE 9 中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24207077/

相关文章:

php - 重新排列数据库表项目顺序的最佳方法?

html - 将无序列表中的图像与列表项对齐

c# - ASP.net session 登录

html - 是否可以使用 CSS 显示没有背景的图像?

firefox - css3 border-image firefox 15.0.1(第二轮)

css - 如何将此按钮旋转 180°?

php - ORM Doctrine ManyToOne 更新 CASCADE (Symfony)

php - 您的 PHP 工具集中有什么?

javascript - 将 php true 或 false 值分配给 JS var

html - IE9 渲染问题 - 空白条(水平线)