How to flow text from DIV to DIV?

后端 未结 3 1050
旧巷少年郎
旧巷少年郎 2021-01-05 07:21

I have two DIVs with absolute position on two sides of a HTML page such as (EXAMPLE)

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-05 07:42

    Here is one for fixed-width approach. The gap between two columns will equal to width of main div.

    Fiddle

    The big text here.

    For variable width you need JS or jQuery.

    Update:

    I have used jQuery for this purpose as I have found pure JS difficult to find solution of this.

    function setGap() {
        var width = $(".main").width();
        $(".sides").css({
            "-moz-column-gap": width + "px",
                "-webkit-column-gap": width + "px",
                "column-gap": width + "px"
        });
    }
    $(window).resize(setGap);
    setGap();
    

    Fiddle

    Update 1:

    function setGap() {
        var width = document.getElementsByClassName("main")[0].offsetWidth;
        var elem = document.getElementsByClassName("sides")[0];
        var style = elem.getAttribute("style");
        if (typeof style != "null") {
            style =
                "-moz-column-gap:" + width + "px; -webkit-column-gap:" + width + "px; column-gap:" + width + "px";
            elem.setAttribute("style", style);
        }
        else {
            style +=
                "-moz-column-gap:" + width + "px; -webkit-column-gap:" + width + "px; column-gap:" + width + "px";
            elem.setAttribute("style", style);
        }
    }
    window.onresize = setGap;
    setGap();
    

    Fiddle

提交回复
热议问题