Home > Blockchain >  Setting nav bar to scroll with a media query. css html
Setting nav bar to scroll with a media query. css html

Time:03-12

Hi guys when my page is full screen the main content scrolls and nav is fixed.

What I would like to do is set the nav to a smaller heigher (e.g. 250px) and have the nav links scroll to take up less space.

I can't see all of the nav when it is set to scroll.

Code below! I have used a CSS style reset not shown.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="styles.css">
    <title>Javascript page</title>
</head>
<body>
<div id="wrapper">
    <header>
    <nav>
<h1>JS DOCUMENTATION</h1>
<ul >
    <li ><a  href="#intro">Introduction</a></li>
    <li ><a href="#what2">What you should already know</a></li>
    <li ><a href="#java3">Javascript and Java</a></li>
    <li ><a href="#hello4">Hello world</a></li>
    <li ><a href="#var5">Variables</a></li>
    <li ><a href="#decl6">Declaring Variables</a></li>
    <li ><a href="#var6">Variable Scope</a></li>
    <li ><a href="#glob7">Global variables</a></li>
    <li ><a href="#const8">Constants</a></li>
    <li ><a href="data9">Data types</a></li>
</ul>
    </nav>
    </header>

    <main>
        <section  id="intro1">
            <h2 >Introduction</h2>

            <p >
                JavaScript is a cross-platform, object-oriented scripting language. It is a small and lightweight language. Inside a
                host environment (for example, a web browser), JavaScript can be connected to the objects of its environment to provide
                programmatic control over them.
            </p>
            <p >
                JavaScript contains a standard library of objects, such as Array, Date, and Math, and a core set of language elements
                such as operators, control structures, and statements. Core JavaScript can be extended for a variety of purposes by
                supplementing it with additional objects; for example:
            </p>

            <ul >
                <li >Client-side JavaScript extends the core language by supplying objects to control a browser and its Document Object Model
                (DOM). For example, client-side extensions allow an application to place elements on an HTML form and respond to user
                events such as mouse clicks, form input, and page navigation.</li>
                <li >Server-side JavaScript extends the core language by supplying objects relevant to running JavaScript on a server. For example, server-side extensions allow an application to communicate with a database, provide continuity of information
                from one invocation to another of the application, or perform file manipulations on a server.</li>
            </ul>
        </section>

        <section  id="what2">
            <h2 >What you should already know</h2>

            <p >
                This guide assumes you have the following basic background:
            </p>

            <ul >
                <li >A general understanding of the Internet and the World Wide Web (WWW).</li>
                <li >Good working knowledge of HyperText Markup Language (HTML).</li>
                <li >Some programming experience. If you are new to programming, try one of the tutorials linked on the main page about JavaScript.</li>
                </ul>

        </section>

        <section  id="java3">
            <h2 >Javascript and Java</h2>
            <p >
            JavaScript and Java are similar in some ways but fundamentally different in some others. The JavaScript language resembles Java but does not have Java's static typing and strong type checking. JavaScript follows most Java expression
            syntax, naming conventions and basic control-flow constructs which was the reason why it was renamed from LiveScript to
            JavaScript.</p>

            <p >
                In contrast to Java's compile-time system of classes built by declarations, JavaScript supports a runtime system based
                on a small number of data types representing numeric, Boolean, and string values. JavaScript has a prototype-based
                object model instead of the more common class-based object model. The prototype-based model provides dynamic
                inheritance; that is, what is inherited can vary for individual objects. JavaScript also supports functions without any
                special declarative requirements. Functions can be properties of objects, executing as loosely typed methods.
            </p>




        </section>

        <section  id="hello4">
                <h2 >Hello World</h2>
                <p >
                    To get started with writing JavaScript, open the Scratchpad and write your first "Hello world" JavaScript code:
                </p>
                <code>
                    function greetMe(yourName) { alert("Hello "   yourName); }
                    greetMe("World");
                </code>

                <p >
                    Select the code in the pad and hit Ctrl R to watch it unfold in your browser!
                </p>

        </section>

        <section  id="var5">
            <h2 >Variables</h2>
            <p >
                You use variables as symbolic names for values in your application. The names of variables, called identifiers, conform
                to certain rules.
                
                A JavaScript identifier must start with a letter, underscore (_), or dollar sign ($); subsequent characters can also be
                digits (0-9). Because JavaScript is case sensitive, letters include the characters "A" through "Z" (uppercase) and the
                characters "a" through "z" (lowercase).
                
                You can use ISO 8859-1 or Unicode letters such as å and ü in identifiers. You can also use the Unicode escape sequences
                as characters in identifiers. Some examples of legal names are Number_hits, temp99, and _name.
            </p>

        </section>

        <section  id="decl6">
            <h2 >Declaring variables</h2>
                        <p >
                            JavaScript and Java are similar in some ways but fundamentally different in some others. The JavaScript language
                            resembles Java but does not have Java's static typing and strong type checking. JavaScript follows most Java
                            expression
                            syntax, naming conventions and basic control-flow constructs which was the reason why it was renamed from LiveScript
                            to
                            JavaScript.</p>
                        
                        <p >
                            In contrast to Java's compile-time system of classes built by declarations, JavaScript supports a runtime system
                            based
                            on a small number of data types representing numeric, Boolean, and string values. JavaScript has a prototype-based
                            object model instead of the more common class-based object model. The prototype-based model provides dynamic
                            inheritance; that is, what is inherited can vary for individual objects. JavaScript also supports functions without
                            any
                            special declarative requirements. Functions can be properties of objects, executing as loosely typed methods.
                        </p>
        </section>

        <section  id="var6">
            <h2 >Variable-scope</h2>
                        <p >
                            JavaScript and Java are similar in some ways but fundamentally different in some others. The JavaScript language
                            resembles Java but does not have Java's static typing and strong type checking. JavaScript follows most Java
                            expression
                            syntax, naming conventions and basic control-flow constructs which was the reason why it was renamed from LiveScript
                            to
                            JavaScript.</p>
                        
                        <p >
                            In contrast to Java's compile-time system of classes built by declarations, JavaScript supports a runtime system
                            based
                            on a small number of data types representing numeric, Boolean, and string values. JavaScript has a prototype-based
                            object model instead of the more common class-based object model. The prototype-based model provides dynamic
                            inheritance; that is, what is inherited can vary for individual objects. JavaScript also supports functions without
                            any
                            special declarative requirements. Functions can be properties of objects, executing as loosely typed methods.
                        </p>
        </section>

        <section  id="glob7">
            <h2 >Global Variables</h2>
                        <p >
                            JavaScript and Java are similar in some ways but fundamentally different in some others. The JavaScript language
                            resembles Java but does not have Java's static typing and strong type checking. JavaScript follows most Java
                            expression
                            syntax, naming conventions and basic control-flow constructs which was the reason why it was renamed from LiveScript
                            to
                            JavaScript.</p>
                        
                        <p >
                            In contrast to Java's compile-time system of classes built by declarations, JavaScript supports a runtime system
                            based
                            on a small number of data types representing numeric, Boolean, and string values. JavaScript has a prototype-based
                            object model instead of the more common class-based object model. The prototype-based model provides dynamic
                            inheritance; that is, what is inherited can vary for individual objects. JavaScript also supports functions without
                            any
                            special declarative requirements. Functions can be properties of objects, executing as loosely typed methods.
                        </p>
        </section>

        <section  id="const8">
            <h2 >Constants</h2>
                        <p >
                            JavaScript and Java are similar in some ways but fundamentally different in some others. The JavaScript language
                            resembles Java but does not have Java's static typing and strong type checking. JavaScript follows most Java
                            expression
                            syntax, naming conventions and basic control-flow constructs which was the reason why it was renamed from LiveScript
                            to
                            JavaScript.</p>
                        
                        <p >
                            In contrast to Java's compile-time system of classes built by declarations, JavaScript supports a runtime system
                            based
                            on a small number of data types representing numeric, Boolean, and string values. JavaScript has a prototype-based
                            object model instead of the more common class-based object model. The prototype-based model provides dynamic
                            inheritance; that is, what is inherited can vary for individual objects. JavaScript also supports functions without
                            any
                            special declarative requirements. Functions can be properties of objects, executing as loosely typed methods.
                        </p>
        </section>

        <section  id="data9">
            <h2 >Data types</h2>
                        <p >
                            JavaScript and Java are similar in some ways but fundamentally different in some others. The JavaScript language
                            resembles Java but does not have Java's static typing and strong type checking. JavaScript follows most Java
                            expression
                            syntax, naming conventions and basic control-flow constructs which was the reason why it was renamed from LiveScript
                            to
                            JavaScript.</p>
                        
                        <p >
                            In contrast to Java's compile-time system of classes built by declarations, JavaScript supports a runtime system
                            based
                            on a small number of data types representing numeric, Boolean, and string values. JavaScript has a prototype-based
                            object model instead of the more common class-based object model. The prototype-based model provides dynamic
                            inheritance; that is, what is inherited can vary for individual objects. JavaScript also supports functions without
                            any
                            special declarative requirements. Functions can be properties of objects, executing as loosely typed methods.
                        </p>
        </section>
    </main>
    </div>
