我有一个 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/