jquery - IE8 不会使用 JQuery 和 html5shiv 设置Figcaption 元素的样式

标签 jquery css html internet-explorer-8

我有一个 JQuery 脚本,可以操作 DOM 来创建 <figure><figcaption> 。不幸的是我似乎无法设计 <figcaption> 的样式在 IE8 中使用 CSS。相同的代码适用于 Chrome 和 Firefox。知道为什么 IE8 不设置元素样式吗?

我在 IE8 中使用 HTML5Shiv 脚本,因此它应该能够识别新的 HTML5 元素并允许我设置它们的样式。这是代码,感谢您查看:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<!--[if lt IE 9]> 
    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> 
<![endif]-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js"></script>     
<title>Untitled</title>
<style>
    body {
               width: 600px;
               margin-left: auto;
               margin-right: auto;
    }
    figure {
              float: left;
    }
    figcaption {
              display: block; 
              text-align: center;
              font-size: 0.5em; 
              font-style: italic;
              font-weight: bold;
              padding: 5px 0;
   }
</style>
</head>

<body>

<img src="http://placehold.it/350x150" alt="This should be bold, italic, centered and small" />

<p>This is a regular paragraph.</p>

<script>
$(document).ready(function() {
$('img').wrap('<figure></figure>');
$('img').after('<figcaption>This should be bold, italic, centered and small</figcaption>');
});
</script>

</body>
</html>

最佳答案

您需要HTML5 innerShiv设置动态 HTML5 元素的样式。

关于jquery - IE8 不会使用 JQuery 和 html5shiv 设置Figcaption 元素的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5480379/

相关文章:

javascript - jQuery 获取点击类名

javascript - 如何动态地从多个复选框(jquery)获取值并将其复制到文本区域?

html - 我试图在 css 中悬停时更改我的 Logo

html - 如何将内联菜单列表移动到右侧的 Burger Bar(菜单栏)旁边

html - 使用 CSS 背景阴影/图像打印 HTML 页面

javascript - JQuery/AJAX Toggle 将 POST 切换到 php 文件,无需导航

jquery - 使用单选按钮和 jquery 更改图像

php - HTML5 - 视频标签播放视频但不播放音频

javascript - CSS 问题 : Chrome adds 3px extra margin-right to text field

html - 将 TEXTAREA 和 INPUT 字段设置为 TD 内的 100% 宽度会截断右边距