Questions tagged [css-calc]

calc() is a native CSS way to do simple math right in CSS as a replacement for any length value (or pretty much any number value). It has four simple math operators: add (+), subtract (-), multiply (*), and divide (/).

The calc() CSS function can be used anywhere a <length>, <frequency>, <angle>, <time>, <number>, or <integer> is required. With calc(), you can perform calculations to determine CSS property values.

It is possible to nest calc() function, the internal ones being considered as simple parenthesis ().

Syntax

/* property: calc(expression) */
width: calc(100% - 100px);

Expressions

The expression can be any simple expression combining the following operators, using standard operator precedence rules:

+ Addition.

- Subtraction.

* Multiplication. At least one of the arguments must be a <number>.

/ Division. The right-hand side must be a <number>.

The operands in the expression may be any length syntax value. You can use different units for each value in your expression, if you wish. You may also use parentheses to establish computation order when needed.

You can see a couple of use cases for calc()

214 questions
0
votes
0 answers

CSS Calc: Vertically centering a positioned element per browser width

I have an absolutely positioned background video that's been "cropped" - meaning the top and bottom 20% or so is hidden. Here's a link to what I've built (hero area): http://pchapman-sandbox.dev.vuforia.com/vuforia-landing/ In the center of this…
0
votes
0 answers

Performance of changing css vars on scroll that affect many svgs

On a recent project, I took Dave Rupert's Cheapass Parallax idea (Demo) and ran with it. I have several chucks of svg shapes (23 relatively simple shapes, all inline svg) down the right side of the page which all scroll at different speeds, creating…
willfalcon
  • 1
  • 1
  • 5
0
votes
2 answers

Sass calc decleration dropped Chrome

I am writing a simple grid layout using Sass. I am trying to use calc() to determine the width in relative units %. To test the styles, I am using a simple HTML file. Problem: Inspecting the results with dev tools on Chrome, it shows that the width…
Abrar Hossain
  • 2,594
  • 8
  • 29
  • 54
0
votes
1 answer

Set a div's height to be equal to calculated width

This is my code (explanation after): https://jsfiddle.net/L7a35dda/1/ body { width: 1920px; height: 1080px; background-color: rgb(48, 48, 48); margin: 0; padding: 0; display: flex; flex-direction: column; flex-wrap:…
thegreatjedi
  • 2,788
  • 4
  • 28
  • 49
0
votes
1 answer

Setting input width with calc does not work as expected

I have an input with width: calc(100% - 100px); without padding/margin/border. I want to put a div beside it with position : inline-block; and width : 100px;. The div goes to the next line but I cannot find any reason for it. If I reduce the div…
Arashsoft
  • 2,749
  • 5
  • 35
  • 58
0
votes
0 answers

Responsive Font Size Calc() Bug

I'm trying to scale my font-size between 0.875rem and 1.3rem for media widths 20rem to 40rem using the following css which works fine in Firefox and Chrome but not Safari where the calc() returns a value that is too big. Any ideas how to make it…
Andreas Larsen
  • 101
  • 3
  • 10
0
votes
1 answer

CSS calc percentage width and division

I have menu which is a list with three list-items: The width of the ul element changes as you resize the browser and I'm…
Jim
  • 1,333
  • 1
  • 11
  • 15
0
votes
2 answers

Css calc() behavior in IE

My purpose is to put inner div in the middle of container. The example in fiddle: The main problem is that inner div is shifted right in IE (Firefox and Chrome shows it fine) because of using css calc() rule. If I uncomment constant width in…
user1820686
  • 2,008
  • 5
  • 25
  • 44
0
votes
4 answers

Correct CSS for Two (Left & Mid) Column Fixed Width Left and Right Column Fluid

I am working on a 3 column divs. The Left and Mid columns have fixed widths (57px and 160px respectively) inside the wrapper with a width of 1005px. the problem is the right column which SHOULD be fluid width and will cover all the remaining space.…
user4491046
0
votes
1 answer

Div spacing offset using calc()

I have 3 vertical rows which are divided on my screen using calc() I'm using JS to set the height for each box type width: calc(1/3 * 100%); This is the javascript to set the height of each block, It's setting the height equal to the width and in…
Miguel Stevens
  • 8,631
  • 18
  • 66
  • 125
0
votes
1 answer

Max-height, with Calc vh in Safari

For Safari the following is not working, can anyone pinpoint in what I'm doing wrong? max-height: calc(80vh - 140px); All methods are individually supported on Safari. -webkit-calc doesn't help either. Thanks!
Maurice Kroon
  • 959
  • 4
  • 13
  • 29
0
votes
1 answer

CSS Calc((100%/5)+10px) isn't working

Alright so in my CSS I'm trying to do the math calc((100%/5)+10px); When I do this It doesn't work. When I do calc(100%/5); It works just fine. What do I need to do to get the +10px working?
user2892875
  • 99
  • 1
  • 1
  • 9
0
votes
1 answer

calc() in Safari for left

I center a div within another one by using calc() function. It works fine in Chrome, Firefox, Opera and even in IE but in Safari this method doesn't work. Any suggestions without a javascript fixation? left: -webkit-calc(50% - 25px); left:…
tolga
  • 2,462
  • 4
  • 31
  • 57
0
votes
2 answers

Using calc() during calculate height

I programming very simple layout. It consist 5 div -> http://jsfiddle.net/8tSk6/ . I want that div with ID "kubka" equal 100% - 100px (height: calc(100% - 100px);). Unfortunately, it doesn't work. I try apply tips with CSS3 height: calc(100%) not…
jaksa
  • 853
  • 2
  • 7
  • 10
0
votes
1 answer

what does this css do: ~"-moz-calc(..)"

I just noticed a css rule that looked like this width: ~"-moz-calc(100% - 10px)"; Now I know -moz-calc, but why is this a string and what is the meaning of the '~'?
Jeanluca Scaljeri
  • 26,343
  • 56
  • 205
  • 333
1 2 3
14
15