</body>
</html>

<styles>
html,
body,
div,
span,
applet,
object,
iframe,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
a,
abbr,
acronym,
address,
big,
cite,
code,
del,
dfn,
em,
img,
ins,
kbd,
q,
s,
samp,
small,
strike,
strong,
sub,
sup,
tt,
var,
b,
u,
i,
center,
dl,
dt,
dd,
ol,
ul,
li,
fieldset,
form,
label,
legend,
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
td,
article,
aside,
canvas,
details,
embed,
figure,
figcaption,
footer,
header,
hgroup,
menu,
nav,
output,
ruby,
section,
summary,
time,
mark,
audio,
video {
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 100%;
  font: inherit;
  vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section {
  display: block;
}
body {
  line-height: 1;
}
/* ol,
ul {
  list-style: none;
} */
blockquote,
q {
  quotes: none;
}
blockquote:before,
blockquote:after,
q:before,
q:after {
  content: "";
  content: none;
}
table {
  border-collapse: collapse;
  border-spacing: 0;
}

@import url("https://fonts.googleapis.com/css2?family=Bebas Neue&family=Lato:wght@400;700;900&family=Montserrat:wght@100&display=swap");

* {
  box-sizing: border-box;
}

body {
  height: 100vh;
  overflow: hidden;
  font-family: "Lato", sans-serif;
}

#wrapper {
  display: flex;
  height: 100%;
}

