简体   繁体   中英

Is there any way to vertically justify text in HTML?

I am currently displaying text in an HTML table that is simply one large row and two columns. I am using the table to take advantage of the side by side aspect (I could switch to floating divs if someone can tell me an advantage to doing so). I fill the text in the left side, and then I fill the right side. It is VERY critical that both sides look even as far as text distribution from top to bottom.

The content for each side is fixed (from the db), and the right side comes up short most of the time. Similar to how text justification spaces out words to fit a line, is there any way I can vertically justify the lines in the right column to make sure that there is text from top top bottom?

I have been searching like crazy and haven't had any luck.

Here is a screenshot of what it looks like. I am attempting to replicate a religious text exactly (hence the column data being fixed, that is actually how it is in the actually book), but I am just having a hard time fine tuning it. The strange thing is that sometimes there isn't a problem, but then other times it is quite bad:

在此处输入图片说明

Assuming UIWebView supports it ( Mobile Safari has since iOS 3.2 ), you could use the -webkit-column CSS properties.

These flow the content of an HTML element into as many columns as you specify, and put as even an amount of text as possible into each column. They also allow you to specify rules (like borders) and gaps between the columns, which would suit your design.

This would mean you wouldn't have to split the content yourself any more.

HTML

<div class="text"><p>I am currently displaying text in an HTML table that is simply one large row and two columns...</div>

<div class="references">If "Side by Side" is your main criterion for choosing a table with just two columns...</div>

CSS

.text {
    -webkit-column-count: 2;
    -webkit-column-gap: 20px;
    -webkit-column-rule: solid 1px #999;
}

.references {
    padding: 10px;
    -webkit-column-count: 3;
    -webkit-column-gap: 10px;
    -webkit-column-rule: solid 1px #999;
    border-top: solid 1px #999;
}

If you are asking this question because you want to use it for an iBook, then use the iBook Author in the Mac App Store , it's free.

Alternatively, you can design a table with 3 columns, the first 2 you can add colspan=2 . This will make the top 2 columns, then the rest will fall in place as 3 columns.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM