How to add/subtract in css property?
#box {
position: absolute;
top: 50% ;
left: calc(50% - 286px);
margin-left: -75px /* half of the width */
background-color: red; /* or something more useful */
z-index:100;
}
I am simply try to add/subtract the contents value in the actual top and left percentage
top: 50% - contents_height_in_number_with_px
I want to do this so that my main contents is automatically centered
Note:i already search on googled and already try calc() not found any solution
That css (
calc()) is not supported in all browsers. You need to know the height of the current viewport and the height of div#box. Here’s a way to determine both, i.e. to center an element. You can ditchtop:50% ; left:calc(50% - 286px);margin-left:-75pxin the css now.See also this jsfiddle