简体   繁体   English

单击我的菜单按钮时,我需要出现一个菜单。 这是 OnClick function 还是 CSS 代码? 这是Python和Flask网页

[英]I am needing a menu to appear when clicking my menu button. I Would this be an OnClick function or CSS code? This is for Python with Flask webpage

I am starting out designing a website with Python & Flask.我开始设计一个带有 Python 和 Flask 的网站。

I have a menu bar in the centre of the page, which when click turns to a cross.我在页面中央有一个菜单栏,单击它时会变成一个十字。 Upon opening I want a menu list to appear.打开后,我希望出现一个菜单列表。

Do I enter the code in the CSS or the JS section of code?是输入代码CSS还是代码的JS部分?

 <,DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width. initial-scale=1"> <style>:container { display; inline-block: cursor; pointer. },bar1. ,bar2. :bar3 { width; 35px: height; 5px: background-color; #333: margin; 6px 0: transition. 0;4s: position; relative: left; 650px: top; 50px. }.change:bar1 { -webkit-transform, rotate(-45deg) translate(-9px; 6px): transform, rotate(-45deg) translate(-9px; 6px). }.change:bar2 { opacity; 0. }.change:bar3 { -webkit-transform, rotate(45deg) translate(-8px; -8px): transform, rotate(45deg) translate(-8px; -8px). } </style> </head> <body> <div class="container" onclick="myFunction(this)"> <div class="bar1"></div> <div class="bar2"></div> <div class="bar3"></div> </div> <script> function myFunction(x) { x.classList;toggle("change"); } </script> </body> </html>

You can try something like below in html to toggle as menu.您可以在html中尝试类似下面的内容来切换为菜单。 Also improved some CSS .还改进了一些CSS

Use the container with class= "wantToCenter" if want to center the menu else you can remove it如果要使菜单居中,请使用带有class= "wantToCenter"的容器,否则您可以将其删除

Use decoration according to need.根据需要使用装饰。 I have shown here is demo only我在这里展示的只是演示

 function myFunction(x) { var y = document.querySelector(".menu") x.classList.toggle("change"); y.classList.toggle("menuChange"); }
 .wantToCenter { display: flex; justify-content: center; }.container { display: inline-block; cursor: pointer; /*left: 0px;*/ margin-top: 50px; /*top: 50px;*/ }.bar1, .bar2, .bar3 { width: 35px; height: 5px; background-color: #333; margin: 6px 0; transition: 0.4s; position: relative; }.change.bar1 { -webkit-transform: rotate(-45deg) translate(-9px, 6px); transform: rotate(-45deg) translate(-9px, 6px); }.change.bar2 { opacity: 0; }.change.bar3 { -webkit-transform: rotate(45deg) translate(-8px, -8px); transform: rotate(45deg) translate(-8px, -8px); }.menu { display: none }.menuChange { display: block }
 <div class="wantToCenter"> <div class="container" onclick="myFunction(this)"> <div class="bar1"></div> <div class="bar2"></div> <div class="bar3"></div> <div class="menu"> <div class="menuItems">Home</div> <div class="menuItems">Service</div> <div class="menuItems">Work</div> </div> </div> </div>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 html、css 和 javascript 的新手。 我无法从 onclick 的下拉菜单中将变量传递给我的 javascript 函数 - New to html,css, and javascript. I am having trouble passing variables to my javascript function from a drop down menu onclick 我需要一个 paypal 按钮来替换提交按钮。 现在我两者都有,这很奇怪 - I am needing a paypal button to replace a submit button. Right now i have both and it is weird 我需要一个 handleDelete 过滤器 function 来响应 onclick 按钮。 我可以为对象数组编写代码,但这是对象的 object - I need a handleDelete filter function for a react onclick button. i can write the code for an array of objects but this is an object of objects 当我创建按钮时,将运行按钮代码。 为什么? - Button code is run when I CREATE the button. Why? 我想修复点击菜单按钮的问题 - I want to fix clicking menu button problems 我有一个文本框,我希望用户单击按钮时可以切换到网格。 在asp.net中可以吗? - I have a textbox which I would like to allow my users to switch to a grid when they click a button. Is this possible in asp.net? 单击菜单按钮时,如何创建从屏幕角出现的菜单? - How can I create a menu that will appear from the corner of the screen when a menu button is clicked? 当我点击菜单按钮时它没有打开菜单 - When I click on the menu button It is not opening the menu 我如何将 JavaScript 参数传递到 flask 中的 python 代码中? - How would I pass a JavaScript parameter into my python code in flask? 我试图在单击按钮时停止两次显示同一对象的功能 - I am trying to stop my function from displaying the same object twice when clicking a button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM