Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - show / hide content with anchor name

Tags:

css

anchor

hide

Single page website

I have a single page website (one page only). I can navigate with a menu to get to different parts of the page with anchor name, just like (see sidebar):

WordPress Docs

Hide the other stuff

I want to hide stuff that does not belong the the current active page part and just show the information of the part that I'm looking at.

Question(s)

  • Can I hide stuff that is not a part of the current #anchor_part with only CSS?
  • Have you seen any sites already doing this?
like image 386
Jens Törnell Avatar asked Sep 17 '13 12:09

Jens Törnell


People also ask

How do I show hidden content in CSS?

You can hide an element in CSS using the CSS properties display: none or visibility: hidden . display: none removes the entire element from the page and mat affect the layout of the page. visibility: hidden hides the element while keeping the space the same.

How do you hide the anchor element?

To disable a HTML anchor element with CSS, we can apply the pointer-events: none style. pointer-events: none will disable all click events on the anchor element. This is a great option when you only have access to class or style attributes. It can even be used to disable all the HTML links on a page.

How do you hide text links 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.

Can anchor tag have name?

<a href="#"><a name=""> The A element defines an anchor. You can create a link to a named anchor by using the name attribute (or the id attribute). When linking within the same document, the A element is set as follows. Anchor names must be unique within a document.


2 Answers

Working Example

Try this Html

<a href="#a">a</a>
<a href="#b">b</a>
<a href="#c">c</a>

<div id="a" class="page"> this is a id</div>
<div id="b" class="page"> this is b id</div>
<div id="c" class="page"> this is c id</div>

and Css

#a, #b, #c{
    display:none;
}
#a:target{
    display:block;
}
#b:target{
    display:block;
}
#c:target{
    display:block;
}
like image 188
Love Trivedi Avatar answered Oct 22 '22 17:10

Love Trivedi


yes you can do this with only css,first creat < div > with a specific width and height and overflow to hidden,then place your stuff in this div beside eachother

<a href="#firstWindow">firstWindow</a>
<a href="#secondWindow">secondWindow</a>
<a href="#thirdWindow">thirdWindow</a>
<div class="window">
    <div id="firstWindow" class="window">
         firstWindow
    </div>
    <div id="secondWindow" class="window">
         secondWindow
    </div>
    <div id="thirdWindow" class="window">
         thirdWindow
    </div>
</div>

.window{
   width:300px;
   height:300px;
   overflow:hidden;
 }

something like above; note that you can use this html/css if you have a constant height,the height of your stuff should be the same.

like image 21
Shirin Abdolahi Avatar answered Oct 22 '22 15:10

Shirin Abdolahi