Circular menus are very popular for mobile apps. Using CSS transforms and transitions we can create a simple circular menu as the one shown in the corner below. And using the same principles explained below, the menu can be modified and customized to create an upwards or downwards opening menu too.
There's no direct way in CSS to translate an item diagonally . But knowing the value of the radius of the circle on which we want to position the items, we can use it, and apply a simple mathematical rule to calculate the value of the horizontal and vertical translation values to pass to the translateX() and translateY() functions, and that way end up with a "diagonal" translation to move the menu items to the exact positions on the circle.
The value of the radius of the circle will be the value of the hypotenuse we will use in a simple math rule according to this image below:
Assuming point A is the position of the "share" button, which is also the center of the circle on which we want to position the other menu items. Let B be the point where we want to position one of the items on the circle. We need to calculate the value of b and a , where b is the value to pass to the translateX() function and a the value for the translateY() function.
The radius of the circle, i.e the value of c in our example is 10em.
According to the cos rule applied to angle BAC of the triangle, we get: cos(BAC) = b / c , hence, b = c * cos(BAC) . You determine the value of the angle you want depending on how many items you need, and apply this rule to calculate the value of b .
Similarly, a = sin(BAC) * c , and this will be the value for translateY().
In this example, the angle for the google plus icon will be 30deg, and that for the facebook icon will be 60deg (after drawing the triangle for each angle), and you can apply the above rules to calculate the values needed to translate the items.
And that's pretty much it.
The click event which closes/opens the menu can be handled using Javascript, or you can take it one step further and have a CSS-only menu by using the CSS Checkbox hack . In this example, I'm using Javascript, and the HTML5 classList API, which is not supported in all browsers, so you need to view the demo in a modern browser to make it work, or uncomment the jQuery code and use that instead of the classList API code.
If you like this simple How-To, you might want to read more about creating circular navigation in my tutorial on Codrops , and have a look at the demos included with it.