Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrap text from bottom to top

Tags:

text

css

Anybody know how I could wrap the text in reverse order, from bottom to top? I attached an example image.

[][http://i.stack.imgur.com/RVsIG.jpg]

Instead of breaking the line after it is full and having an incomplete line at the end, I need to brake somehow from bottom to top, so bottom lines are full and top line is incomplete.

like image 735
Adrian Cumpanasu Avatar asked Mar 15 '14 12:03

Adrian Cumpanasu


People also ask

How do you wrap text on top and bottom?

Go to Picture Format or Shape Format and select Arrange > Wrap Text. If the window is wide enough, Word displays Wrap Text directly on the Picture Format tab. Choose the wrapping options that you want to apply. For example, In Line with Text, Top and Bottom, and Behind Text.

How do you wrap text in Word?

Click on the "Wrap Text" button in the "Arrange" tool group. Select your desired text wrap style from the drop-down menu that appears by clicking on it. You can preview each style by moving your cursor over them. Save your Word document.

What is the Wrap text feature in Excel?

The Excel wrap text feature can help you fully display longer text in a cell without it overflowing to other cells. "Wrapping text" means displaying the cell contents on multiple lines, rather than one long line.


3 Answers

I would not recommend using exotic CSS attributes which aren't even in Chrome & Firefox yet. The best cross-browser solution is to handle this in Javascript when the document loads. Here's a sketch of how to do that:

$(function() {
    $(".title").each(function(i,title) {
        var width = 0;
        var originalHeight = $(title).height();
        var spacer = $('<div style="float:right;height:1px;"/>').prependTo(title);
        while (originalHeight == $(title).height()) {
            spacer.width( ++width );
        }
        spacer.width( --width );
    });
});

Working JSFiddle is here: http://jsfiddle.net/zephod/hfuu3m49/1/

like image 60
Tom Rees Avatar answered Oct 27 '22 22:10

Tom Rees


There is no general css solution for it. You must have to utilize help of any language. This is one of the solution using PHP:

<?php
$str= "This is what I want to achieve with your help";
$str = strrev($str);
$exp = str_split($str,18);
$str = implode(">rb<", $exp);
echo strrev($str);
?>
like image 25
Asif Iqbal Avatar answered Oct 28 '22 00:10

Asif Iqbal


6 years later, but fret not! I have found a pure CSS solution!

Turns out you can achieve this result with flexbox, but it's not obvious or very straight forward. This is what I started out with:

A CSS card with text wrongly aligned

I want the header to be "bottom-heavy", the same effect as you describe in the question.

I began by splitting up my string by whitespace and giving them each a <span> parent. By using flex-wrap: wrap-reverse, and align-content: flex-start. You will achieve this:

The same image as before, but the last word has now been overflowed upwards, making it read the wrong way!

Oh no! Now the order is messed up! Here comes the trick. By reversing both the order in which you add spans to the HTML and the direction order of flex with 'flex-direction: row-reverse', you actually achieve the "pyramid-shaped" upwards overflow effect you desire.

The text is now in the proper order, with most of it being at the bottom, creating the desired effect.

Here is my (simplified) code, using react and react-bootstrap:

        <Row className='d-flex flex-wrap-reverse flex-row-reverse align-content-start'>
          {props.deck.name
            .split(' ')
            .reverse()
            .map(word => (
              <span className='mr-1'>{word}</span>
            ))}
        </Row>
like image 24
Torben Nordtorp Avatar answered Oct 27 '22 23:10

Torben Nordtorp