Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html CSS导航栏固定在顶部,尽管将位置更改为静态_Html_Css - Fatal编程技术网

Html CSS导航栏固定在顶部,尽管将位置更改为静态

Html CSS导航栏固定在顶部,尽管将位置更改为静态,html,css,Html,Css,我一直在练习这个freecodecamp挑战,我正在努力实现这个输出 这是我的HTML代码 <script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script> <!DOCTYPE html> <html lang="en"> <head> <meta charset="

我一直在练习这个freecodecamp挑战,我正在努力实现这个输出

这是我的HTML代码

<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=">
  <title>Technical Documentation</title>
</head>
<body>
  <main id="main-doc">
 <section class="main-section" id="introduction">
   <!--1-->
   <header>
     <h2>Introduction</h2>
   </header>
   <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 class="main-section" id="what_you_should_already_know"> 
  <!--2-->
     <header>
     <h2>What you should already know</h2>
   </header>
  <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 class="main-section" id="javascript_and_java">
  <!--3-->
     <header>
     <h2>Javascript and Java</h2>
   </header>
  <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>
  <p>JavaScript is a very free-form language compared to Java. You do not have to declare all variables, classes, and methods. You do not have to be concerned with whether methods are public, private, or protected, and you do not have to implement interfaces. Variables, parameters, and function return types are not explicitly typed.</p>
</section>
 <section class="main-section" id="hello_world"> 
   <!--4-->
      <header>
     <h2>Hello World</h2>
   </header>
   <p>To get started with writing JavaScript, open the Scratchpad and write your first "Hello world" JavaScript code:</p>
   <pre>
   <code>
     function greetMe(yourName) { alert("Hello " + yourName); }
        greetMe("World");
   </code>
   </pre>
   <p>Select the code in the pad and hit Ctrl+R to watch it unfold in your browser!</p>
 </section>
    
<section class="main-section" id="variables"> 
  <!--5-->
     <header>
     <h2>Variables</h2>
   </header>
  <p>You use variables as symbolic names for values in your application. The names of variables, called identifiers, conform to certain rules.</p>
  <p>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).</p>
  <p>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 class="main-section" id="declaring_variables"> 
  <!--6-->
     <header>
     <h2>Declaring Variables</h2>
   </header>
  <p>You can declare a variable in three ways:</p>
  <p>With the keyword var. For example,</p>
  <pre>
    <code>var x = 42;</code>
  </pre>
  <p>This syntax can be used to declare both local and global variables.</p>
  <p>By simply assigning a value. For example,</p>
  <pre>
    <code>x = 42;</code>
  </pre>
  <p>This always declares a global variable. It generates a strict JavaScript warning. You shouldn't use this variant.</p>
  <p>With the keyword let. For example,</p>
  <pre>
    <code>let x = 42;</code>
  </pre>
  <p>This syntax can be used to declare a block scope local variable. See Variable scope below.</p>
  
</section>
    
<section class="main-section" id="variable_scope"> 
  <!--7-->
     <header>
     <h2>Variable Scope</h2>
   </header>
  <p>When you declare a variable outside of any function, it is called a global variable, because it is available to any other code in the current document. When you declare a variable within a function, it is called a local variable, because it is available only within that function.</p>
  <p>JavaScript before ECMAScript 2015 does not have block statement scope; rather, a variable declared within a block is local to the function (or global scope) that the block resides within. For example the following code will log 5, because the scope of x is the function (or global context) within which x is declared, not the block, which in this case is an if statement.</p>
  <code>if (true) { var x = 5; } console.log(x); // 5</code>
  <p>This behavior changes, when using the let declaration introduced in ECMAScript 2015.</p>
  <code>
    if (true) { let y = 5; } console.log(y); // ReferenceError: y is not
        defined
  </code>
 </section>
    
<section class="main-section" id="global_variables"> 
  <!--8-->
     <header>
     <h2>Global Variables</h2>
   </header>
  <p>Global variables are in fact properties of the global object. In web pages the global object is window, so you can set and access global variables using the window.variable syntax.</p>
  <p>Consequently, you can access global variables declared in one window or frame from another window or frame by specifying the window or frame name. For example, if a variable called phoneNumber is declared in a document, you can refer to this variable from an iframe as parent.phoneNumber.</p>
