


How to adapt and adjust the label size of the Element-UI horizontal menu el-menu on the PC and mobile side?
Element-UI horizontal menu el-menu: adaptation between PC and mobile terminals and label size adjustment
Element-UI's el-menu
component is powerful, but developers often need additional processing when adapting to PC and mobile. This article will explore how to adjust the size of menu labels in mode="horizontal"
mode, and how to deal with the differences between hovering and clicking on the mobile side.
question:
Using mode="horizontal"
el-menu
, on the PC side, the menu item hovered and expanded, leaving and closed, as expected. However, on the mobile terminal, this interaction is invalid. You need to click to expand the submenu and click to close it in other areas. In addition, developers also hope to be able to resize menu labels.
Code example:
The following code shows a horizontal el-menu
that contains first and second menus. The PC side is normal, but the mobile terminal menu needs to be expanded/closed.
<el-menu :ellipsis="ellipsis" active-text-color="#ffd04b" background-color="#1b80e9" class="el-menu-demo" mode="horizontal" ref="menu" text-color="#fff"> <el-menu-item index="0"> <a target="_blank">front page</a></el-menu-item> <el-menu-item index="1"> <a target="_blank">Event News</a></el-menu-item> <el-sub-menu index="2"> <template>National fitness</template> <el-menu-item index="2-1">Introduction to the swimming pool</el-menu-item> <el-menu-item index="2-2">Charge announcement</el-menu-item> <el-menu-item index="2-3">Service staff announcement</el-menu-item> <el-menu-item index="2-4">Public notice of rules and regulations</el-menu-item> </el-sub-menu> </el-menu>
methods: { handleOpen(key, keyPath) { console.log("open: key=" key, "keyPath=" keyPath); }, handleClose(key, keyPath) { console.log("close: key=" key, "keyPath=" keyPath); } }
Solution:
- Menu Tag Size: Use CSS style to control font size (
font-size
) and margins (padding
). For example:
.el-menu-demo .el-menu-item { font-size: 14px; padding: 0 15px; }
- Mobile adaptation:
el-menu
automatically switches to click-and-expand mode on the mobile side, which is part of its responsive design, not a mistake. If you need to maintain the hover effect on the PC side on the mobile side, you need to customize the components or consider other UI libraries. You can use media queries to adjust styles based on screen width, for example:
@media (max-width: 768px) { .el-menu-demo { /* Mobile style*/ } }
Through CSS style adjustment and responsive design, the display and interaction problems of el-menu
on different devices can be effectively solved, thereby improving the user experience. If more complex interaction logic is needed, you need to consider custom components or use other more flexible UI components.
The above is the detailed content of How to adapt and adjust the label size of the Element-UI horizontal menu el-menu on the PC and mobile side?. For more information, please follow other related articles on the PHP Chinese website!

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.

HTMLisaspecifictypeofcodefocusedonstructuringwebcontent,while"code"broadlyincludeslanguageslikeJavaScriptandPythonforfunctionality.1)HTMLdefineswebpagestructureusingtags.2)"Code"encompassesawiderrangeoflanguagesforlogicandinteract

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

Zend Studio 13.0.1
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.