An example of the calculation function calc in CSS in website layout

An example of the calculation function calc in CSS in website layout

calc is a function in CSS that is used to calculate numerical values. It can calculate length, angle, time, etc. Supports + , - , * , / and parentheses. One thing to note when using it is that there needs to be a space before and after the plus sign and minus sign . calc greatly increases the flexibility of CSS. Provides convenience for some special layouts.

The effect of the example display

An example using the cacl layout

I want to create an effect where the background of #div1 extends to the visible area of #div2 , and displays a fixed 60 pixels in #div2 . That is, the black frame width is 60px. Regardless of the width of #div1 .

CSS Code

#div1 {
    width: 100%;
    min-width: 400px;
    outline: blue;
}
#div2 {
    width: 300px;
    margin: 0 auto;
    outline: 1px solid #ccc;
    color: white;
}

HTML code

<div id="div1" class="cw">
    <div id="div2">
        test
    </div>
</div>

Solution

.cw {
    background:blue linear-gradient(
    to right, red calc(50% - 150px + 60px ) ,
    transparent calc(50% - 150px + 60px )
    );
}

cacl compatibility

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

<<:  Detailed explanation of encoding issues during MySQL command line operations

>>:  Parameters to make iframe transparent

Recommend

Detailed explanation of nginx optimization in high concurrency scenarios

In daily operation and maintenance work, nginx se...

JavaScript to achieve progress bar effect

This article example shares the specific code of ...

Detailed explanation of the implementation of shared modules in Angular projects

Table of contents 1. Shared CommonModule 2. Share...

Analyze how a SQL query statement is executed in MySQL

Table of contents 1. Overview of MySQL Logical Ar...

WeChat Mini Programs are shared globally via uni-app

In actual use, it is often necessary to share the...

How to Completely Clean Your Docker Data

Table of contents Prune regularly Mirror Eviction...

Introduction to JWT Verification Using Nginx and Lua

Table of contents Preface Lua Script nignx.conf c...

MySQL 5.7 cluster configuration steps

Table of contents 1. Modify the my.cnf file of se...

Detailed explanation of two quick ways to write console.log in vscode

(I) Method 1: Define it in advance directly in th...

CSS3 realizes bouncing ball animation

I usually like to visit the special pages or prod...

CSS: visited pseudo-class selector secret memories

Yesterday I wanted to use a:visited to change the...

Linux kernel device driver address mapping notes

#include <asm/io.h> #define ioremap(cookie,...

Analysis of common usage examples of MySQL process functions

This article uses examples to illustrate the comm...

Some notes on mysql create routine permissions

1. If the user has the create routine permission,...

Detailed explanation of mysql replication tool based on python

Table of contents 1. Introduction Second practice...