search
HomeWeb Front-endCSS TutorialComparison of usage of CSS frameworks and typography techniques

Comparison of usage of CSS frameworks and typography techniques

CSS framework is often used to speed up the development of web pages and improve development efficiency. However, their usage is different from traditional CSS typesetting, and we need to study it carefully. This article will explain the different usage methods and techniques of CSS framework and traditional CSS typesetting, and attach specific code examples.

Basic concept of CSS framework
CSS framework is a collection of encapsulated CSS codes, which is designed to help developers quickly establish the skeleton or layout of a website, thereby shortening development time. Mainly including layout, typesetting, responsive design, interactive effects, etc. Common CSS frameworks include Bootstrap, Foundation, Semantic UI, etc. These frameworks provide a set of default styles, which can be modified or overridden to achieve personalized design.

Advantages and Disadvantages of CSS Framework
The advantage of CSS framework is to improve development efficiency, reduce duplication of labor, and enable developers to focus more on the functionality and interaction design of the website. In addition, CSS frameworks generally include responsive design functions, which can achieve cross-device adaptation. Moreover, since these frameworks have been extensively tested and used, their compatibility and reliability are guaranteed.

The disadvantage is that the framework may cause the style of the website to become more ordinary or uniform. If all websites used the same framework, they would lose their individuality and differentiation. In addition, the development of frameworks is often relatively rapid. If not followed up in time, it will lead to obsolete code and huge update costs.

How to use the CSS framework
The way to use the CSS framework is usually to import some CSS files and then use the classes in them to implement the style of the website. For example, using the Bootstrap framework, you can import files as follows:

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/%20bootstrap.min.css">

Then, reference the corresponding class in HTML to implement the style. For example, to implement a page with a navigation bar and carousel, you can use the following code:

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Brand</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <div class="collapse navbar-collapse" id="navbarNav">
    <ul class="navbar-nav">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Features</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Pricing</a>
      </li>
      <li class="nav-item">
        <a class="nav-link disabled" href="#">Disabled</a>
      </li>
    </ul>
  </div>
</nav>

<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
  <ol class="carousel-indicators">
    <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
    <li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
    <li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
  </ol>
  <div class="carousel-inner">
    <div class="carousel-item active">
      <img class="d-block w-100 lazy"  src="/static/imghwm/default1.png"  data-src="https://via.placeholder.com/800x400?text=Slider%201?x-oss-process=image/resize,p_40"  alt="First slide">
    </div>
    <div class="carousel-item">
      <img class="d-block w-100 lazy"  src="/static/imghwm/default1.png"  data-src="https://via.placeholder.com/800x400?text=Slider%202?x-oss-process=image/resize,p_40"  alt="Second slide">
    </div>
    <div class="carousel-item">
      <img class="d-block w-100 lazy"  src="/static/imghwm/default1.png"  data-src="https://via.placeholder.com/800x400?text=Slider%203?x-oss-process=image/resize,p_40"  alt="Third slide">
    </div>
  </div>
  <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
    <span class="carousel-control-prev-icon" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
    <span class="carousel-control-next-icon" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>

In the above code, a navigation bar is first defined and the navbar class provided by Bootstrap is used; then it is defined I created a carousel chart and used the carousel class and some related classes provided by Bootstrap to implement the layout and style of the carousel chart. These classes are all predefined.

Tips of CSS framework
Tips of CSS framework include flexible use of classes, overriding default styles, and achieving personalized design through custom classes.

  1. Flexible use of classes
    CSS framework usually defines a large number of CSS classes, and we can select and use these classes according to our needs. The classes of CSS framework are usually divided according to functions or components, such as buttons, navigation bars, carousels, tables, etc. We can quickly build the layout and style of the website by using these classes.
  2. Override the default style
    The default style of the CSS framework may not be suitable for our website, or it may require personalized design. If we encounter this situation, we can use custom CSS rules to override the default styles. It should be noted that overriding the default style may cause problems with the layout and style of the website, so it needs to be used with caution. You can use your browser's developer tools to inspect an element's style properties to determine which CSS properties and values ​​need to be overridden.

For example, if you need to modify the background color and font color of the Bootstrap navigation bar, you can use the following CSS rules:

.navbar {
    background-color: #333;
    color: white;
}

