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

Ubuntu Basic Tutorial: apt-get Command

Preface The apt-get command is a package manageme...

Detailed explanation of pid and socket in MySQL

Table of contents 1. Introduction to pid-file 2.S...

Understand the use of CSS3's all attribute

1. Compatibility As shown below: The compatibilit...

JavaScript implements random generation of verification code and verification

This article shares the specific code of JavaScri...

Quick solution for forgetting MySQL8 password

Preface When we forget the MySQL database passwor...

Solution to uninstalling Python and yum in CentOs system

Background of the accident: A few days ago, due t...

Detailed steps to use Redis in Docker

1. Introduction This article will show you how to...

Getting Started with Mysql--sql execution process

Table of contents 1. Process 2. Core Architecture...

How to use border-image to implement text bubble border sample code

During the development activity, I encountered a ...

How to solve the problem that Seata cannot use MySQL 8 version

Possible reasons: The main reason why Seata does ...

Pitfalls based on MySQL default sorting rules

The default varchar type in MySQL is case insensi...

MySQL query tree structure method

Table of contents MySQL query tree structure 1. A...

Steps to build MHA architecture deployment in MySQL

Table of contents MAH 1. Introduction to MAH Arch...