</section>
    
<section class="main-section" id="constants"> 
  <!--9-->
     <header>
     <h2>Constants</h2>
   </header>
  <p>You can create a read-only, named constant with the const keyword. The syntax of a constant identifier is the same as for a variable identifier: it must start with a letter, underscore or dollar sign and can contain alphabetic, numeric, or underscore characters.</p>
  <pre>
    <code>const PI = 3.14;</code>
  </pre>
  <p>A constant cannot change value through assignment or be re-declared while the script is running. It has to be initialized to a value.</p>
  <p>The scope rules for constants are the same as those for let block scope variables. If the const keyword is omitted, the identifier is assumed to represent a variable.</p>
  <p>You cannot declare a constant with the same name as a function or variable in the same scope. For example:</p>
  <pre>
    <code>
      // THIS WILL CAUSE AN ERROR
      function f() {}; const f = 5; 
      // THIS WILL CAUSE AN ERROR ALSO 
      function f() { const g = 5; var g; //statements
        }
    </code>
  </pre>
  <p>However, object attributes are not protected, so the following statement is executed without problems.</p>
  <pre>
    <code>
      const MY_OBJECT = {"key": "value"}; MY_OBJECT.key = "otherValue";
    </code>
  </pre>
</section>
    
<section class="main-section" id="data_types"> 
  <!--10-->
     <header>
     <h2>Data Types</h2>
   </header>
  <p>The latest ECMAScript standard defines seven data types:</p>
  <ul>
    <li>Six data types that are primitives</li>
    <ul>
      <li>Boolean. true and false.</li>
      <li>null. A special keyword denoting a null value. Because JavaScript is case-sensitive, null is not the same as Null, NULL, or any other variant.</li>
      <li>undefined. A top-level property whose value is undefined.</li>
      <li>Number. 42 or 3.14159.</li>
      <li>String. "Howdy"</li>
      <li>Symbol (new in ECMAScript 2015). A data type whose instances are unique and immutable.</li>
    </ul>
    <li>and Object</li>
  </ul>
  <p>Although these data types are a relatively small amount, they enable you to perform useful functions with your applications. Objects and functions are the other fundamental elements in the language. You can think of objects as named containers for values, and functions as procedures that your application can perform.</p>
</section>
    
<section class="main-section" id="if...else_statement"> 
  <!--11-->
     <header>
     <h2>if...else statement</h2>
   </header>
  <p>Use the if statement to execute a statement if a logical condition is true. Use the optional else clause to execute a statement if the condition is false. An if statement looks as follows:</p>
  <pre>
    <code>
      if (condition) { statement_1; } else { statement_2; }
    </code>
  </pre>
  <p>condition can be any expression that evaluates to true or false. See Boolean for an explanation of what evaluates to true and false. If condition evaluates to true, statement_1 is executed; otherwise, statement_2 is executed. statement_1 and statement_2 can be any statement, including further nested if statements.</p>
  <p>You may also compound the statements using else if to have multiple conditions tested in sequence, as follows:</p>
  <pre>
    <code>
     if (condition_1) { statement_1; } else if (condition_2) { statement_2;
        } else if (condition_n) { statement_n; } else { statement_last; } 
    </code>
  </pre>
  <p>In the case of multiple conditions only the first logical condition which evaluates to true will be executed. To execute multiple statements, group them within a block statement ({ ... }) . In general, it's good practice to always use block statements, especially when nesting if statements:</p>
  <pre>
    <code>
      if (condition) { statement_1_runs_if_condition_is_true;
        statement_2_runs_if_condition_is_true; } else {
        statement_3_runs_if_condition_is_false;
        statement_4_runs_if_condition_is_false; }
    </code>
  </pre>
  <p>It is advisable to not use simple assignments in a conditional expression, because the assignment can be confused with equality when glancing over the code. For example, do not use the following code:</p>
  <pre>
    <code>
      if (x = y) { /* statements here */ }
    </code>
  </pre>
  <p>If you need to use an assignment in a conditional expression, a common practice is to put additional parentheses around the assignment. For example:</p>
  <pre>
    <code>
      if ((x = y)) { /* statements here */ }
    </code>
  </pre>
