D
D
Denis Bukreev2016-08-10 11:37:44
css
Denis Bukreev, 2016-08-10 11:37:44

How to layout a menu like flex-box (justify-content: space-between)?

So it goes. I'm already used to flex, and then suddenly I needed support for old browsers.
But I don't even remember laying out such menus without flex: The point
e67e278c422841188349675f6b05cf4a.png
is that the empty space should be evenly centered between menu items, and the first and last items should be adjacent to the edges.
Well, there can be 3 or 4 menu items. This adds problems, because. under a constant number of points, you can still make up.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrey Verkh, 2016-08-10
@sadisme

Do an inlinde-block with text-align:justify
Here is the description

K
KlassT, 2016-08-10
@KlassT

You can solve it with js. I will write code in jquery:

var mainWidth = $('.container').width();
var menuWidth = 0;
var countItems = 0;
$('nav li').each(function() {
    menuWidth += $(this).width();
    countItems++;
});
countItems--;
var marginItems = (mainWidth-menuWidth)/countItems;
$('nav li').css('margin-right', marginItems);
$('nav li:last-child').css('margin-right', 0);

A
Ankhena, 2016-08-10
@Ankhena

codepen.io/anon/pen/kXzroX

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question