Solution 1 :

Use this below code to achieve your need

<!DOCTYPE html>
<html>
<head>
    <title>Position</title>
    <style type="text/css">
        #tab_position_1 {
            width: 20px;
            height: 100px;
            position: fixed;
            background: #999999;
            cursor: pointer;
            color: white;
            right:0;
            top: calc(50% + 100px);
            z-index: 4;
            border-top-left-radius: 10px;
            border-bottom-left-radius: 10px;
        }
        #tab_position_2 {
            width: 20px;
            height: 100px;
            position: fixed;
            background: #999999;
            cursor: pointer;
            color: white;
            right:0;
            top: calc(50% + 200px);
            z-index: 4;
            border-top-left-radius: 10px;
            border-bottom-left-radius: 10px;
        }
        #tab_position_3 {
            width: 20px;
            height: 100px;
            position: fixed;
            background: #999999;
            cursor: pointer;
            color: white;
            right:0;
            top: calc(50% - 100px);
            z-index: 4;
            border-top-left-radius: 10px;
            border-bottom-left-radius: 10px;
        }
        #tab_position_4 {
            width: 20px;
            height: 100px;
            position: fixed;
            background: #999999;
            cursor: pointer;
            color: white;
            right:0;
            top: calc(50% - 200px);
            z-index: 4;
            border-top-left-radius: 10px;
            border-bottom-left-radius: 10px;
        }
    </style>
</head>
<body>
<div id="tab_position_1"></div>
<div id="tab_position_2"></div>
<div id="tab_position_3"></div>
<div id="tab_position_4"></div>
</body>
</html>

Problem :

I know CSS calc works for an example like:

width: calc(100% - 100px);

But it doesn’t seem to work with the “top” attribute, like:

top: calc(50% + 100px);

The object is stuck near the top of the page.

My full CSS is:

#tab_position_1 {
    width: 20px;
    height: 100px;
    position: fixed;
    background: #999999;
    cursor: pointer;
    color: white;
    right:0;
    top: calc(50% + 100px);
    z-index: 4;
    border-top-left-radius: 10px;
    border-bottom-left-radius: 10px;
}

I have a cluster of 4 tabs that I would like to space on the edge of the page at 50% +100px, +200px, -100px, -200px, so that as the screen size changes, the cluster stays centered. I know I can do this through javascript, but would like to know if I can do this through CSS and Calc?

Is there a way this can be done with CSS/Calc for the TOP attribute?

Comments

Comment posted by Anthony McGrath

You have an extra % character that shouldn’t be there it looks like.

Comment posted by hder

Yes, you are right. I removed that extra % – still does not work.

Comment posted by w3schools.com/cssref/tryit.asp?filename=trycss_position_top

Maybe changing position: fixed to absolute will allow it to work. It seems to work in this example:

Comment posted by hder

Fixed, Absolute – no change. The link does not show Calc examples – just a pixel position, which I know works fine.

Comment posted by Anthony McGrath

Try adjusting the top: to use calc(40% + 50px) for example

By