css-calc

How to use calc() inside another function

守給你的承諾、 提交于 2019-12-05 12:25:48
问题 Is it possible to use calc() inside of a CSS function like transform or translate ? I cannot seem to get it working. Here is a demo so you guys can play around: http://jsfiddle.net/qdJwY/1/ 回答1: You can use calc() wherever you can use a length based value in CSS. The example you have provided does work, but actually adds up to 0. Here is a slightly changed demo to illustrate: http://jsfiddle.net/joshnh/6ydR3/ Also, make sure to list the unprefixed version last. Mixing percentages with other

Can i use Calc inside Transform:Scale function in CSS?

╄→尐↘猪︶ㄣ 提交于 2019-12-05 10:26:01
I'm trying to calculate the right scale to apply to children inside a parent but i can't use calc() inside transform: scale CSS function. I've done this function with javascript but i'm interested in a pure CSS solution to avoid bloating the page with scripts as much as possible. Example: CSS .anyclass{ height:250px; /*this value can change dinamically */ transform:scale(calc(100% / 490 )); /*is using height value*/ } This definition gives back an invalid property value. Other uses like translate: .anyclass{ transform:translate(calc(100% - 50px )); } works with no problem. Is there anyway i

What Is Result Of calc() In CSS

匆匆过客 提交于 2019-12-05 05:14:41
We have now started using calc() in css, for setting widths on a result of calculation. For example: <div id='parent'> <div id='calcWidth'></div> </div> #parent{ width:100px; } #calcWidth{ width:calc(100% - 3px); height:100px; background:red; } I know how calc() works, but I just want to know what is returned in css, in the place of calc(100% - 3px); in the example given above. Whats my confusion? In the above example width:calc(100% - 3px); say the 100% width is actually 100px , which will be determined at runtime by css. So the calculated width will be 100px-3px=97px 97px and if you convert

Use css calc() in jquery

纵饮孤独 提交于 2019-12-05 00:16:19
How can I do this? $('#element').animate({ "width": "calc(100% - 278px)" }, 800); $('#element').animate({ "width": "calc(100% - 78px)" }, 800); I can do it if it's only % or only px , but not calc() , can I use some other option of jQuery? or some other trick of JavaScript? It's a change that have to be done when the user clicks some element, so: $("#otherElement").on("click", FunctionToToggle); when the user clicks the $("#otherElement") the toggle effect has to occur. maybe this helps: $('#element').animate({ "width": "-=278px" }, 800); every time this script will remove 278px from the

CSS calc with inherit

ぃ、小莉子 提交于 2019-12-04 23:44:23
I would like to use inherit with calc() like this: #foo { animation-duration: 10s; } #foo > .bar { animation-duration: calc(inherit + 2s); /* =12s */ } But it don't seem to works. Is it browsers bug or specs? The inherit keyword can only exist alone as a value in a property declaration. It cannot be used with anything else as a value, because it's a value in and of itself. This means it cannot be used with functions like calc() either. See CSS2.1 and css3-cascade . Furthermore, the calc() function itself only takes literal numeric values such as numbers, dimensions and percentages . So to put

jQuery animate() and CSS calc()

╄→尐↘猪︶ㄣ 提交于 2019-12-04 22:53:37
I tried to set CSS calc() using jQuery animate, for example: $element.animate({ height: 'calc(100% - 30px)' }, 500); and I noticed that calc() is not working with jQuery animate... I hope that there is a way to do it, I don't want a similar way to do it, an alternative or a workaround, I want to set calc() Is this impossible? In any way? If it is possible, please can you show how? Setting calc() like you want won't work. The easiest way to do it is to "calculate" it's value into a variable, something like this: var newHeight = $('.container').height() - 30; then you can use the animate() with

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

 ̄綄美尐妖づ 提交于 2019-12-02 18:48:12
问题 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? 回答1: What you need to do, is use the proper syntax: calc((100%/5) + 10px) https://developer.mozilla.org/en-US/docs/Web/CSS/calc: “Note: The + and - operators must always be surrounded by whitespace.” 来源: https://stackoverflow.com/questions/25298829/css-calc100-510px-isnt-working

Is there a way to use variables in Less for the ~ operator, like ~“calc(100% - @spacing)”;

别等时光非礼了梦想. 提交于 2019-12-02 16:05:26
Is there a way to use variables in less ~ operator, like ~"calc(70% - @spacing)"; When I have tried it it only works with static values like ~"calc(70% - 10px)"; Can I get the string to be evaluated prior to beeing set as a property. To disable the calculation which LESS does automatically when discovering a - between two numeric values but still being able to use variables, you can write one of the following: 1) Only escape the operator that triggers the calculation and use the variable like you normally do @padding: 20px; body { padding: calc(100% ~"-" @padding); } 2) Escape the whole

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

故事扮演 提交于 2019-12-02 09:45:24
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? What you need to do, is use the proper syntax: calc((100%/5) + 10px) https://developer.mozilla.org/en-US/docs/Web/CSS/calc : “Note: The + and - operators must always be surrounded by whitespace.” 来源: https://stackoverflow.com/questions/25298829/css-calc100-510px-isnt-working

Calc() outputting unexpected value

给你一囗甜甜゛ 提交于 2019-12-02 09:09:44
问题 What I would like to do is make the #grid height 160% of the #grid width via calc(var(--grid-item-width) * 1.6) , but it appears that --grid-item-width is being treated as a percentage of the viewport width instead of a pixel value. The height of #grid is much larger than 160% of its width as can be seen in the screenshot below. :root { --gap: 26px; --grid-item-width: calc(100% - calc(var(--gap) * 4)); } #grid { width: 100%; height: var(--grid-item-width); /* does not match */ overflow-x: