【问题标题】:Why are some of my html tags following css and others not? [closed]为什么我的一些 html 标签跟随 css 而其他的却没有? [关闭]
【发布时间】:2011-12-25 08:59:54
【问题描述】:

所以我有一个普通的 html 文件,带有诸如等标签。

我有这个 css 文件:

html, body {
    margin:0; 
    padding:0;
    backgound-color:blue; 
}

a {
    /* Note: For whatever reason this does not apply to templates/tags/naviagtion.html */
    text-decoration: none;
}

无论出于何种原因,当它通过以下方式应用于我的 html 文件时:

<link rel="stylesheet" type="text/css" href="/static/css/base.css" /> 

注意:放在base.html中,它是基本模板。正文的背景和链接的文本装饰不会更改为 css 样式。其他标签如 div 将其宽度、浮动等更改为 base.css 文件的样式。当我通过标签中的 style="" 亲自编辑标签时,将应用属性。为什么样式是使用 style="" 而不是从 css 文件中应用的。我在 base.html 文件中没有覆盖任何内容的内联 css。此外,html 的边距和填充、css 文件中的 body 等属性会被应用,而 background-color 则不会。怎么回事?

谢谢!

base.html 文件看起来很像这样

....
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/base.css" />
</head>
<body>
    <!-- 
    <div class="left_holder" >
    </div>
    -->
    <div class="center_holder" >
        <div id="top_1" >
            <div id="search" class="top_left" >
                <!-- [ searchbar ] -->
                {% include "tags/search.html" %}
            </div>
....

navigation.html 文件:

<div><a href="/" >Home</a></div>

抱歉,没有网址,因为这是在本地主机上

【问题讨论】:

    标签: python html css django


    【解决方案1】:

    拼写错误已修复。 css 也区分大小写。

    html, body {
        margin:0; 
        padding:0;
        background-color:blue; 
    }
    
    a{
        /* Note: For whatever reason this does not apply to templates/tags/naviagtion.html */
        text-decoration: none;
    }
    

    你说 text-decoration:none 没有得到应用。 您的意思是在链接下方看到了下划线,还是在点击后看到了轮廓?

    如果您有 text-decoration:none; 则不应看到下划线;在你的 CSS 中。

    如果您看到边框或 ouline,请尝试添加 outline:none;以及 {}

    的 css

    【讨论】:

    • LOL WOW 简直不敢相信这是一个拼写错误......感觉我只是在浪费你的时间......对不起,我现在更频繁地阅读我的工作...... .
    • @Derek 一个“智能”编辑器会显示明显无效的 CSS,如上所示。或者,使用CSS validator
    【解决方案2】:

    尝试使用 HTTP 调试器来确保您的 .css 文件正在加载。我怀疑不是。对于 Windows,请使用 Fiddler。如果 .css 没有被加载,你会在列表中看到一个红色的 404。

    还可以尝试使用浏览器的调试工具来确保 .css 文件已加载。 例如,在 Chrome 或 Safari 中,只需右键单击页面并选择“检查元素”。单击顶部的“资源”选项卡,确保您的 .css 文件列在左侧面板中。如果不是,您的文件路径可能不正确。

    【讨论】:

    【解决方案3】:

    templates/tags/naviagtion.html 是包含在 base.html 中还是单独的文件?

    包含示例 HTML 代码非常重要,因为这也是问题的一部分。或者,如果您有一个我们可以看到问题的 URL,也会有所帮助。

    【讨论】:

    • navigation.html 包含在 base.html 中,现在在上面发布示例,抱歉这是在本地主机上,没有 url,谢谢!
    【解决方案4】:

    不确定background-color,但请尝试获取链接:

    a:link {
      text-decoration: none;
    }
    

    选择器a 通常过于笼统,无法用a:link 选择器覆盖浏览器设置的链接样式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-16
      • 2023-01-18
      • 1970-01-01
      相关资源
      最近更新 更多