Easily get started with the CSS framework and easily create beautiful web pages, specific code examples are required
With the continuous development of the Internet, web design has become an important field. The emergence of the CSS (Cascading Style Sheets) framework has greatly simplified the process of web design, allowing ordinary users to easily create beautiful web pages. In this article, we will introduce some commonly used CSS frameworks and provide specific code examples to help readers get started quickly.
1. Bootstrap framework
Bootstrap is one of the most popular CSS frameworks at present. It has rich styles and components, responsive design, and extensive support and documentation. Below is a code example of a simple web page built using the Bootstrap framework.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>My Bootstrap Website</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css"> </head> <body> <header class="bg-primary text-white text-center py-5"> <h1>Welcome to My Website</h1> </header> <div class="container mt-5"> <h2>About Me</h2> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nihil sequi numquam rerum repellat? Fugit, ut?</p> </div> <div class="container mt-5"> <h2>Contact Me</h2> <form> <div class="mb-3"> <label for="name" class="form-label">Your Name</label> <input type="text" class="form-control" id="name"> </div> <div class="mb-3"> <label for="email" class="form-label">Your Email</label> <input type="email" class="form-control" id="email"> </div> <div class="mb-3"> <label for="subject" class="form-label">Subject</label> <input type="text" class="form-control" id="subject"> </div> <div class="mb-3"> <label for="message" class="form-label">Message</label> <textarea class="form-control" id="message" rows="5"></textarea> </div> <button type="submit" class="btn btn-primary">Submit</button> </form> </div> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/js/bootstrap.bundle.min.js"></script> </body> </html>
In the above code, we introduced the CSS and JavaScript files of the Bootstrap framework by referencing the CDN link. Then use the classes provided by Bootstrap to define styles and layouts. For example, we use the container
class to create a container, and use mt-5
to set the top and bottom margins. At the same time, we also use the bg-primary
and text-white
classes to set the background color and text color of the head.
2. Semantic UI Framework
Semantic UI is another popular CSS framework that focuses on semantic design and provides a wealth of themes and customization options. Below is a code example of a simple web page built using the Semantic UI framework.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>My Semantic UI Website</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css"> </head> <body> <header class="ui inverted vertical center aligned segment"> <h1>Welcome to My Website</h1> </header> <div class="ui container segment"> <h2>About Me</h2> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nihil sequi numquam rerum repellat? Fugit, ut?</p> </div> <div class="ui container segment"> <h2>Contact Me</h2> <form class="ui form"> <div class="field"> <label for="name">Your Name</label> <input type="text" id="name"> </div> <div class="field"> <label for="email">Your Email</label> <input type="email" id="email"> </div> <div class="field"> <label for="subject">Subject</label> <input type="text" id="subject"> </div> <div class="field"> <label for="message">Message</label> <textarea id="message" rows="5"></textarea> </div> <button class="ui primary button" type="submit">Submit</button> </form> </div> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.js"></script> </body> </html>
In the above code, we introduced the CSS and JavaScript files of the Semantic UI framework by referencing the CDN link. Then use the classes provided by Semantic UI to define styles and layouts. For example, we use the classes inverted
, vertical
, center aligned
to implement the style of the head.
3. Bulma Framework
Bulma is a lightweight CSS framework that provides a simple and flexible web design solution. Below is a code example of a simple web page built using the Bulma framework.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>My Bulma Website</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.9.3/css/bulma.min.css"> </head> <body> <header class="hero is-primary is-bold"> <h1 class="title has-text-centered">Welcome to My Website</h1> </header> <section class="section"> <div class="container"> <h2 class="title">About Me</h2> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nihil sequi numquam rerum repellat? Fugit, ut?</p> </div> </section> <section class="section"> <div class="container"> <h2 class="title">Contact Me</h2> <form> <div class="field"> <label class="label" for="name">Your Name</label> <div class="control"> <input class="input" type="text" id="name"> </div> </div> <div class="field"> <label class="label" for="email">Your Email</label> <div class="control"> <input class="input" type="email" id="email"> </div> </div> <div class="field"> <label class="label" for="subject">Subject</label> <div class="control"> <input class="input" type="text" id="subject"> </div> </div> <div class="field"> <label class="label" for="message">Message</label> <div class="control"> <textarea class="textarea" id="message" rows="5"></textarea> </div> </div> <div class="field"> <div class="control"> <button class="button is-primary" type="submit">Submit</button> </div> </div> </form> </div> </section> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.9.3/js/bulma.min.js"></script> </body> </html>
In the above code, we introduced the CSS and JavaScript files of the Bulma framework by referencing the CDN link. Then use the classes provided by Bulma to define styles and layouts. For example, we use the classes hero
, is-primary
, is-bold
to implement the style of the head.
Summary
The above is a brief introduction to three commonly used CSS frameworks, and provides specific code examples. By using these frameworks, you can create beautiful web pages quickly and easily. However, as a beginner, you should not rely too much on the framework at the beginning, but should gradually learn CSS native syntax and layout skills in order to better understand and master the essence of web design. I hope this article is helpful to your learning, and I wish you success in your web design journey!
The above is the detailed content of Simply master the CSS framework and quickly create beautiful web pages. For more information, please follow other related articles on the PHP Chinese website!