CSS to line break before/after a particular `inline-block` item

后端 未结 9 1618
再見小時候
再見小時候 2020-11-27 09:36

Let\'s say I have this HTML:

Features

  • Smells Good
  • <
9条回答
  •  醉酒成梦
    2020-11-27 10:19

    Maybe it's is completely possible with only CSS but I prefer to avoid "float" as much as I can because it interferes with it's parent's height.

    If you are using jQuery, you can create a simple `wrapN` plugin that is similar to `wrapAll` except it only wraps "N" elements and then breaks and wraps the next "N" elements using a loop. Then set your wrappers class to `display: block;`.

    (function ($) {
        $.fn.wrapN = function (wrapper, n, start) {
            if (wrapper === undefined || n === undefined) return false;
            if (start === undefined) start = 0;
            for (var i = start; i < $(this).size(); i += n)
               $(this).slice(i, i + n).wrapAll(wrapper);
            return this;
        };
    }(jQuery));
    

    $(document).ready(function () {
        $("li").wrapN("", 3);
    });
    

    Here is a JSFiddle of the finished product:

    http://jsfiddle.net/dustinpoissant/L79ahLoz/

提交回复
热议问题