Greetings, dear readers of the blog site. Today I want to talk about things like HTML forms. Whatever the engine of your site (cms), it will definitely use forms created using the Form and Input tags, as well as the Button, Checked, Value, Checkbox, Radio, Checkbox, Submit attributes and parameters .
Well, you can also add elements to this for creating drop-down lists and text fields - Select, Option, Textarea, Label, Fieldset, Legend.
Why forms are needed and how they work on modern sites
The same site search string () is created using these tags, and searching for that on your project will be mandatory. Therefore, understanding how they are arranged and work will not hinder you at all for successful work on the design, and it will not be superfluous for self-promotion and promotion.
So, with the rationale for the need to study these elements, I think there should be no more questions, so it's time to proceed directly to the study of their possible options.
Yes, I also want to remind you that we have already managed to consider a lot of materials on the topic of hypertext markup language, for example, three ) and .
At their core, forms consist of elements, to create which various tags are inserted inside the main container from Form tags - Checked, Value, Checkbox, Radio, Checkbox, Submit, etc. We just need to place its code in any place convenient for this site template , specifying how it should look with the help of tags and their attributes.
This could be a text box with a submit button for the entered request, radio button choices (where you can only leave one of the provided buttons pressed), multiple text boxes with a submit button (), and more.
For example, in the case of "search", using the Value attribute, you can specify what exactly will be written on the button located next to the field for entering a query. The data entered in the forms must be further processed in some way.
For example, in the case of feedback, the user, after filling in the field with his name, entering his E-mail and message text, and then clicking on the submit button, will have the right to hope to send the data from the form to the E-mail of the site author. But to implement this using only one hypertext markup language (), unfortunately, is not possible.
For these purposes, a special handler program is required, which, after the user clicks on the send button, will take all the data from the feedback fields and send them to the E-mail owner of the resource. Which program will do this, you must specify yourself using the Action attribute.
Typically, the processing program is a script written in PHP. Therefore, in the Action attribute of the Form tag, you will need to specify the path to the file of this script located on the server of your hosting. I will give as an example a subscription to the RSS feed of my blog via E-mail:
A little unclear, probably, it seems at first, but I think that everything will become clearer as the story goes on.
Form and Input tags for creating buttons, checkboxes and radio buttons
Any form must be enclosed in opening and closing tags Form. This is a kind of container for their creation. This tag has a number of required and optional attributes:
- Name - a unique name that must be specified if several web forms will be used in the Html file where you are doing something
- Action - a mandatory attribute indicating the path to the script to which the data from it will be transferred for further processing
- Method - using it you can change the method of passing data from this web form to the handler file script. If you do not specify it, then the Get method will be used by default, which, in fact, is intended mainly for variables and short messages, and also passing data in an open way through the browser's address bar. To pass form data to the handler script, it is still better to use POST method, designed specifically for transferring text messages in a closed way
Let's look at the rest of the tags that allow you to create a variety of web forms. The most versatile is Input. Inside it, the Type attribute must be written, which determines what exactly the HTML form created using this tag will be like.
With Input and Type , you can create the following elements:
- single line text fields (Type="Text")
- password fields (Type="Password")
- checkboxes (Type="Checkbox")
- radio buttons (Type="Radio")
- hidden fields (Type="Hidden")
- normal buttons (Type="Button")
- buttons for submitting data to the handler (Type="Submit")
- buttons to bring the web form to its original state (Type="Reset")
- fields for uploading files to the server (Type="File)
- image buttons (Type="Image")
Input does not have a closing tag. What exactly will be the web form created with it depends entirely on the parameter specified in the Type attribute. If Type is not specified, a text field will be created by default.
Examples of forms created on Input with different values for Type
Other attributes of the Input tag and examples of their use
Consider what the rest of the attributes are for:
- Name - if the data is to be sent to the handler program script, then you must specify a parameter for the Name attribute. Under this name, the data submitted from the form will appear in the information handler program.
- Size - with the help of it the size of the field of the created web form is set. The value is specified in the number of characters that can fit in this field. If Size is not specified, the width will default to 24 characters.
- Maxlength - by default, the number of characters that can be entered in the Html form is not limited, but using Maxlength you can set this limit. More characters than it will be indicated, you will not be able to enter in the field
- Value - with it you can set what exactly will be written by default in the field or on the send data button
- Checked is a flag attribute that can be inserted into the Input for radio buttons (radio) or for checkboxes (checkbox). In this case, this radio button or checkbox will be active when the page with the webform is loaded (they will already have a checkmark)
Now let's look at everything form examples with Input. The appearance of the text field is similar to the appearance of the password field, so we will only consider the option of creating Text, for example, to enter an email address:
Now let's look at creating a web form with radio buttons (Radio):
Note that this form uses the Input tag twice, once to create each of the two radio buttons. Moreover, each of them has the Name attribute with the same value (resultat), and the Value value is different (YES and NO).
This means that when processing it, if any of the radio buttons is selected, a variable will be sent, the name of which is written in Name, but the value of this variable will depend on which radio button was selected.
Consider the example of creating a web form with checkboxes (Checkbox):
Checkboxes differ from radio buttons by the ability to select multiple options at once. Name is used to determine in the handler file which checkbox the checkboxes are set in, and Value specifies the value that will be sent to the handler (if Value is not set, then the text located next to this checkbox will be sent to the handler).
Select, Option, Textarea, Label, Fieldset, Legend - drop-down lists, text areas and other web form elements
To begin with, I want to remind you a little what, in fact, web forms are and why they are needed on the pages of the site. They are primarily designed to repeat the elements available in any operating system in a user-friendly form: buttons, text entry fields, drop-down lists, checkboxes, switches, and the like.
All users, without any additional explanation, understand the purpose of these elements, and if they see an Html form button, they understand that they need to click on it.
Moreover, all its constituent elements (like Select, Option, Textarea, Label, Fieldset, Legend) are already finished blanks (containers), for inserting which it will be enough just to use the desired tag with the necessary attributes and parameters.
Browsers themselves know how to display a particular web form element. True, the display options for the same element in different browsers may differ slightly from each other, but, as a rule, not significantly.
That. it turns out that web forms in Html are an attempt to transfer key elements used in any operating system, to website pages. But why might they be needed on the pages of the site?
In principle, for the same purpose for which similar elements are used in operating systems - the transfer of data from the user. In the case of forms, data from the user is transferred to the server, where it is processed by a special program (hypertext markup language, unfortunately, does not allow data processing).
Although, data can be sent not only to the server, but also, for example, by e-mail to the address specified in the Action attribute of the Form tag. When sending data from Html to E-mail, the user who fills in the fields, after clicking on the send data button, will launch the mail program used on his computer by default.
The opening Form tag should then look something like this:
As you can see, clicking on the text to activate this element is useless - you need to click on it yourself. This is exactly the state of affairs that the Label tag is designed to fix. It allows you to make the text next to the web form element clickable, which is undoubtedly improve usability.
But how to link form Html element and text? To do this, you need to add an ID with a unique parameter to the attribute, and the text must be surrounded by opening and closing Label tags. And that is not all. In the opening Label tag, you need to write the For attribute, the parameter of which must be exactly the same as the ID attribute in the Html tag of the form element. It turns out something like this:
As you can see, now, thanks to the use of Label, web form elements can be activated not only by clicking on it, but also by clicking on the text located next to it.
Fieldset and Legend - splitting the form into parts
You probably often saw that large forms in Html are divided into groups (Fieldset), which are circled in a frame, and each such group has its own header (Legend). This is implemented using just two tags: Fieldset and Legend. They are paired, i.e. they must have an opening and a closing one.
So, to create a group of component parts, you need to enclose all these parts in the opening and closing Fieldset tags. And in order to set a title (Legend) for this group, you need to immediately after the opening Fieldset write a construction from the opening and closing Legend, between which you need to insert the text of the group's title.
Here is an example of creating groups using Fieldset and Legend:
Good luck to you! See you soon on the blog pages site
You may be interested
Select, Option, Textarea, Label, Fieldset, Legend - Html tags of dropdown list form and text field Lists in Html code - UL, OL, LI and DL tags
MailTo - what is it and how to create an email link in Html
How colors are set in Html and CSS code, selection of RGB shades in tables, Yandex results and other programs
What is Html Hypertext Markup Language and how to list all tags in W3C validator
How to insert a link and a picture (photo) into HTML - IMG and A tags
Tables in Html - Table, Tr and Td tags, as well as Colspan, Cellpadding, Cellspacing and Rowspan to create them
Font (Face, Size and Color), Blockquote and Pre tags - deprecated text formatting in pure HTML (without using CSS)
How to create a hyperlink (A, Href, Target blank), how to open it in a new window on the site, and also make an image a link in Html code
Over the past two years, the development of web applications (sites) has moved far ahead and what we used to create a site earlier is already outdated or more recent methods have appeared.
Previously, to create a dropdown list in html ( in English. — dropdown), we just used
Especially for this article, I found 16 different examples that may come in handy during the development of the site. And so let's get started.
1. Custom list
Html template that allows you to customize your own colors on the dropdown list.
2. Made with CSS3/JavaScript
Written in CSS3 and JavaScript. Normal dropdown list.
3. Style: subway stations
Transparent drop-down list with the style of metro stations.
4.Dropy. Written in SCSS & jQuery
5. For long listings
Great solution for long drop down menus.
A dropdown menu that is written in pure CSS without using any scripts.
Great for side menus on the site to visually show the categories on the site.
8. Stylish user settings menu
9. CSS3 Dropdown
Made in UI style, suitable for the UI style of the site.
12. Flag selection
Dropdown in country selection style.
13. Plain HTML, CSS dropdown
I hope you enjoyed my selection. Leave comments, share your opinion and send your own work!
How to make a dropdown list in html (selection of TOP 16) from bologer
Horizontal Dropdown Menu used to organize the site navigation structure. The optimal number of nesting levels is one or two. The fewer levels of attachments, the easier it is for a site visitor to find the information they need. How to create a regular horizontal menu is detailed in .
How to make a horizontal drop down menu
1. HTML markup and basic styles for a dropdown menu with one level of nesting
The HTML markup of a horizontal drop-down menu differs from a regular menu in that it refers to the desired list item
- or<оl> .
To position the submenu relative to the main menu, the following styles are declared:
— for the list element in which the drop-down list is nested: li (position: relative;) ;
- for the dropdown menu ul (position: absolute;) , as well as the left and top values.
For clarity and convenience of formatting, let's add the topmenu class to the main menu, and the submenu class to the drop-down menu.
You can hide the dropdown menu in several ways:
1) display: none;
2) visibility: hidden;
3) opacity: 0;
4) transform: scaleY(0);
5) using the jQuery library.
Method 1. (display: none;)
The dropdown menu is hidden with .submenu (display: none;) , shown on hover with .topmenu li:hover .submenu (display: block;) .
Method 2. (visibility: hidden;)
The menu is hidden with .submenu (visibility: hidden;) , shown with .topmenu li:hover .submenu (visibility: visible;) .
Method 3. (opacity: 0;)
The menu is hidden with .submenu (opacity: 0;) , shown with .topmenu li:hover .submenu (opacity: 1;) . To prevent the menu from appearing when you hover over the area where it is located, add visibility: hidden; , and on hover change to visibility: visible; .
Method 4. (transform: scaleY(0);)
The menu is hidden with .submenu (transform: scaleY(0);) , shown with .topmenu li:hover .submenu (transform: scaleY(1);) . Since the default transformation of an element is from the center, you need to add for .submenu (transform-origin: 0 0;) , i.e. from the top left corner.
Method 5: Using jQuery
$(".five li ul").hide(); // hide dropdown menu $(".five li:has(".submenu")").hover(function()( $(".five li ul").stop().fadeToggle(300);) /* select the list element that contains the element with the .submenu class and add a hover function to it that shows and hides the dropdown menu */);2. 3D drop down menu
Interesting effects can be created using CSS3 transforms, such as making menus appear from the bottom of the screen.
* ( box-sizing: border-box; ) body ( margin: 0; background: radial-gradient(#BFD6E2 1px, rgba(255,255,255,0) 2px); background-size: 10px 10px; ) nav ul ( list-style : none; margin: 0; padding: 0; ) nav a ( display: block; text-decoration: none; outline: none; transition: .4s ease-in-out; ) .topmenu ( backface-visibility: hidden; background : rgba(255,255,255,.8); ) .topmenu > li ( display: inline-block; position: relative; ) .topmenu > li > a ( font-family: "Exo 2", sans-serif; height: 70px; line-height: 70px; padding: 0 30px; font-weight: bold; color: #003559; text-transform: uppercase; ) .down:after ( content: "\f107"; margin-left: 8px; font-family : FontAwesome; ) .topmenu li a:hover ( color: #E6855F; ) .submenu ( background: white; border: 2px solid #003559; position: absolute; left: 0; visibility: hidden; opacity: 0; z-index : 5; width: 150px; transform: perspective(600px) rotateX(-90deg); transform-origin: 0% 0%; transition: .6s ease-in-out; ) .topmenu > li:hover .submenu( visibility: visible; opacity: 1 transform: perspective(600px) rotateX(0deg); ) .submenu li a ( color: #7f7f7f; font-size: 13px; line-height: 36px; padding: 0 25px; font-family: "Kurale", serif; )
3. Expandable dropdown menu with logo
In this example, the top section of the page contains the logo and site navigation. The logo can be an image or text. The dropdown menu gradually expands from below the top list element using the CSS3 transform function.
4. Increasing Dropdown Menu
Another example for a drop down menu. The magnification effect when the menu appears is realized by reducing the initial size.submenu (transform: scale(.8);) , on hover the size increases to.topmenu > li:hover .submenu (transform: scale(1);) .
* ( box-sizing: border-box; ) body ( margin: 0; background: url(https://html5book.ru/wp-content/uploads/2015/10/background54.png) ) nav ( background: white; ) nav ul ( list-style: none; margin: 0; padding: 0; ) nav a ( text-decoration: none; outline: none; display: block; transition: .4s ease-in-out; ) .topmenu ( text-align: center; padding: 10px 0; ) .topmenu > li ( display: inline-block; position: relative; ) .topmenu > li:after ( content: ""; position: absolute; right: 0; width: 1px; height: 12px; background: #d2d2d2; top: 16px; box-shadow: 4px -2px 0 #d2d2d2; transform: rotate(30deg); ) .topmenu > li:last-child:after ( background: none; box -shadow: none; ) .topmenu > li > a ( padding: 12px 26px; color: #767676; text-transform: uppercase; font-weight: bold; letter-spacing: 1px; font-family: "Exo 2", sans-serif; ) .topmenu li a:hover ( color: #c0a97a; ) .submenu ( position: absolute; left: 50%; top: 100%; width: 210px; margin-left: -105px; background: #fafafa ; border: 1px solid #ededed; z-index: 5; visibility: hidden; opacity: 0 transform:scale(.8); transition: .4s ease-in-out; ) .submenu li a ( padding: 10px 0; margin: 0 10px; border-bottom: 1px solid #efefef; font-size: 12px; color: #484848; font-family: "Kurale", serif; ) .topmenu > li:hover .submenu ( visibility: visible; opacity: 1; transform: scale(1); )
5. Pull-down menu
Horizontal menu with mini-animation: hovering over top menu links will show a small circle that also accompanies the appearance of the drop-down menu.
@import url("https://fonts.googleapis.com/css?.jpg); background-position: center center; background-repeat: no-repeat; background-size: cover; height: 100vh; position: relative; ) body:before ( content: ""; position: absolute; left: 0; bottom: 0; height: 100%; width: 100%; background: linear-gradient(45deg, rgba(0,0,0,0) , rgba(255,255,255,.8)); ) nav ( text-align: center; padding: 40px 0 0; ) nav ul ( list-style: none; margin: 0; padding: 0; ) nav a ( text-decoration : none; display: block; color: #222; ) .topmenu > li ( display: inline-block; position: relative; ) .topmenu > li > a ( position: relative; padding: 10px 15px; font-family: " Kaushan Script", cursive; font-size: 1.5em; line-height: 1; letter-spacing: 3px; ) .topmenu > li > a:before ( content: ""; position: absolute; z-index: 5; left: 50%; top: 100%; width: 10px; height: 10px; background: white; border-radius: 50%; transform: translate(-50%, 20px); opacity: 0; transition: .3s; ) .topmenu li:hover a:before ( transform: translate(-50%, 0); opacity: 1 ) .submenu ( position: absolute; z-index: 4; left: 50%; top: 100%; width: 150px; padding: 15px 0 15px; margin-top: 5px; background: white; border-radius: 5px; box-shadow: 0 0 30px rgba(0,0,0,.2); box-sizing: border-box; visibility: hidden; opacity: 0; transform: translate(-50%, 20px); transition: .3s ; ) .topmenu > li:hover .submenu ( visibility: visible; opacity: 1; transform: translate(-50%, 0); ) .submenu a ( font-family: "Libre Baskerville", serif; font-size: 11px; letter-spacing: 1px; padding: 5px 10px; transition: .3s linear; ) .submenu a:hover (background: #e8e8e8;)
In this article, we will consider elements that allow you to create drop-down lists, learn how to form groups in these lists, consider how to disable items and even groups of lists, get acquainted with an element that allows you to create a multi-line text field, you can use it later inside HTML forms (element
In addition, we placed a button inside the form, which serves to submit the form (element with button type "submit form": type = "submit" ).
The result of our example:
Text area tooltip
And so we will consider the final example and move on to the practical task of the article in this tutorial.
Thanks to the attribute (HTML tag
The tooltip text is hidden when the user enters a value (any character) into the text field, if it is removed, the tooltip will be displayed again.
Let's consider an example of use:
type = "submit" name = "submitInfo" value = "submit" > !}
In this example, we have created two text areas (element
Note that if the text field is read-only, then the content cannot be changed, but the user can still navigate to the content, select it, and copy it.
In addition, we placed a button inside the form, which serves to submit the form (element with button type "submit form": type = "submit" ).
The result of our example:
Questions and tasks on the topic
Before moving on to the next topic, complete the practical task:
- Using the knowledge gained, compose the following form for posting a vacancy:
Before proceeding with the task, open the example in a new window and carefully examine the form in order to repeat all its points. To complete the task, you will need knowledge from the article. If you missed it, then come back to study it.
After you complete the exercise, inspect the page code by opening the example in a separate window to make sure you did everything correctly.
Today I want to present a small "recipe" for creating a list in CSS. No jQuery, no CSS3 - just good old, cross-browser CSS. The example is quite simple, so experienced comrades may not be interested. We will implement a drop-down list with social buttons.
So, let's not talk for a long time, let's get straight to the point
HTML
Share this post
- Google Plus
- In contact with
- RSS
I deliberately omit general points, such as including styles, so that the code does not grow. At the bottom of the page I will give a link to the source code - everything is there.
What we have in HTML is a regular list and an unusual heading. Its unusualness is that it is made by a hyperlink, which allows you to track the event :hover, that is, guidance. The dropdown list will work when hovering over the heading.
css
First, let's look at the basic styles of the dropdown list. I tried to comment every line of code to make it clearer:
/*Reset padding*/ .droplink ul,.droplink h3,.droplink h3 a( padding:0;margin:0 ) /*Basic wrapper*/ .droplink ( width:200px; position:absolute; margin:10px 0 0 25px ) /*Block style on hover*/ .droplink:hover( height:auto; background-color:#3E403D; border:solid 1px #3A3C39 ) /*Title in normal state*/ .droplink h3 a( text-align:center ;width:100%;display:block;padding:12px 0px;color:#999;text-decoration:none ) a ( color:#FFF; font-weight:bold; position:absolute )
There is nothing special here, we indicated the size and style of the block, the style of the heading, and for both elements - their styles when hovering over. Go ahead:
/*Hide the list without hover*/ .droplink ul( list-style:none; display:none ) /*Display the list on hover*/ .droplink:hover ul( display:block; margin-top:40px ) .droplink li( display:block)
This code is already more interesting and shows how it behaves drop-down list when hovering over. Worth it in normal condition display: none i.e. it is not displayed. On hover, we show it as a block. That's the whole secret. Now let's decorate the list elements a bit and insert icons:
/*List item style*/ .droplink li a( padding:5px 12px 4px 34px; margin:1px; background-color:#484A47; display:block; color:#FFF; text-decoration:none; font-size:12px ; background-repeat:no-repeat; background-position: 10px 3px ) /*Element style on hover*/ .droplink li a:hover( background-color:#999 ) /*Icons*/ .facebook a (background-image :url("icons/facebook.png")) .twitter a (background-image:url("icons/twitter.png")) .vk a (background-image:url("icons/vk.png")) .rss a (background-image:url("icons/rss.png")) .gplus a (background-image:url("icons/gplus.png"))
That, in fact, is all. The dropdown list is ready and looks nice enough. You can arrange the elements at your discretion, add rounded corners and other "gadgets".
If you want the list to “overlap” the text below it on hover, look away z-index.
If something is not clear or does not work, ask in the comments or use the "Send message" button, it's there —>