header {
  border-right: solid grey 2px;
}

h1 {
  font-size: 1.5rem;
  padding: 20px 20px;
  color: black;
}

nav {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.navlink {
  list-style-type: none;
  border-top: solid black 1px;
  padding: 10px 10px;
}

a {
  text-decoration: none;
  color: rgb(77, 75, 75);
}

main {
  overflow: auto;
  width: 700px;
  flex-grow: 1;
  padding: 30px 50px;
  color: rgb(77, 75, 75);
}

.section-title {
  font-size: 1.5rem;
  padding: 20px 0px;
  color: black;
}

.content {
  padding: 10px 10px;
  word-spacing: 0.2em;
}

.content-bullet {
  padding: 15px 40px;
}

.bullet {
  padding: 10px 0px;
}

@media (max-width: 768px) {
  #wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
  }

  header {
    border-right: solid white 2px;
  }

  body {
    overflow: hidden;
  }

  main {
    width: 100%;
    flex-grow: 1;
    padding: 20px 10px;
    color: rgb(77, 75, 75);
  }


  nav {
    height: 200px;
    overflow: scroll;
  }

  .navlink {
    list-style-type: none;
    border-top: solid black 1px;
    border-bottom: solid black 1px;
    padding: 10px 10px;
  }
}
</styles>

