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

The difference between GB2312, GBK and UTF-8 in web page encoding

First of all, we need to understand that GB2312, ...

Detailed analysis of matching rules when Nginx processes requests

When nginx receives a request, it will first matc...

How to install ionCube extension using pagoda

1. First install the pagoda Installation requirem...

Summarize the common application problems of XHTML code

Over a period of time, I found that many people d...

What can I use to save you, my table (Haiyu Blog)

Tables once played a very important role in web p...

Implementation of CSS sticky footer classic layout

What is a sticky footer layout? Our common web pa...

Specific use of Mysql prepare preprocessing

Table of contents 1. Preprocessing 2. Pretreatmen...

jQuery plugin to implement stacked menu

A jQuery plugin every day - stacked menu, for you...

Detailed explanation of MySql data type tutorial examples

Table of contents 1. Brief Overview 2. Detailed e...

How to use CSS attribute value regular matching selector (tips)

There are three types of attribute value regular ...

Detailed explanation of Linux CPU load and CPU utilization

CPU Load and CPU Utilization Both of these can re...

translate(-50%,-50%) in CSS achieves horizontal and vertical centering effect

translate(-50%,-50%) attributes: Move it up and l...

A brief discussion on ifnull() function similar to nvl() function in MySQL

IFNULL(expr1,expr2) If expr1 is not NULL, IFNULL(...

npm Taobao mirror modification explanation

1. Top-level usage 1. Install cnpm npm i -g cnpm ...