Hướng dẫn vay tiền HDBank mới nhất

Certainly! Below is an example of how you can create a sticky header for a website using CSS and JavaScript:

HTML:

```html

<!DOCTYPE html>

<html lang="en">

<head>

  <meta charset="UTF-8">

  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <title>Sticky Header Example</title>

  <link rel="stylesheet" href="styles.css">

</head>

<body>

  <header id="header">

    <h1>My Sticky Header</h1>

  </header>

  <div class="content">

    <!-- Your website content here -->

  </div>

  <script src="script.js"></script>

</body>

</html>

```

CSS (styles.css):

```css

body {

  margin: 0;

  font-family: Arial, sans-serif;

}

header {

  background-color: #333;

  color: #fff;

  padding: 10px 0;

  text-align: center;

  width: 100%;

  position: fixed;

  top: 0;

  left: 0;

  z-index: 1000;

}

.content {

  padding-top: 70px; /* Adjust this value to match the height of your header */

  /* Other styles for your content */

}

```

JavaScript (script.js):

```javascript

// JavaScript is optional for the basic functionality of sticky header, 

// but you might want to include it for more advanced behavior.

// In this example, let's assume you don't need additional JavaScript.

// However, if you want to add animations or additional interactions,

// you can extend the script.js file accordingly.

```

This code creates a simple website with a sticky header. The header will stay fixed at the top of the viewport as the user scrolls down the page. Adjust the styles and JavaScript as needed for your specific requirements.

4.8/5 (99 votes)

Bạn muốn vay tiền? - Click xem Vay tiền Online

Ý kiến khách hàngPreNext