Is it possible to select the nth css column?

I have divwith 4 css columnsand I would like to select the 3rd and 4th columns to make the text a little darker, because I do not have a good contrast between the text and background-image, Is this possible? I can make any decision css or js.

Here is a demo .

- EDIT -

It seems that it is impossible to find a selector for pseudoblocks (if I may say so), however I still need to figure out a way to create responsive blocks (for example, columns) that will divide the text equally (in width) each time the browser size changes.

+5
source share
3 answers

, . 3 4 .

#columns {
    background: -webkit-linear-gradient(left, rgba(0,0,0,0) 50%, blue 50%);
    /*... appropriate css for other browser engines*/
}

jsFiddle

- EDIT -

, , .

. span. , JavaScript , . .

, script .

- , , (, span , styleCols, ...).

JavaScript

function styleCols() {
    // get #columns
    var columns = document.getElementById('columns');
    // split the text into words
    var words = columns.innerText.split(' ');
    // remove the text from #columns
    columns.innerText = '';

    // readd the text to #columns with one span per word
    var spans = []
    for (var i=0;i<words.length;i++) {
        var span = document.createElement('span');
        span.innerText = words[i] + ' ';
        spans.push(span);
        columns.appendChild(span);
    }

    // offset of the previous word
    var prev = null;
    // offset of the column
    var colStart = null;
    // number of the column
    var colCount = 0;
    // first element with a specific offset
    var firsts = [];
    // loop through the spans
    for (var i=0;i<spans.length;i++) {
        var first = false;
        var oL = spans[i].offsetLeft;
        console.info(spans[i].innerText, oL);
        // test if this is the first span with this offset
        if (firsts[oL] === undefined) {
            console.info('-- first');
            // add span to firsts
            firsts[oL] = spans[i];
            first = true;
        }
        // if the offset is smaller or equal to the previous offset this
        // is a new line
        // if the offset is also greater than the column offset we are in
        // (the second row of) a new column
        if ((prev === null || oL <= prev) && (colStart === null || oL > colStart)) {
            console.info('-- col++', colCount + 1);
            // update the column offset
            colStart = oL;
            // raise the column count
            colCount++;
        }
        // if we have reached the third column
        if (colCount == 3) {
            // add our new class to the first span with the column offset
            // (this is the first span in the current column
            firsts[oL].classList.add('first-in-col3');
            return;
        }
        // update prev to reflect the current offset
        prev = oL;
    }
}
styleCols();
addEventListener('resize', styleCols, false);

CSS

.first-in-col3, .first-in-col3~span {
    color: red;
}

jsFiddle

+3

, , - , , background-clip:text. , . .

+1
source

All Articles