Here the navbar class is used to select the navigation bar, and the background is modified -color attribute and the value of the color attribute.

  1. Personalized design through custom classes
    Although there are many classes in the CSS framework, they may not fully meet our design needs. At this time, we need to use custom classes to achieve personalization. design. You can define your own classes in CSS files and then use these classes in HTML to implement your design needs. It should be noted that before using custom classes, you need to understand the layout and style rules of the classes provided by the CSS framework to avoid conflicts between custom classes and the framework's classes, which may cause style failure or problems.

The following is an example of using a custom class to implement styles:

.custom-text {
    font-size: 24px;
    font-weight: bold;
    color: #FF5733;
}

A custom class .custom-text is defined here to implement some font styles. Then use this class in HTML:

<p class="custom-text">这是自定义的文字样式。</p>

This code will make this text use a custom style.

Summary
The CSS framework is a tool that improves development efficiency and can help developers quickly build the layout and style of a website. However, when using CSS frameworks, you need to pay attention to how they are used differently from traditional CSS layout. You must flexibly use the framework's classes, reasonably override the default styles, and use custom classes to achieve personalized design. Only by mastering these skills can you effectively use the CSS framework and continuously improve development efficiency and website quality.

The above is the detailed content of Comparison of usage of CSS frameworks and typography techniques. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
CSS Flexbox vs Grid: a comprehensive reviewCSS Flexbox vs Grid: a comprehensive reviewMay 12, 2025 am 12:01 AM

Choosing Flexbox or Grid depends on the layout requirements: 1) Flexbox is suitable for one-dimensional layouts, such as navigation bar; 2) Grid is suitable for two-dimensional layouts, such as magazine layouts. The two can be used in the project to improve the layout effect.

How to Include CSS Files: Methods and Best PracticesHow to Include CSS Files: Methods and Best PracticesMay 11, 2025 am 12:02 AM

The best way to include CSS files is to use tags to introduce external CSS files in the HTML part. 1. Use tags to introduce external CSS files, such as. 2. For small adjustments, inline CSS can be used, but should be used with caution. 3. Large projects can use CSS preprocessors such as Sass or Less to import other CSS files through @import. 4. For performance, CSS files should be merged and CDN should be used, and compressed using tools such as CSSNano.

Flexbox vs Grid: should I learn them both?Flexbox vs Grid: should I learn them both?May 10, 2025 am 12:01 AM

Yes,youshouldlearnbothFlexboxandGrid.1)Flexboxisidealforone-dimensional,flexiblelayoutslikenavigationmenus.2)Gridexcelsintwo-dimensional,complexdesignssuchasmagazinelayouts.3)Combiningbothenhanceslayoutflexibilityandresponsiveness,allowingforstructur

Orbital Mechanics (or How I Optimized a CSS Keyframes Animation)Orbital Mechanics (or How I Optimized a CSS Keyframes Animation)May 09, 2025 am 09:57 AM

What does it look like to refactor your own code? John Rhea picks apart an old CSS animation he wrote and walks through the thought process of optimizing it.

CSS Animations: Is it hard to create them?CSS Animations: Is it hard to create them?May 09, 2025 am 12:03 AM

CSSanimationsarenotinherentlyhardbutrequirepracticeandunderstandingofCSSpropertiesandtimingfunctions.1)Startwithsimpleanimationslikescalingabuttononhoverusingkeyframes.2)Useeasingfunctionslikecubic-bezierfornaturaleffects,suchasabounceanimation.3)For

@keyframes CSS: The most used tricks@keyframes CSS: The most used tricksMay 08, 2025 am 12:13 AM

@keyframesispopularduetoitsversatilityandpowerincreatingsmoothCSSanimations.Keytricksinclude:1)Definingsmoothtransitionsbetweenstates,2)Animatingmultiplepropertiessimultaneously,3)Usingvendorprefixesforbrowsercompatibility,4)CombiningwithJavaScriptfo

CSS Counters: A Comprehensive Guide to Automatic NumberingCSS Counters: A Comprehensive Guide to Automatic NumberingMay 07, 2025 pm 03:45 PM

CSSCountersareusedtomanageautomaticnumberinginwebdesigns.1)Theycanbeusedfortablesofcontents,listitems,andcustomnumbering.2)Advancedusesincludenestednumberingsystems.3)Challengesincludebrowsercompatibilityandperformanceissues.4)Creativeusesinvolvecust

Modern Scroll Shadows Using Scroll-Driven AnimationsModern Scroll Shadows Using Scroll-Driven AnimationsMay 07, 2025 am 10:34 AM

Using scroll shadows, especially for mobile devices, is a subtle bit of UX that Chris has covered before. Geoff covered a newer approach that uses the animation-timeline property. Here’s yet another way.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools