Home Web Front-end JS Tutorial HTML, CSS, and jQuery: Build a beautiful web sidebar

HTML, CSS, and jQuery: Build a beautiful web sidebar

Oct 27, 2023 pm 03:42 PM
css jquery html

HTML, CSS, and jQuery: Build a beautiful web sidebar

HTML, CSS and jQuery: Build a beautiful web sidebar

In modern web design, the sidebar is an important part of the page layout one. It provides additional navigation, functionality and content display space to help users better browse and understand web content. This article will introduce how to use HTML, CSS and jQuery to build a beautiful web sidebar, and provide specific code examples.

First, we need to create a basic HTML structure. Here is a simple example:

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>侧边栏示例</title>
  <link rel="stylesheet" href="styles.css">
  <script src="jquery.min.js"></script>
  <script src="script.js"></script>
</head>
<body>
  <div class="sidebar">
    <ul class="menu">
      <li><a href="#">首页</a></li>
      <li><a href="#">分类</a></li>
      <li><a href="#">标签</a></li>
      <li><a href="#">关于</a></li>
    </ul>
  </div>

  <div class="content">
    <!-- 内容区域 -->
  </div>
</body>
</html>

In the above code, we have created a basic HTML structure containing a sidebar and content area. The sidebar is wrapped using div elements, and a ul list is added to display the navigation menu. The content area is represented by another div element, where you can place the specific content you need to display.

Next, we need to use CSS styles to beautify the appearance of the sidebar. Here is a basic CSS example:

/* styles.css */

.sidebar {
  width: 250px;
  background-color: #f1f1f1;
  padding: 20px;
}

.menu {
  list-style-type: none;
  padding: 0;
  margin: 0;
}

.menu li {
  margin-bottom: 10px;
}

.menu li a {
  text-decoration: none;
  color: #333;
  font-weight: bold;
}

.menu li a:hover {
  color: #ff0000;
}

In the above CSS code, we define the style of the sidebar. We set the width of the sidebar to 250 pixels and added a gray background color to it. We also use the padding property to set the spacing inside the sidebar to ensure the content is the right distance from the border. The style of the navigation menu uses the list-style-type attribute to remove the default bullet style, and uses the margin and padding attributes to set the spacing between items. spacing. We also used the text-decoration and color properties to set the style of the menu items, and the hover pseudo-class to set the color of the menu items when the mouse is hovered. style.

Finally, we can use jQuery to add some interactive effects and functionality. Here is a simple jQuery example:

/* script.js */

$(document).ready(function() {
  $('.menu li').click(function() {
    // 点击菜单项时的操作
    // 这里可以添加一些你想要的交互效果或功能
  });
  $('.menu li:first-child').addClass('active');
});

In the above jQuery code, we first use the $(document).ready() function to ensure that the code is executed after the document is loaded. Then, we use the .click() event to add a click event handler for the menu item, where you can add any interactive effects or functionality you want. We also added an active class to the first menu item using the .addClass() function, you can customize this class as needed and add it for specific menu items.

To sum up, this article provides an example of building a beautiful web page sidebar by using HTML, CSS and jQuery. Of course, you can further beautify the sidebar according to your needs and creativity, and add more interactive effects and functions according to actual conditions. Hope this example helps you build a beautiful web sidebar!

The above is the detailed content of HTML, CSS, and jQuery: Build a beautiful web sidebar. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to create an image sprite with HTML and CSS How to create an image sprite with HTML and CSS Aug 23, 2025 am 06:25 AM

AnimagespritecombinesmultipleimagesintoonefiletoreduceHTTPrequestsandimprovepageloadspeed.2.Prepareasinglespriteimagebyarrangingsmallergraphics(e.g.,50x50pxicons)inagrid(e.g.,100x100px).3.UseHTMLelementslikewithsharedanduniqueclasses(e.g.,class=&quot

How to restrict file types for an upload input in HTML How to restrict file types for an upload input in HTML Aug 24, 2025 am 02:57 AM

Use the accept attribute to limit the upload type of HTML file, such as accept="image/*" only allows images, accept=".pdf" only allows PDF, accept=".doc,.docx,.pdf,.txt" allows multiple specified types, and can combine JavaScript to verify file types to improve user experience, but security verification must be performed on the server side, because the accept attribute is not secure and the browser supports are different, and it is only used to improve availability rather than replace server verification.

How to disable a form element in HTML How to disable a form element in HTML Aug 30, 2025 am 08:45 AM

To disable HTML form elements, you can use the disabled attribute, which can prevent user interaction and the element value will not be submitted with the form. This attribute is of a Boolean type and can be directly added to form element tags such as input, textarea, select, or button. For example, it can also be dynamically controlled through JavaScript, such as document.getElementById("myInput").disabled=true. If the element cannot be edited but the value is still submitted, you should use the readonly attribute. The disabled attribute is simple and effective and widely supported.

What is ARIA in HTML for accessibility? What is ARIA in HTML for accessibility? Aug 27, 2025 am 04:57 AM

ARIAisneededtoenhancewebaccessibilityfordynamiccontentandcustomUIcomponentsthatlacknativeHTMLsemantics.1)ARIArolesdefineanelement’spurpose(e.g.,role="dialog").2)ARIApropertiesdescribecharacteristics(e.g.,aria-label,aria-describedby).3)ARIAs

How to create a ripple effect on a button with CSS How to create a ripple effect on a button with CSS Aug 23, 2025 am 07:51 AM

To create a button's ripple effect, you need to combine HTML, CSS animation and JavaScript; first build a button structure with span elements, set the button style with CSS and hide the overflow content, then create the initial hidden circular ripple element through absolute positioning and rounded corner styles, then define the CSS keyframe animation that expands and fades from the center point, and finally use JavaScript to dynamically add activation classes when clicking to trigger the animation, and calculate the click coordinates to make the ripple diffuse from the click position. The entire process ensures continuous triggering through re-arrangement, and finally achieves an ink ripple interaction effect similar to MaterialDesign.

How to implement a basic client-side image map in HTML How to implement a basic client-side image map in HTML Aug 26, 2025 am 08:08 AM

To implement basic client image mapping, you need to follow the following steps: 1. Use a tag with the usemap attribute, whose value is "#map name", such as

How to use the source tag with video and audio in HTML How to use the source tag with video and audio in HTML Aug 28, 2025 am 02:42 AM

Thetagisusedtospecifymultiplemediasourceswithinorelements,ensuringbroaderbrowsercompatibility.1.Itallowslistingdifferentfileformatssothebrowsercanplaythefirstsupportedone.2.Thetypeattributehelpsbrowsersdetectcompatibilitywithoutdownloadingthefile.3.F

How to use the mix-blend-mode property in CSS How to use the mix-blend-mode property in CSS Aug 29, 2025 am 07:37 AM

mix-blend-mode controls the mixing method of the content of the element and the color of the behind element. 1. There must be a background (such as picture or color) to show the effect; 2. Commonly used values ​​such as multiply and screen can achieve text hollowing or image superposition; 3. Pay attention to stacking context to avoid parent isolation:isolate from preventing mixing; 4. Avoid overuse in performance, especially in large elements or animations; 5. Modern browsers have good support, suitable for creating text effects, image filters, hover interactions and artistic layouts. It is recommended to get started with multiply and screen and combine high-contrast background to test the effect.

See all articles