简体   繁体   English

在HTML或CSS中单击按钮之前,如何隐藏表单?

[英]How do you hide a form until a button is clicked in HTML or CSS?

I want to hide an html form within a button. 我想在按钮内隐藏HTML表单。 I tried adding a button around the form similar to a parent div with a child div, but that didn't seem to work. 我尝试在窗体的周围添加类似于父div和子div的按钮,但这似乎不起作用。 I'm confused about how to add the "hide" element. 我对如何添加“隐藏”元素感到困惑。 Do I have to use javascript or jQuery? 我必须使用javascript还是jQuery? Or is there a simple way to do it with just CSS or HTML? 还是只有CSS或HTML可以做到这一点的简单方法?

Thanks in advance!! 提前致谢!!

 /*LOGIN*/ html { background: #fff; font-size: 10pt; } .loginform ul { padding: 0; margin: 0; } .loginform il { display: inline; float: top right; } label { display: block; color: #ED4337; } label:hover { background-color: #fff; color: white; border-radius: 8px; } .cf:before .cf:after { content: ""; display: table; } .cf:after { *zoom: 1; } :focus { outline: 0; } .loginform input:not([type=submit]) { padding: 5px; margin-right: 10px; border: 1px solid rgba(0, 0, 0, 0.3); border-radius: 3px; box-shadow: inset 0px 1px 3px 0px rgba(0, 0, 0, 0.1), 0px 1px 0px 0px rgba(250, 250, 250, 0.5); } .loginform input[type=submit] { border: 1px solid rgba(0, 0, 0, 0.3); background: #64c8ef; /*old browsers*/ background: -moz-linear-gradient(top, #64c8ef 0%, #00a2e2 100%); /*FF3.6+ */ background: -webkit-gradient(linear, left top, left bottom, color-stop(100%, #00a2e2)); background: -webkit-linear-gradient(top, #64c8ef 0%, #00a2e2 100%); background: -o-linear-gradient(top, #64c8ef 0%, #00a2e2 100%); background: -ms-linear-gradient(top, #64c8ef 0%, #00a2e2 100%); background: linear-gradient(to bottom, #64c8ef 0%, #00a2e2); filter: progid:DXImageTransform.Microsoft.gradient ( startColors)='#64c8ef', endColorstr='#00a2e2', GradientType=0); color: #fff; padding: 5px 15px; margin-right: 0; margin-top: 15px; border-radius: 3px; text-shadow: 1px 1px 0px #fff; } /*END LOG IN */ 
 <!--LOG IN INFO--> <button class="log">Log In <section class="loginfrom cf"> <form name="login" action="index_submit" method="get" accept-charset="utf-8"> <ul> <li><label for="username">Email</label> <input type="email" name="usermail" placeholder="yourname@email.com" required></li> <li><label for="password">Password</label> <input type="email" name="password" placeholder="password" required></li> <li> <input type="submit" value="Login"></li> </ul> </form> </section> </button> <!--END LOG IN INFO--> 

First and foremost, close the button tag <button class="log">Log in</button> . 首先,关闭按钮标记<button class="log">Log in</button> Then, hide the form by using css, like .loginform { display: none; } 然后,使用CSS隐藏表单,例如.loginform { display: none; } .loginform { display: none; }

Finally, to show the form when the user clicks the button, you can use jQuery. 最后,要在用户单击按钮时显示表单,可以使用jQuery。

$('.log').click(function() {
    $('.loginform').css('display', 'block');
});

To further understand CSS and Javascript and how they work together, I strongly advise you to read some tutorials and check some examples in W3Schools 为了进一步了解CSS和Javascript以及它们如何协同工作,我强烈建议您阅读一些教程并检查W3Schools中的一些示例。

https://www.w3schools.com/jquery/default.asp https://www.w3schools.com/jquery/default.asp

https://www.w3schools.com/css/default.asp https://www.w3schools.com/css/default.asp

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

相关问题 在HTML中单击所有元素之前,如何隐藏按钮? - How do I hide a button until all elements are clicked in HTML? 如何隐藏iframe,直到单击按钮? - How to hide an iframe until a button is clicked? 如何在单击按钮之前隐藏 div 内容? - How to hide div contents until button is clicked? 如何隐藏标签,直到单击“提交”按钮? - How to hide labels until the submit button is clicked? 我如何创建一个固定的按钮,当使用HTML和CSS单击该按钮时会打开一个联系表单? - How do I create a fixed button which opens a contact form when clicked using HTML & CSS? 如何隐藏Web应用程序中的表单,直到单击按钮进行登录和注册为止 - How can I hide a form within a web application until a button is clicked for login and register purposes 触发 html 表单提交就像您单击按钮一样(但没有按钮)? - Trigger html form submit as if you clicked on button (but without a button)? 在单击另一个按钮之前,如何禁用HTML按钮? - How can I disable an HTML button until another button is clicked? 如何隐藏信息,仅在单击按钮html,css时显示。 JavaScript的? - How to hide the information, just only show when button is clicked html, css. javascript? 如何使用 Vanilla JS HTML CSS 仅隐藏属于同一类按钮的单击按钮 - How to hide only clicked button belonging to same class of buttons using Vanilla JS HTML CSS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM