D
D
Dmitry Kim2015-09-22 14:39:59
css
Dmitry Kim, 2015-09-22 14:39:59

Document fragmentation with fixed top navigation. How?

Essence of the question: there is a page with text and a menu with links to paragraphs of this text. Example here: jsfiddle.net/zLeau0qz
The problem is that there is a fixed navigation menu at the top of the page. When you click on the links to the paragraphs of the text, the headings of these paragraphs are closed by the navigation menu. Is there a simple css + html solution?
UPD: Maybe somehow you can screw something like this, but more beautifully?

h2:target {
    padding-top: 40px;
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly Inchin ☢, 2015-09-22
@kimono

I doubt very much that it will turn out more beautiful ... at least margin , at least padding .
But I will offer you something else:

  • Make the menu bar barely visible through opacity (on hover - opaque).
  • Place dimensionless elements after each subtext (on the last line) and make anchors on them.
  • Use JavaScript:
    document.querySelector("aside").onclick = function(e){
      var tr = e.target.href;
      if(tr){
          e.preventDefault();
          window.scrollTo(
            0, 
            window.pageYOffset + document.querySelector("#"+tr.split("#")[1]).getBoundingClientRect().top - 60
           );
       }
    }

    Like this: jsfiddle.net/zLeau0qz/2

S
sashabeep, 2015-09-22
@sashabeep

Add padding to list items and give them an ID

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question