</section>
    
<section class="main-section" id="while_statement"> 
<!--12-->
     <header>
     <h2>While statement</h2>
   </header>
  <p>A while statement executes its statements as long as a specified condition evaluates to true. A while statement looks as follows:</p>
  <pre>
    <code>
      while (condition) statement
    </code>
  </pre>
  <p>If the condition becomes false, statement within the loop stops executing and control passes to the statement following the loop.</p>
  <p>The condition test occurs before statement in the loop is executed. If the condition returns true, statement is executed and the condition is tested again. If the condition returns false, execution stops and control is passed to the statement following while.</p>
  <p>To execute multiple statements, use a block statement ({ ... }) to group those statements.</p>
  <p>Example:</p>
  <p>The following while loop iterates as long as n is less than three:</p>
  <pre>
    <code>
      var n = 0; var x = 0; while (n&lt;3) { n++; x += n; }
    </code>
  </pre>
  <p>With each iteration, the loop increments n and adds that value to x. Therefore, x and n take on the following values:</p>
  <ul>
    <li>After the first pass: n = 1 and x = 1</li>
    <li>After the second pass: n = 2 and x = 3</li>
    <li>After the third pass: n = 3 and x = 6</li>
  </ul>
  <p>After completing the third pass, the condition n&lt;3 is no longer true, so the loop terminates.</p>
</section>
    
<section class="main-section" id="function_decleration"> 
  <!--13-->
     <header>
     <h2>Function decleration</h2>
   </header>
  <p>A function definition (also called a function declaration, or function statement) consists of the function keyword, followed by:</p>
  <ul>
    <li>The name of the function.</li>
    <li>A list of arguments to the function, enclosed in parentheses and separated by commas.</li>
    <li>The JavaScript statements that define the function, enclosed in curly brackets, { }.</li>
  </ul>
  <p>For example, the following code defines a simple function named square:</p>
  <pre>
    <code>
      function square(number) { return number * number; }
    </code>
  </pre>
  <p>The function square takes one argument, called number. The function consists of one statement that says to return the argument of the function (that is, number) multiplied by itself. The return statement specifies the value returned by the function.</p>
  <pre>
    <code>
      return number * number;
    </code>
  </pre>
  <p>Primitive parameters (such as a number) are passed to functions by value; the value is passed to the function, but if the function changes the value of the parameter, this change is not reflected globally or in the calling function.</p>
 </section>
    
<section class="main-section" id="reference"> 
  <!--14-->
     <header>
     <h2>Reference</h2>
   </header>
  <ul>
    <li>All the documentation in this page is taken from <a href="#">MDN</a></li>
  </ul>
</section>
  </main>
  <nav id="navbar">
    <header>
      <h1>JS Documentation</h1>
    </header>
    <a class="nav-link" href="#introduction">Introduction</a>
    <a class="nav-link" href="#what_you_should_already_know">What you should already know</a>
    <a class="nav-link" href="#javascript_and_java">Javascript and Java</a>
    <a class="nav-link" href="#hello_world">Hello World</a>
    <a class="nav-link" href="#variables">Variables</a>
    <a class="nav-link" href="#declaring_variables">Declaring variables</a>
    <a class="nav-link" href="#variable_scope">Variable scope</a>
    <a class="nav-link" href="#global_variables">Global variables</a>
    <a class="nav-link" href="#constants">Constants</a>
    <a class="nav-link" href="#data_types">Data types</a>
    <a class="nav-link" href="#if...else_statement">if...else statement</a>
    <a class="nav-link" href="#while_statement">While statement</a>
    <a class="nav-link" href="#function_decleration">Function decleration</a>
    <a class="nav-link" href="#reference">Reference</a>
  </nav>
</body>
</html>
在pad中选择代码,然后按Ctrl+R以查看它在浏览器中展开

变量 在应用程序中使用变量作为值的符号名。变量名(称为标识符)符合某些规则

