When it comes to I first learned about these two tags when I was learning reset.css or normalize.css in my early years. I saw them in the CSS that reset the default style of the unified code. Recently, I encountered these two tags while studying borders, and found them very interesting, so I wrote an article to share some knowledge points with you. Understanding Generally speaking,
In short, fieldset can be used alone to group form elements, while Let's take a look at a simple example. The simple HTML and structure are as follows: <fieldset> <legend>Form</legend> <div> <label>Name :</label><input type="text" placeholder="input Name" /> </div> <div> <label>Password :</label><input type="text" placeholder="input Name" /> </div> </fieldset> fieldset { border: 1px solid#ddd; padding: 12px; } legend font-size: 18px; padding: 0 10px; } The effect is as follows: CodePen Demo -- fieldset & legend Demo The interesting point is that if Control the position and style of The position and style of For the position, we can control it through fieldset { border: 1px solid#ddd; // padding: 12px; } legend font-size: 18px; } Effect picture: By changing fieldset { border: 1px groove #ddd; } legend animation: marginMove 10s infinite alternate; } @keyframes marginMove { 100% { margin-left: 100px; } } Effect picture: By controlling Application scenario - horizontal lines on both sides of the title After understanding the above basic knowledge, we can start to go a little deeper and think about some interesting application scenarios of the above I think the most suitable scenario is the layout with horizontal lines on both sides of the title. Something like this: Of course, there are many ways to solve this layout. Usually, pseudo-elements are used to generate horizontal lines on the left and right sides, or they are covered and superimposed locally through absolute positioning. Here, this is done very quickly using <div class="g-container"> <fieldset><legend>Ranking</legend></fieldset> </div> fieldset { width: 300px; height: 24px; border: 1px solid transparent; border-top-color: #000; } legend margin: auto; padding: 0 10px; } CodePen Demo -- fieldset & legend Demo 2 Border nested text In this article, How to Add Text in Borders Using Basic HTML Elements, a very interesting usage scenario is also introduced, which is to nest text in borders. Imagine that a The pseudo code is as follows: <div class="g-container"> <fieldset><legend>CSS fieldset</legend></fieldset> <fieldset><legend>HTML element</legend></fieldset> <fieldset><legend>JavaScript</legend></fieldset> <fieldset><legend>TypeScript</legend></fieldset> </div> .g-container { position: relative; width: 300px; height: 300px; } fieldset{ position: absolute; width: 300px; height: 300px; border: 10px solid transparent; border-top-color: #000; } legend padding: 0 10px; } fieldset:nth-of-type(2){ transform: rotate(90deg); } fieldset:nth-of-type(3){ transform: rotate(180deg); } fieldset:nth-of-type(3)>legend{ transform: rotate(180deg); } fieldset:nth-of-type(4){ transform: rotate(-90deg); } The effect diagram is as follows: By combining multiple By adding legend animation: move 3s infinite linear alternate; } @keyframes move { 100% { margin-left: 70px; } } CodePen Demo -- Border Text Design using HTML fieldset and legend Okay, based on this, we can generate various N-sided borders with embedded text. Here is a simple attempt at several polygon borders. CodePen Demo -- fieldset and legend generate polygon This is the end of this article about the detailed usage of the uncommon tags fieldset and legend. For more related fieldset and legend tag content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! |
<<: Two ways to implement HTML page click download file
>>: 3 functions of toString method in js
Table of contents From father to son: Son to Fath...
First, let's take a look at my basic developm...
If your DOCTYPE is as follows: Copy code The code ...
Whether you're trying to salvage data from a ...
Preface In the process of writing code, we will i...
Table of contents Review of Vue2 responsive princ...
Apache Superset is a powerful BI tool that provid...
In Vue, we generally have front-end and back-end ...
This article shares the specific code of the firs...
Joint Index The definition of the joint index in ...
Table of contents 1. What is an event? 2. Enable ...
This script can satisfy the operations of startin...
Use JS timer to make an element to make a method ...
1. Download 1. Download the installation package ...
Enough of small talk <br />Based on the lar...