![](/img/trans.png)
[英]xhtml2pdf not applying css while creating pdf (html to pdf)
[英]CSS not applying to XHTML
我正在学习CSS / XHTML。 我有一个在外部定义的样式表,正在尝试在我的HTML文件中使用它。
.css文件的内容很简单:
borderstyle {
font-family:"Times New Roman", Times, serif;
font-size: 20%;
font-style:normal;
border: blue dotted medium;
display: inline;
}
这是我尝试在HTML中使用它的地方:
<body>
<link rel="stylesheet" type="text/css" href="myCSS.css" />
<center>
<div class ="borderStyle">
Welcome
</div>
</center>
</body>
欢迎文本显示为居中,但格式正常,没有边框。
更新:这是XHTML文件,我忘了提了。
borderstyle
是一个类,而不是元素,选择器应以句点开头,请使用:
.borderstyle {
/* CSS here */
}
此外,我建议将Times New Roman字体名称括在引号( 'Times New Roman'
)中,并且不建议使用center
,将CSS auto
用作左,右,边距或text-align: center;
在父元素上(已分配display: inline
。
其他答案都是有效的。 您应该更正他们提到的所有错误。
但是还没有提到另一个错误:类名"borderStyle"
。 如果以CSS为目标,则应使用相同的大小写。 IE .borderStyle
而不是.borderstyle
。
为完整性起见,其他错误的摘要:
borderstyle
中的borderstyle
需要一段时间 <link>
元素应该在头部 <center>
另外,我想说20%的字体很小。 在大多数浏览器上,这大约等于3像素。 您是说200%吗?
您错过了.
在CSS规则的选择器中,并且类别名称应拼写为borderStyle
而不是borderstyle
,以便与HTML中的类别名称匹配。 尝试以下方法:
.borderStyle {
font-family:"Times New Roman", Times, serif;
font-size: 20%;
font-style:normal;
border: blue dotted medium;
display: inline;
}
另外,您应该将CSS文件的链接移至网页的<head>
部分,例如
<html>
<head>
<link rel="stylesheet" type="text/css" href="myCSS.css" />
</head>
<body>
<!-- body content omitted for brevity -->
</body>
</html>
添加。 befor类并通过CSS将文本居中,并在头部区域添加样式链接
.borderstyle {
font-family:"Times New Roman, Times, serif";
font-size: 20%;
font-style:normal;
border: blue dotted medium;
display: inline;
text-align: center;
}
而这没有中心标记的HTML,仍然文本居中
<head>
<link rel="stylesheet" type="text/css" href="myCSS.css" />
<head>
<body>
<div class ="borderStyle">
Welcome
</div>
</body>
指向CSS文件的链接应放在标题部分,而不是正文中。
例如:
<html>
<head>
<title> title
</title>
<link rel="stylesheet" type="text/css" href="myCSS.css" />
</head>
<body>
</body>
</html>
上课
.borderstyle
身份证
#borderstyle
标签
div
类型,名称或任何其他属性
[type="type"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.