JavaScript标识符必须以字母、下划线(_)或美元符号($)开头;后续字符也可以是数字(0-9)。因为JavaScript是区分大小写的,所以字母包括字符“A”到“Z”(大写)和字符“A”到“Z”(小写)

您可以使用ISO 8859-1或Unicode字母,例如标识符中的å和ü。还可以将Unicode转义序列用作标识符中的字符。法定名称的一些例子有Number_hits、temp99和_name

变量的声明 可以通过三种方式声明变量:

以关键字var.为例

body{
    grid-template-columns: 100%;
    grid-template-rows: 100%;
    grid-template-areas: "main-content";
  }
此语法可用于声明局部变量和全局变量

通过简单地赋值。比如说,

body{
    grid-template-columns: 100%;
    grid-template-rows: 100%;
    grid-template-areas: "main-content";
  }
这总是声明一个全局变量。它会生成一个严格的JavaScript警告。你不应该使用这个变体

使用关键字let。比如说,

body{
    grid-template-columns: 100%;
    grid-template-rows: 100%;
    grid-template-areas: "main-content";
  }
此语法可用于声明块作用域局部变量。请参阅下面的变量范围

可变范围 在任何函数之外声明变量时,它称为全局变量,因为当前文档中的任何其他代码都可以使用该变量。在函数中声明变量时,称为局部变量,因为它仅在该函数中可用

ECMAScript 2015之前的JavaScript没有block语句范围;相反,在块中声明的变量是块所在的函数(或全局范围)的局部变量。例如,下面的代码将记录5,因为x的作用域是在其中声明x的函数(或全局上下文),而不是块(在本例中是if语句)

if(true){var x=5;}console.log(x);//5
使用ECMAScript 2015中引入的let声明时,此行为会发生变化


如果(true){let y=5;}console.log(y);//ReferenceError:y不是
定义
全局变量 全局变量实际上是全局对象的属性。在网页中,全局对象是window,因此您可以使用window.variable语法设置和访问全局变量

因此,您可以通过指定窗口或框架名称,从另一个窗口或框架访问在一个窗口或框架中声明的全局变量。例如,如果在文档中声明了一个名为phoneNumber的变量,则可以从iframe中将该变量引用为parent.phoneNumber

常数 您可以使用const关键字创建一个只读的命名常量。常量标识符的语法与变量标识符的语法相同:它必须以字母、下划线或美元符号开头,并且可以包含字母、数字或下划线字符

脚本运行时,常量不能通过赋值更改值或重新声明。它必须初始化为一个值

常量的作用域规则与let block作用域变量的作用域规则相同。如果省略const关键字,则假定标识符表示变量

不能在同一范围内声明与函数或变量同名的常量。例如:

但是,对象属性不受保护,因此执行以下语句时不会出现问题

数据类型 最新的ECMAScript标准定义了七种数据类型:

  • 六种基本数据类型
    • 布尔型。真假
    • 空。表示空值的特殊关键字。因为JavaScript区分大小写,所以null与null、null或任何其他变体不同
    • 未定义。值未定义的顶级属性
    • 号码。42或3.14159
    • 绳子。“你好”
    • 符号(ECMAScript 2015中新增)。实例唯一且不可变的数据类型
  • 和对象
尽管这些数据类型的数量相对较少,但它们使您能够在应用程序中执行有用的功能。对象和函数是语言中的其他基本元素。您可以将对象视为值的命名容器,将函数视为应用程序可以执行的过程

if…else语句 如果逻辑条件为true,则使用if语句执行语句。如果条件为false,则使用可选的else子句执行语句。if语句如下所示:

条件可以是计算结果为true或false的任何表达式。有关计算结果为true和false的说明,请参见布尔值。如果条件的计算结果为true,则执行语句_1;否则,执行语句_2。语句_1和语句_2可以是任何语句,包括进一步嵌套的if语句

如果要按顺序测试多个条件,还可以使用else合成语句,如下所示:

在多个条件的情况下,仅执行计算结果为true的第一个逻辑条件。要执行多个语句,请将它们分组到块语句({…})中。通常,最好始终使用块语句,尤其是嵌套if语句时:

建议不要在条件表达式中使用简单赋值,因为赋值可以是