calc() Function - HTML CSS CSS

HTML CSS examples for CSS:Function

Definition and Usage

The calc() function does calculation on the property value.

CSS Syntax

Value Require Description
expression Required. A mathematical expression. The operators can be used: + - * /

The following code shows how to Use calc() to calculate the width of a <div> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#div1 {<!--   w  ww.  ja  v a2s . c  o  m-->
    position: absolute;
    left: 50px;
    width: calc(100% - 100px);
    border: 1px solid black;
    background-color: red;
    padding: 5px;
    text-align: center;
}
</style>
</head>
<body>

<div id="div1">Some text...</div>

</body>
</html>

Related Tutorials