4

I have a link in a div:

  <div class="parentStyle">Click me:<a>foo</a></div>

How do I make the link NOT have any of it's own style, so that it takes on the appearance of the parent div?

The issue is that the parent div has a blue background with white letters. Because it is a link, it is styled like a link with blue letters so I end up with blue on blue.

The parent style is added with Javascript. So the parent is sometime styled with white letters, and sometimes not.

I need the link to keep the same look as the parent.

This is how it looks when selected:

<div class="k-top k-top"><span class="k-in k-state-selected">
        <a class="au-target" au-target-id="222" href="#/entity-router/entityDetails/2">
            Item 1</a>
    </span></div>

This is how it looks when it is not selected:

<div class="k-bot"><span class="k-in">
        <a class="au-target" au-target-id="234" href="#/entity-router/entityDetails/8">Item 2</a>
    </span></div>
Greg Gum
  • 33,478
  • 39
  • 162
  • 233

4 Answers4

8

You can also use this to make the link no different from the parent element's text.

a {
  color: inherit;
  text-decoration: inherit;
  cursor: inherit;
}
<p>Some normal text and a <a href="https://stackoverflow.com/">link</a>.</p>

PS: You may need to use more styles depending on the CSS already used.

2

Use css

div#parent a{
    color: #fff;
    text-decoration: none;
    }
Abhay
  • 314
  • 1
  • 2
  • 11
0

You can do this by using CSS.

Try this.

<html>
  <style>
    #parent{
      background:blue;
      }
    #parent a{
      color:#fff;
      text-decoration:none;
      }
    </style>
  <body>
    <div id="parent">Click me:<a href="http://stackoverflow.com/questions/39291385/how-to-unstyle-a-link">foo</a></div>
   </body>
  </html>

Hope it will help.

Pirate
  • 2,886
  • 4
  • 24
  • 42
0

You can't unstyle an element, but you can apply a style only when a parent has a particular style like this:

parentStyle  a {
    color: #fff;
    background: blue;
    /*etc.*/
}

This style will apply only when it is a child of an element with a class of 'parentStyle'

Greg Gum
  • 33,478
  • 39
  • 162
  • 233
Bojan Petkovski
  • 6,835
  • 1
  • 25
  • 34