1
I need to decrease 20px
of 100% with the javascript . style
Attempts:
circulo[0].style.left = "calc(100%" + "-90px)";
circulo[0].style.left = "calc(" + 100 +"%" + "-20px)";
1
I need to decrease 20px
of 100% with the javascript . style
Attempts:
circulo[0].style.left = "calc(100%" + "-90px)";
circulo[0].style.left = "calc(" + 100 +"%" + "-20px)";
2
The function calc()
shall have a space before and after the operator:
calc(valor1 - valor2)
↑ ↑
In your case, these concatenations are unnecessary. You should use concatenation when the value used is dynamic represented by some variable, not fixed values. And even then, its concatenation would result in an invalid value of the property:
"calc(" + 100 +"%" + "-20px)";
would be "calc(100%-20px)";
See missing spaces before and after the operator -
.
The right thing would be:
circulo[0].style.left = "calc(100% - 20px)";
Remembering that to move the element with the property
left
, the element must have aposition
other thanstatic
(pattern):
position: relative ou fixed ou absolute;
Example:
var circulo = document.getElementsByClassName("circulo");
circulo[0].style.left = "calc(100% - 50px)";
.circulo{
width: 100px;
height: 100px;
background: red;
position: relative;
}
<div class="circulo"></div>
See that in the example above, the div
of 100px
is with left
of 100%
(which would make her stay off the screen) but has a recoil of 50px
(half), with half of 50px
.
Browser other questions tagged javascript
You are not signed in. Login or sign up in order to post.
That one
calc
is CSS,See the documentation - MDN, also has a tutorial on the site of Maujor– NoobSaibot
I’m trying to do a range with two buttons to search by age. no uijquery searched the net but I found nothing that worked on my site
– Pedro Fillipe
Why are you concatenating? Have you tried
"calc(100% - 20px)"
?– Sam
I was going to say what @sam said, see: http://jsfiddle.net/0ek397qd/6
– NoobSaibot