Style.css(原)

CSS样式代码示例
博客展示了一系列CSS样式代码,涵盖了链接、标题、段落、菜单、主体区域、页脚等元素的样式设置,包括颜色、字体大小、边距、边框等属性的定义,用于网页的样式设计。
body {
font-size : 0.9em;
font-family : Verdana, Geneva, Arial, Helvetica, sans-serif;
margin : 0px;
}

a:visited,
a:active,
a:link {
color : #00F;
text-decoration : none;
}

a:hover {
text-decoration : underline;
}

h1 {
margin : 0px;
font-size : 1.5em;
}

h1 a:visited,
h1 a:active,
h1 a:link {
color : #000;
}

h1 a:hover {
color : #47F;
text-decoration : none;
}

h2 {
margin-top : 10px;
font-size : 1em;
}

h5
{
margin: 0px;
padding: 0px;
}

#top {
padding : 10px;
background-color : #ADF;
color : #000;
border-bottom : 4px solid #47F;
}

#tagline {
font-size : 0.8em;
margin : 0px;
}

p.date img {
vertical-align : middle;
}

p.date {
font-size : 0.9em;
font-weight : bold;
border-bottom : 1px solid #AAA;
margin-bottom : 0px;
padding : 2px 0px;
}

blockquote {
font-style : italic;
}

p.postfoot {
font-size : 0.75em;
}

#leftmenu {
position : absolute;
left : 10px;
margin-top : 10px;
width : 180px;
}

#leftmenu h3,
#rightmenu h3 {
font-size : 0.9em;
margin : 0px;
padding : 4px;
border-bottom : none;
}

#leftmenu ul,
#rightmenu ul {
list-style : none;
margin : 0px;
padding : 0px;
margin-left : 5px;
margin-bottom : 10px;
font-size : 0.8em;
}

#rightmenu {
width : 180px;
position : absolute;
right : 0px;
margin-top : 10px;
}

#main {
margin : 0px 200px 0px 200px;
background-color : #EEE;
padding : 10px;
border-left : 1px solid #555;
border-right : 1px solid #555;
border-bottom : 4px solid #47F;
}

#footer {
margin : 0px;
padding-top : 5px;
text-align : center;
font-size : 0.7em;
}

input.text {
width : 300px;
}

textarea {
width : 300px;
height : 200px;
}

#comments h4 span {
color : #999;
}

#comments h4 {
margin : 0px;
font-size : 0.9em;
}

p {
margin : 10px 0px;
}

h3 {
font-size : 1.2em;
border-bottom : 1px solid #AAA;
}

#relatedlinks ul {
list-style : none;
margin-left : 10px;
padding : 0px;
}

span.highlight
{
background-color:Yellow;
}



这个问题是由于在 `.less` 文件中使用 `@import` 引入了 `.css` 文件,而 Angular 默认的 Less 编译器(通过 `less-loader`)会尝试解析导入的内容。由于 `.css` 文件不符合 Less 的语法规范,导致编译失败,出现如下错误: ``` Module parse failed: Unexpected character '@' (2:0) ``` --- ### ✅ 解决方案 #### ✅ 方法一:将 CSS 文件直接引入到 `angular.json` 中(推荐) 这是最稳定、最推荐的做法。Angular 提供了全局样式加载机制,可以将第三方 CSS 文件或本地 CSS 文件直接配置在 `angular.json` 中。 **修改 angular.json:** ```json "architect": { "build": { "options": { "styles": [ "src/index.less", "node_modules/@cloudscope/core/index.css", "node_modules/@cloud/tiny3/themes/theme-default.css", "src/assets/css/zTreeStyle/zTreeStyle.css" ] } } } ``` > **注意:** > - 如果你使用的是 `~package-name/path` 这样的路径,需要确保这些包已经安装,并且其 CSS 文件位于正确的路径下。 > - Angular 构建系统会自动处理这些文件,不需要再在 `.less` 文件中使用 `@import` 导入它们。 --- #### ✅ 方法二:在 `.less` 文件中使用 `@import (css)` 显式声明导入为 CSS 文件 Less 支持一种特殊的语法来告诉编译器不要解析某个导入的文件,而是将其当作CSS 处理。 ```less /* src/index.less */ @import (css) url("~@cloudscope/core/index.css"); @import (css) url("~@cloud/tiny3/themes/theme-default.css"); @import (css) url("./assets/css/zTreeStyle/zTreeStyle.css"); ``` > 使用 `@import (css)` 告诉 Less 不要尝试解析这个文件的内容,避免报错。 --- ### 📌 错误因详解 - Angular 在构建时使用 `less-loader` 来处理 `.less` 文件。 - 当你使用 `@import "~some/file.css"` 时,Less 会尝试读取并解析该文件内容。 - `.css` 文件中含有不被 Less 支持的语法(如 `@charset`, `url()` 等),从而导致解析失败。 - 使用 `@import (css)` 或者通过 `angular.json` 配置可以绕过这个问题。 --- ### 🧪 示例代码(完整 .less 文件) ```less /* index.less */ // 正确方式:使用 @import (css) 告知 less 不要解析这些文件 @import (css) url("~@cloudscope/core/index.css"); @import (css) url("~@cloud/tiny3/themes/theme-default.css"); @import (css) url("./assets/css/zTreeStyle/zTreeStyle.css"); // 自定义全局样式 body { font-family: sans-serif; } ``` --- ### ✅ 方法三:改为使用 `.css` 文件(如果不需要 LESS 功能) 如果你并不真正需要 `.less` 的变量、嵌套等特性,可以直接将 `index.less` 改为 `index.css`,然后使用CSS 的 `@import`: ```css /* styles.css */ @import url('~@cloudscope/core/index.css'); @import url('~@cloud/tiny3/themes/theme-default.css'); @import url('./assets/css/zTreeStyle/zTreeStyle.css'); ``` 并在 `angular.json` 中引用这个 `.css` 文件即可。 --- ### 🧠 总结 | 方法 | 描述 | 推荐程度 | |------|------|----------| | ✅ 方法一 | 将 CSS 文件配置在 `angular.json` 的 `styles` 数组中 | ⭐⭐⭐⭐⭐ | | ✅ 方法二 | 使用 `@import (css)` 强制 Less 不解析目标文件 | ⭐⭐⭐⭐ | | ❌ 方法三 | 修改 loader 配置或 eject Angular 构建配置 | ⚠️ 不推荐 | ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值