CodePudding user response:

Here you go...

Add this to your CSS:

.navlinks {
  overflow-y: scroll;
  height: 250px;
}

See the snippet below.

html,
body,
div,
span,
applet,
object,
iframe,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
a,
abbr,
acronym,
address,
big,
cite,
code,
del,
dfn,
em,
img,
ins,
kbd,
q,
s,
samp,
small,
strike,
strong,
sub,
sup,
tt,
var,
b,
u,
i,
center,
dl,
dt,
dd,
ol,
ul,
li,
fieldset,
form,
label,
legend,
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
td,
article,
aside,
canvas,
details,
embed,
figure,
figcaption,
footer,
header,
hgroup,
menu,
nav,
output,
ruby,
section,
summary,
time,
mark,
audio,
video {
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 100%;
  font: inherit;
  vertical-align: baseline;
}


/* HTML5 display-role reset for older browsers */

article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section {
  display: block;
}

body {
  line-height: 1;
}


/* ol,
ul {
  list-style: none;
} */

blockquote,
q {
  quotes: none;
}

blockquote:before,
blockquote:after,
q:before,
q:after {
  content: "";
  content: none;
}

table {
  border-collapse: collapse;
  border-spacing: 0;
}

@import url("https://fonts.googleapis.com/css2?family=Bebas Neue&family=Lato:wght@400;700;900&family=Montserrat:wght@100&display=swap");
* {
  box-sizing: border-box;
}

body {
  height: 100vh;
  overflow: hidden;
  font-family: "Lato", sans-serif;
}

#wrapper {
  display: flex;
  height: 100%;
}

header {
  border-right: solid grey 2px;
}

h1 {
  font-size: 1.5rem;
  padding: 20px 20px;
  color: black;
}

nav {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.navlink {
  list-style-type: none;
  border-top: solid black 1px;
  padding: 10px 10px;
}

a {
  text-decoration: none;
  color: rgb(77, 75, 75);
}

main {
  overflow: auto;
  width: 700px;
  flex-grow: 1;
  padding: 30px 50px;
  color: rgb(77, 75, 75);
}

.section-title {
  font-size: 1.5rem;
  padding: 20px 0px;
  color: black;
}

.content {
  padding: 10px 10px;
  word-spacing: 0.2em;
}

.content-bullet {
  padding: 15px 40px;
}

.bullet {
  padding: 10px 0px;
}

@media (max-width: 768px) {
  #wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
  }
  header {
    border-right: solid white 2px;
  }
  body {
    overflow: hidden;
  }
  main {
    width: 100%;
    flex-grow: 1;
    padding: 20px 10px;
    color: rgb(77, 75, 75);
  }
  nav {
    height: 200px;
    overflow: scroll;
  }
  .navlink {
    list-style-type: none;
    border-top: solid black 1px;
    border-bottom: solid black 1px;
    padding: 10px 10px;
  }
}

