Is there any way to text wrapping into two or more columns in HTML only with CSS?
I have continous text with p tags only like this:
<div id="needtowrap">
<p>Lorem ipsum dolor sit amet, ...</p>
<p>Nulla ullamcorper diam arcu, ...</p>
<p>In libero diam, facilisis quis urna nec, ...</p>
<p>Sed varius et mi quis dictum. ...</p>
</div>
I wan to wrap this text into two columns at 50% of the text, like in Microsoft Word or LibreOffice, etc.
It is possible?
See the "column" rule:
http://www.w3schools.com/css/css3_multiple_columns.asp
As you can see, it's a CSS3 rule, and so you might not find browser support as complete as you'd like..
MDN:
https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Using_multi-column_layouts
Breakdown of browser support:
http://caniuse.com/#feat=multicolumn
More reading, examples etc:
http://css-tricks.com/guide-responsive-friendly-css-columns/
(fairly comprehensive)
Multi-column layout in CSS with the columns property and related properties is rather well supported in modern browsers. At the very simplest, you would set just columns: 2 on the div element. In practice, you additionally need vendor prefixed versions for reasonable browser coverage:
#needtowrap {
-webkit-columns: 2;
-moz-columns: 2;
columns: 2;
}
#needtowrap p {
margin: 0;
}
#needtowrap p + p {
text-indent: 1em;
}
<div id="needtowrap">
<p>Lorem ipsum dolor sit amet, ...
Well we need some real content too.
Otherwise this looks rather dull.</p>
<p>Nulla ullamcorper diam arcu, ...
And some more text to make this look like a paragragh.</p>
<p>In libero diam, facilisis quis urna nec, ...
By the way, fake Latin is not good fill text.
It behaves differently from the texts you will really use.</p>
<p>Sed varius et mi quis dictum. ...
But I digress.</p>
</div>
The example uses ”literary paragraph” formatting: instead of default vertical spacing between paragraphs, the first line of each paragraph except the first one is indented a bit. In multi-column rendering, this works much better than the default p formatting (which reflects defaults of office automation software rather than typographic traditions).
There are many other things to consider. As a rule, multi-column text usually looks much better when justified on both sides. This in turn makes hyphenation more or less a necessity.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I'm making a website using HTML5 and don't know which semantic element to use for the first page content the user sees first (full viewport height and width). I've read that the <header> element should be used for introductory stuff like website title and navigation. I don't even have that in my site, instead I have something like this, basically the first part of the website where you can see what it is about and links to some contact stuff.
It is a single page site, but if I had more pages, they would not have that content and I would probably make a navbar and put it in a <header>. With <main> I'd like to cover more stuff than only this.
Maybe an even different element? I don't know, it's like the combination of a <header>, a <section> and a <main>.
What do you think would be best?
Edit: This is not the entire page I have shown on the image. It is just the part that shows up first when you open the website, there is also content under it. I wanted to know what element to wrap over the thing in the image.
Here is the code (deleted classes and changed text to dummy text):
<header>
<address>
123 456 789
</address>
<div>
<h1>Heading</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nibh nibh, egestas eget justo maximus, consectetur ultricies ante. Quisque facilisis pellentesque sagittis. Donec iaculis tellus nisl, vitae sodales ipsum ornare id. Suspendisse potenti. Curabitur eu ornare quam. Fusce laoreet vitae quam at ornare. Etiam quis malesuada magna.</p>
Button
</div>
</header>
Is this OK?
(the phone icon on the bottom right has position: fixed and is outside the header)
This is honestly a matter of opinion.
Personally I wouldn't bother at all with sectional elements on such a small site, since it really just adds noise. It won't be helping, say, a blind person or a search engine crawler to understand better, because there's just not that much to understand.
However I admire your effort. I would put "heading" in header, the phone stuff in "footer" (even though it's at the top) and the rest in main.
Edit: Considering that this is just the top of your page, I believe considering it the header is reasonable. The code you posted is certainly valid html.
I am using Angular6.
I have a pre tag with email text. Within this email text are tags like [cid:image001.jpg] which represent an image, using image001.jpg, I can retrieve that specific image from the back-end.
The problem is that I don't know how I can insert a new HTML element from the Typescript file into the pre tag, if this is even possible.
I have tried using a replace() method and replacing the '[cid:image001.jpg]' with '<img ...>' but it (understandably) gets interpreted as a string.
Help would be much appreciated.
Edit:
the positioning of the images is important, the <img> tag should appear where the [cid:image001.jpg] is, for example.
Example email:
Greetings,
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum
vehicula egestas elit viverra auctor. [cid:image001.jpg] Morbi at
nisi vel lorem porta pellentesque ut non urna.
Integer tempor tincidunt viverra. Vivamus ullamcorper et risus ac.
[cid:image002.jpg]
Best regards...
Can you try to pass the image in argument like this:
<img [cid]="pictureUrl">
I fixed this by doing the following, I changed:
<pre> {{emailText}} </pre>
To:
<pre innerHTML="safeHTML(emailText)"> </pre>
Where safeHTML() cleans the text so that scripting is not possible, this is important because it would be very unsafe otherwise.
I'm very new to coding, and am currently teaching myself html/css and i found that my paragraphs weren't centering in the middle of the page. I'd had my headline and sub headline labelled as h1 and h2, so i thought naturally the paragraphs would be the same (even though they had exactly the same declarations), yet when i changed both the elements to just p and brought them both under the same selector it worked. I was wondering if p1/p2 using would cause a lot of problems in the future? (this was before i was learning about ID's and classes, would that be the correct way to differentiate between paragraphs instead?)
please be kind, I've been learning less than a couple weeks:)
p1 and p2 are not valid HTML elements in themselves.
Granted, with HTML5, you can define your own elements where necessary, however this is usually reserved for instances where it makes your markup more semantic, and usually with a front-end framework or such.
With paragraphs, if you must differentiate between them, then I would suggest using classes.
<h1>Heading One</h1>
<h2>Heading Two</h2>
<p class="p1">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean volutpat efficitur magna eget tincidunt.</p>
<p class="p2">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean volutpat efficitur magna eget tincidunt.</p>
Paragraphs are always <p>. Only the header elements have this kind of numbering.
My personal reccomendation would be to use ID's rather than Classes. This is due to the nature of what seem to you want in your question.
ID's are unique - meaning that there can only be one of them per page.
Classes aren't unique - meaning that they can be assigned to multiple objects per page.
<p id="one">This is paragraph one.</p>
<p id="two">This is paragraph two.</p>
Before you slate me, yes I know that you shouldn't parse HTML with regex, you should use a dedicated parser. I don't have that option in the language I'm using (Xojo) and for various reasons, I need to use RegEx.
I'm trying to capture an entire block of HTML that may or may not contain nested HTML elements. Examples:
<blockquote> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
id sem consectetuer libero luctus adipiscing.</blockquote>
-----------------
<blockquote> This is the first level of quoting.
<blockquote> This is nested blockquote.</blockquote>
Back to the first level.</blockquote>
-----------------
<div>
Not nested
</div>
-----------------
<div>
Top level
<div>Nested</div>
</div>
I had come up with this pattern: <(\w*)>([\S\s]*?)<\/\1> but whilst it works for blocks of HTML it fails if the block contains a block of HTML with the same tags as the parent block. Online example here.
I'm using the PRCE variant of RegEx and coding in Xojo.
Does anyone have any useful advice on how to solve this problem? Thank you.
Why is the line height different between these two paragraphs (at least in Safari and Chrome on OS X)? Shouldn't the default line height be 1.0, which I would interpret as the "natural" height of a given font (where descenders on the line above do not touch ascenders from the line below)? I find that if I use 1.0, descenders get cut off by the line below (depending on the font).
JSFiddle
<p style="font:14pt/1.0 Times">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque maximus mi vel erat finibus, eu tincidunt vehicula quis eu odio. In vel nisi non odio consequat porta in eros, sit amet tincidunt nunc dictum eu. In rhoncus convallis dapibus.</p>
<p style="font:14pt Times">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque maximus mi vel erat finibus, eu tincidunt vehicula quis eu odio. In vel nisi non odio consequat porta in eros, sit amet tincidunt nunc dictum eu. In rhoncus convallis dapibus.</p>
I have an HTML "web view" embedded in my iOS app and want to give the user control over line spacing. I find I need to use something like 1.2, 1.8, and 2.4 for single, one-and-a-half, and double spacing. Anything less than about 1.2 and the lines overlap.
I've found other questions where 1.2 is described as equivalent to normal, which looks about right.
So second question is, how can I calculate at run time (assuming it might vary by device) the fudge factor that I need to multiply line spacing by so that lines don't overlap? Or is 1.2 a "rule" that I can assume will always be true?
I believe its actually due to the font. Font families can have different line heights based on their chars. The default for Times is not equal to the default sans-serif (browser default).
normal
Depends on the user agent. Desktop browsers (including Firefox) use a default value of roughly 1.2, depending on the element's font-family. mdn link
It turns out that setting the line-height to 1.0 means "slightly overlap the line above when writing each line". In order to avoid this, every Web designer in the world has to make adjustments to line-height to guess at what every browser in the world is going to do, instead of a small number of browser writers making their software work correctly in the first place.
EDIT: Further research has revealed if you create a UIFont using the selected font family and size, you can get the exact line height multiplier to use by dividing the UIFont lineHeight property by the pointSize property. This doesn't do you much good on a website, but it works great when you have an integrated web view as described in the question.