Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding a link on click css only

Tags:

html

css

i'm pretty new to coding (just started a free weeks ago with html and css). For a news page i tried to implement "read on" links, similiar to this question here: on click hide this (button link) pure css

However i can't seem to make the link disappear after clicking it. I got this for my code so far (opening and closing works just fine):

.readmore {
  display: none;
}

article[id*="n"]:target .readmore {
  display: block;
}

article:target .used {
  display: none;
}
<article>Text visible after you open the site.


  <a href="#n2" class="used">Link that opens more text and should diappear after clicking</a>

  <article id="n2">
    <div class="readmore">more text
     <a href="#back">Closing button</a>
    </div>
  </article>
</article>

I feel like i messed something up big time, but i really can't figure it out.

like image 505
Mjyrn Avatar asked Nov 15 '17 14:11

Mjyrn


People also ask

How do I hide a link in CSS?

Use CSS styling to make your links invisible The first way is by using none as the pointer-events CSS property value. The other is by simply coloring the text to match the background of the page. Neither method hides the link if someone inspects the HTML source code.

How do you hide a click element in CSS?

The css input:checked+div selects the div immediately next to/after the input. The label for said checkbox (or hey leave out the label and just have the checkbox) display:none hides stuff.

How do I hide a link in a tag?

By changing the display feature to "none", you will remove the link from the page layout. This may cause other elements of your page to move if they define their position in reference to your link. Changing your visibility to "hidden" will hide the link without influencing the page layout.


2 Answers

Just put your link inside the article tag including your id.

.readmore {
  display: none;
}

article[id*="n"]:target .readmore {
  display: block;
}

article[id*="n"]:target .used {
  display: none;
}
<article>Text visible after you open the site.

  <article id="n2">
    <a href="#n2" class="used">Link that opens more text and should diappear after clicking</a>
    <div class="readmore">more text
      <a href="#back">Closing button</a>
    </div>
  </article>
</article>
like image 148
bhansa Avatar answered Oct 05 '22 09:10

bhansa


Using this you can achieve what you want.....you have added id inner article which you have to give parent artical and change css

.readmore {
  display: none;
}

#n2:target .readmore {
  display: block;
}

#n2:target .used {
  display: none;
}

.readmore {
  display: none;
}

#n2:target .readmore {
  display: block;
}

#n2:target .used {
  display: none;
}
<article id="n2">Text visible after you open the site.


  <a href="#n2" class="used">Link that opens more text and should diappear after clicking</a>

  <article>
    <div class="readmore">more text
     <a href="#back">Closing button</a>
    </div>
  </article>
</article>
like image 38
Hiren Vaghasiya Avatar answered Oct 05 '22 10:10

Hiren Vaghasiya