.navlinks {
  overflow-y: scroll;
  height: 250px;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="styles.css">
  <title>Javascript page</title>
</head>

<body>
  <div id="wrapper">
    <header>
      <nav>
        <h1>JS DOCUMENTATION</h1>
        <ul >
          <li ><a  href="#intro">Introduction</a></li>
          <li ><a href="#what2">What you should already know</a></li>
          <li ><a href="#java3">Javascript and Java</a></li>
          <li ><a href="#hello4">Hello world</a></li>
          <li ><a href="#var5">Variables</a></li>
          <li ><a href="#decl6">Declaring Variables</a></li>
          <li ><a href="#var6">Variable Scope</a></li>
          <li ><a href="#glob7">Global variables</a></li>
          <li ><a href="#const8">Constants</a></li>
          <li ><a href="data9">Data types</a></li>
        </ul>
      </nav>
    </header>

    <main>
      <section  id="intro1">
        <h2 >Introduction</h2>

        <p >
          JavaScript is a cross-platform, object-oriented scripting language. It is a small and lightweight language. Inside a host environment (for example, a web browser), JavaScript can be connected to the objects of its environment to provide programmatic control
          over them.
        </p>
        <p >
          JavaScript contains a standard library of objects, such as Array, Date, and Math, and a core set of language elements such as operators, control structures, and statements. Core JavaScript can be extended for a variety of purposes by supplementing it
          with additional objects; for example:
        </p>

        <ul >
          <li >Client-side JavaScript extends the core language by supplying objects to control a browser and its Document Object Model (DOM). For example, client-side extensions allow an application to place elements on an HTML form and respond to user events
            such as mouse clicks, form input, and page navigation.</li>
          <li >Server-side JavaScript extends the core language by supplying objects relevant to running JavaScript on a server. For example, server-side extensions allow an application to communicate with a database, provide continuity of information from
            one invocation to another of the application, or perform file manipulations on a server.</li>
        </ul>
      </section>

      <section  id="what2">
        <h2 >What you should already know</h2>

        <p >
          This guide assumes you have the following basic background:
        </p>

        <ul >
          <li >A general understanding of the Internet and the World Wide Web (WWW).</li>
          <li >Good working knowledge of HyperText Markup Language (HTML).</li>
          <li >Some programming experience. If you are new to programming, try one of the tutorials linked on the main page about JavaScript.</li>
        </ul>

      </section>

      <section  id="java3">
        <h2 >Javascript and Java</h2>
        <p >
          JavaScript and Java are similar in some ways but fundamentally different in some others. The JavaScript language resembles Java but does not have Java's static typing and strong type checking. JavaScript follows most Java expression syntax, naming conventions
          and basic control-flow constructs which was the reason why it was renamed from LiveScript to JavaScript.
        </p>

        <p >
          In contrast to Java's compile-time system of classes built by declarations, JavaScript supports a runtime system based on a small number of data types representing numeric, Boolean, and string values. JavaScript has a prototype-based object model instead
          of the more common class-based object model. The prototype-based model provides dynamic inheritance; that is, what is inherited can vary for individual objects. JavaScript also supports functions without any special declarative requirements.
          Functions can be properties of objects, executing as loosely typed methods.
        </p>




      </section>

      <section  id="hello4">
        <h2 >Hello World</h2>
        <p >
          To get started with writing JavaScript, open the Scratchpad and write your first "Hello world" JavaScript code:
        </p>
        <code>
                    function greetMe(yourName) { alert("Hello "   yourName); }
                    greetMe("World");
                </code>

        <p >
          Select the code in the pad and hit Ctrl R to watch it unfold in your browser!
        </p>

      </section>

      <section  id="var5">
        <h2 >Variables</h2>
        <p >
          You use variables as symbolic names for values in your application. The names of variables, called identifiers, conform to certain rules. A JavaScript identifier must start with a letter, underscore (_), or dollar sign ($); subsequent characters can also
          be digits (0-9). Because JavaScript is case sensitive, letters include the characters "A" through "Z" (uppercase) and the characters "a" through "z" (lowercase). You can use ISO 8859-1 or Unicode letters such as å and ü in identifiers. You can
          also use the Unicode escape sequences as characters in identifiers. Some examples of legal names are Number_hits, temp99, and _name.
        </p>

      </section>

      <section  id="decl6">
        <h2 >Declaring variables</h2>
        <p >
          JavaScript and Java are similar in some ways but fundamentally different in some others. The JavaScript language resembles Java but does not have Java's static typing and strong type checking. JavaScript follows most Java expression syntax, naming conventions
          and basic control-flow constructs which was the reason why it was renamed from LiveScript to JavaScript.
        </p>

        <p >
          In contrast to Java's compile-time system of classes built by declarations, JavaScript supports a runtime system based on a small number of data types representing numeric, Boolean, and string values. JavaScript has a prototype-based object model instead
          of the more common class-based object model. The prototype-based model provides dynamic inheritance; that is, what is inherited can vary for individual objects. JavaScript also supports functions without any special declarative requirements.
          Functions can be properties of objects, executing as loosely typed methods.
        </p>
      </section>

      <section  id="var6">
        <h2 >Variable-scope</h2>
        <p >
          JavaScript and Java are similar in some ways but fundamentally different in some others. The JavaScript language resembles Java but does not have Java's static typing and strong type checking. JavaScript follows most Java expression syntax, naming conventions
          and basic control-flow constructs which was the reason why it was renamed from LiveScript to JavaScript.
        </p>

        <p >
          In contrast to Java's compile-time system of classes built by declarations, JavaScript supports a runtime system based on a small number of data types representing numeric, Boolean, and string values. JavaScript has a prototype-based object model instead
          of the more common class-based object model. The prototype-based model provides dynamic inheritance; that is, what is inherited can vary for individual objects. JavaScript also supports functions without any special declarative requirements.
          Functions can be properties of objects, executing as loosely typed methods.
        </p>
      </section>

      <section  id="glob7">
        <h2 >Global Variables</h2>
        <p >
          JavaScript and Java are similar in some ways but fundamentally different in some others. The JavaScript language resembles Java but does not have Java's static typing and strong type checking. JavaScript follows most Java expression syntax, naming conventions
          and basic control-flow constructs which was the reason why it was renamed from LiveScript to JavaScript.
        </p>

        <p >
          In contrast to Java's compile-time system of classes built by declarations, JavaScript supports a runtime system based on a small number of data types representing numeric, Boolean, and string values. JavaScript has a prototype-based object model instead
          of the more common class-based object model. The prototype-based model provides dynamic inheritance; that is, what is inherited can vary for individual objects. JavaScript also supports functions without any special declarative requirements.
          Functions can be properties of objects, executing as loosely typed methods.
        </p>
      </section>

      <section  id="const8">
        <h2 >Constants</h2>
        <p >
          JavaScript and Java are similar in some ways but fundamentally different in some others. The JavaScript language resembles Java but does not have Java's static typing and strong type checking. JavaScript follows most Java expression syntax, naming conventions
          and basic control-flow constructs which was the reason why it was renamed from LiveScript to JavaScript.
        </p>

        <p >
          In contrast to Java's compile-time system of classes built by declarations, JavaScript supports a runtime system based on a small number of data types representing numeric, Boolean, and string values. JavaScript has a prototype-based object model instead
          of the more common class-based object model. The prototype-based model provides dynamic inheritance; that is, what is inherited can vary for individual objects. JavaScript also supports functions without any special declarative requirements.
          Functions can be properties of objects, executing as loosely typed methods.
        </p>
      </section>

      <section  id="data9">
        <h2 >Data types</h2>
        <p >
          JavaScript and Java are similar in some ways but fundamentally different in some others. The JavaScript language resembles Java but does not have Java's static typing and strong type checking. JavaScript follows most Java expression syntax, naming conventions
          and basic control-flow constructs which was the reason why it was renamed from LiveScript to JavaScript.
        </p>

        <p >
          In contrast to Java's compile-time system of classes built by declarations, JavaScript supports a runtime system based on a small number of data types representing numeric, Boolean, and string values. JavaScript has a prototype-based object model instead
          of the more common class-based object model. The prototype-based model provides dynamic inheritance; that is, what is inherited can vary for individual objects. JavaScript also supports functions without any special declarative requirements.
          Functions can be properties of objects, executing as loosely typed methods.
        </p>
      </section>
    </main>
  </div>
</body>

</html>

CodePudding user response:

Try pin pointing the exact part of the code relating to your questions.

It's a lot more easier that way!

CodePudding user response:

Although i was not able to find the the reason why the nav is 200px aligned top. you can fix it like this.

 .navlink:last-child {
     margin-bottom: 30px;
  }

 .navlink:first-child {
    margin-top: 200px;
 }
  • Related