文字装饰在DIV中不起作用

时间:2012-02-27 18:08:16

标签: css html hyperlink text-decorations

我有以下CSS:

.top-category-item  {
        height: 338px;
        background-color: black;
        position: relative;
        }

.top-category-item-copy {
        width: 100%;
        /* Fallback for web browsers that doesn't support RGBa */
        background: rgb(0, 0, 0);
        /*  RGBa with 0.8 opacity */
        background: rgba(0, 0, 0, 0.8);
        bottom: 0px;
        position: absolute;
        padding-left: 5px;
        padding-right: 15px;
        padding-top: 2px;
        padding-bottom: 4px;
        box-sizing:border-box;
        -moz-box-sizing:border-box; /* Firefox */
        -webkit-box-sizing:border-box; /* Safari */
        font-family: Georgia, Times New Roman, serif;
        font-size: 35px;
        line-height: 36px;
        font-weight: bold;
        color: #F1F1F1;
        }

.top-category-item-copy a       {
                text-decoration: none;
                }

这是我的HTML:

    <a href="">
    <div class="top-category-item low-gutter">
    <img src="images/feature-placeholder.jpg" alt="latest-image-placeholder"/ width=100% height=100%>
    <div class="top-category-item-copy">Earlier French Quarter curfew for youths gets mixed reaction.</div>
    </div>
    </a>

我搜索了Stack Overflow以寻找解决此问题的方法:

  • 尝试将语法交换一点,例如.class-name a:link {text-decoration: none;}

  • 尝试声明全局a {text-decoration: none;},这有效,但感觉就像是一种解决方法,而不是真正的解决方案

3 个答案:

答案 0 :(得分:2)

在您的HTML中,top-category-item-copydiv,父亲为a。您的CSS说{34}中a内的所有.top-category-item-copy代码都没有文字装饰。&#34;

答案 1 :(得分:0)

当我希望链接的行为与文本不同时,我通常会做这个oldschool的动作

.top-category-item-copy:link { text-decoration: none; }

希望这会有所帮助

答案 2 :(得分:0)

为了那些可能仍然遇到此问题的人的利益,我遇到了同样的问题,其中a标签是我的自定义div标签的父级。我不希望我的网站中的整个锚标签被改变,所以我不得不使用父div类来修改我正在改变的锚标签块。当在html中查看时,这种安排看起来像这样:

    <div class="parent-div-class-for-this-block-containing-anchor-tags" "bla" "bla" "bla">

    <maybe-other-div-classes-and-ids>

    <a href="my-anchor-tag-which-i-want-to-alter" class="whatever">

    <div class="my-custom-div-class-which-refuses-to-alter-this-ahref-tag-above">

所以我在css中的解决方案是使用父div类,如下所示:

    .parent-div-class-for-this-block-containing-anchor-tags a {
            text decoration: none;
    }

而不是

    .my-custom-div-class-which-refuses-to-alter-this-ahref-tag-above a {
            text-decoration: none;
     }

这将改变此块中所有锚标记的文本修饰,而不是尝试使用由“whatever”类重写的单个锚标记的锚标记。希望这有助于某人。

相关问题