链接到外部的css文件 [英] Linking to an external css file

查看:110
本文介绍了链接到外部的css文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图将我在本地计算机上创建的css文件链接到我的html代码,但它似乎不起作用。我们应该在哪里保留我们想要在我们的html代码中链接的css文件,或者我们应该如何链接到该文件?作为一个例子,我发布了这个html代码:

i have been trying to link a css file i created in my local computer to my html code but it doesn't seem to work. Where should we keep the css file we want to link in our html code or how should we link to that file? As an example i am posting this html code:

<!DOCTYPE html>
<html lang="en-GB">
<head>
  <meta charset="utf-8">
  <title>Breeding Dogs—Tips about Alsatians</title>
  <meta name="description" content="How to breed Alsatians, tips on proper breeding and information about common issues with this breed.">
  <meta name="keywords" content="Dogs,Alsatian,Breeding,Dog,Tips,Free,Pet">
  <link rel="stylesheet" type="text/css" media="screen" href="styles.css">
  <link rel="stylesheet" type="text/css" media="print" href="printstyles.css">
  <script src="leaving.js"></script>
</head>
<body>
Test!
<a href="http://dailypuppy.com" onclick="return leave()">The Daily Puppy</a>
</body>
</html>

从这个例子中,如果我想重新创建这个应该保留我的styles.css文件等等。我有点困惑,并可以真正使用一点帮助,谢谢。

from this example, if i wanna re-create this where should i be keeping my styles.css file and etc. I am a little confused and could realy use a bit help , thank you.

推荐答案

这取决于您的文件结构。通常,如果您将.html文件保存在根目录中,则会将样式文件(.css)保存在标有 css 的目录中,以便您的结构可以像

It's dependent on your file structure. Conventionally, if you keep .html files in the root directory, you'd keep style files (.css) in a directory labeled css so your structure would like

/-
 - /img
 - /css
 | --- style.css
 | --- printstyle.css
 - index.html

这意味着您的标记行会读取

which means your tag line would read

<link rel="stylesheet" type="text/css" media="screen" href="./css/styles.css">
<link rel="stylesheet" type="text/css" media="screen" href="./css/printstyles.css">

请注意目录名称前面的./。这是一个相对的位置,如果你正在本地读取.html文件(使用file:///,而不是像我想象的那样通过本地服务器提供),则需要它。

Please note the "./" preceding the directory name. This means it's a relative location and is needed if you're reading your .html files locally (using file:/// instead of serving them via a local server as I imagine you are).

这篇关于链接到外部的css文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