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.
Related
How to wrap a text around a centered (round) image like this:
I tried this jsfiddle but the text goes behind the image and does not flow around it.
#circle {
float:positioned;
position: absolute;
top:10%;
left: 40%;
wrap-shape: circle(50%, 50%, 120px);
wrap-margin: 10px;
}
<div id="circle"><img src="http://www.guitare-rabuffetti.fr/test/circle.png"/></div>
<div>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nam cursus. Morbi ut mi. Nullam enim leo, egestas id, condimentum at, laoreet mattis, massa. Sed eleifend nonummy diam. Praesent mauris ante, elementum et, bibendum at, posuere sit amet, nibh. Duis tincidunt lectus quis dui viverra vestibulum. Suspendisse vulputate aliquam dui. Nulla elementum dui ut augue. Aliquam vehicula mi at mauris. Maecenas placerat, nisl at consequat rhoncus, sem nunc gravida justo, quis eleifend arcu velit quis lacus. Morbi magna magna, tincidunt a, mattis non, imperdiet vitae, tellus. Sed odio est, auctor ac, sollicitudin in, consequat vitae, orci. Fusce id felis. Vivamus sollicitudin metus eget eros.
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. In posuere felis nec tortor. Pellentesque faucibus. Ut accumsan ultricies elit. Maecenas at justo id velit placerat molestie. Donec dictum lectus non odio. Cras a ante vitae enim iaculis aliquam. Mauris nunc quam, venenatis nec, euismod sit amet, egestas placerat, est. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Cras id elit. Integer quis urna. Ut ante enim, dapibus malesuada, fringilla eu, condimentum quis, tellus. Aenean porttitor eros vel dolor. Donec convallis pede venenatis nibh. Duis quam. Nam eget lacus. Aliquam erat volutpat. Quisque dignissim congue leo.
Mauris vel lacus vitae felis vestibulum volutpat. Etiam est nunc, venenatis in, tristique eu, imperdiet ac, nisl. Cum sociis natoque penatibus et
</div>
As already noted, shape wrapping currently only works for floated elements, so this exact situation isn't do-able with CSS only, because only wrapping on one side of a shape is permitted (expected). Once the CSS Shapes 2 and/or CSS Exclusions specs) are adopted, we will be able to do this with not only shapes but also image transparency.
I ran into this same problem while trying to figure out how shapes and CSS columns interact (spoiler: decent, but not organically). The problem seems to be that the layout algorithm looks for the farthest edge (ignoring the possiblity of multiple sides), then starts content layout from that coordinate. For elements in the middle, this means you get text only on one side. For CSS columns (which is how I figured this out), the layout again starts from the farthest edge, but then continues straight down instead of wrapping to the shape on each line (see fiddle), so protrusions on shapes (like a star polygon) can actually force wrapping content to end up below the entire shape instead of squished to one side or flowing down into the protrusion.
(note there are 3 sets of 2 columns on 2nd example)
However, there are a couple options that may work for similar situations. I have adapted the following from the other answers/comments, but had to make several changes to get them working (and several of the CSS attributes were experimental and are no longer valid), so I felt this was better as a new answer than as edits/comments:
Wrap one side
Use shape-outside on a left floated div to create a wrapping circle, then use margin-left to push it away from the left side. I added a circle inside the div for illustration (your image URL is 404), but had to tweak the location as Chrome did not calculate its position the way one would expect once margins were added.
http://jsfiddle.net/brichins/50h20kxa/1/
Columns and mirrored wrapping elements
If columns are acceptable, manually (see above CSS column discussion) creating 2 containers for columns and placing a shaped element on the side of each gives the following:
http://jsfiddle.net/brichins/gvhpfccu/
The disadvantage here is columns where you may have wanted a single block (not necessarily bad for readability), as well has having to compute an appropriate split for your content.
Reading
Intro and walkthrough on HTML5 Rocks: https://www.html5rocks.com/en/tutorials/shapes/getting-started/
References the amazing Alice in Wonderland example from 2013. It appears to not function completely anymore, but the entire talk is still interesting
Creating Non-Rectangular Layouts With CSS Shapes: https://sarasoueidan.com/blog/css-shapes/
CSS Tricks article: https://css-tricks.com/almanac/properties/s/shape-outside/
D3plus workaround plugin (for similar SVG solutions): https://d3plus.org/examples/utilities/a39f0c3fc52804ee859a/
Question resolved :
Actual situation :
The CSS shape works for float, so it's not for centered images now. This property works only for Chrome and Opera at the moment.
Maybe there will be a solution for non float elements in the future. Look at this W3C editor's draft : http://www.interoperabilitybridges.com/css3-floats/OriginalSubmition.html
A hand made CSS solution :
Basically, there are 2 columns (like in newspapers). The text begins in the left column and goes down. The text continues on the top of the right column and goes down. The columns are a bit higher than the image. The left column has a half invisible circle as well as the right column - on the position of the centered image. The two half circles are build by multiple boxes of different length, they are invisible. (The hight of the boxes is the height of the font.) The text must be justified. The text is now flowing around the half circles in each column. The image will be positioned over the 2 invisible half circles.
Another, not very technical solution is to use Libre Office and Inkscape to produce an SVG file.
Import the picture into Libre Office - wrap the text around the image - save as PDF - open Inkscape - save as SVG - import the SVG in your Webpage - done.
Thanks everybody for helping me and for your inputs !
I don't think it's possible since it relies on float and you can't float to the middle/center of the page.
Here's what I came up with:
[old fiddle]/5Lxc444p/8/
If you put the width style on the actual circle it works better than on a parent div.
Also, here's a good writeup on css shapes: http://www.html5rocks.com/en/tutorials/shapes/getting-started/
EDIT:
Here's an updated fiddle for the 2 column layout with absolute positioned circle.
http://jsfiddle.net/5Lxc444p/11/
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.
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.
I have a fairly large WordPress .XML export file from a blog that I am going to migrate to Drupal. One glaring issue with the export file is that it's missing <p> tags for any paragraph breaks. However, the tags are present on the actual site.
From what I can see from the raw text in the XML file, there are multiple line breaks between paragraphs where there should have been a single <p> tag. I was hoping to globally add in a <p> tag where there's a line break and a capital letter using RegEx but I don't have a working knowledge of how that works. A sample XML tag in the export file that contains the text in question is:
<content:encoded><![CDATA[Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur gravida risus at sem interdum iaculis. Curabitur eget est tellus, quis viverra arcu.
Cras posuere turpis imperdiet odio aliquet sollicitudin. Maecenas et neque eget quam fringilla tempor. Vivamus sodales vulputate consectetur.
Sed ullamcorper elementum est, at dapibus orci fermentum vitae. Vivamus nisi turpis, pretium sed tincidunt et, dapibus at eros. Quisque neque magna, posuere eget eleifend ut.
As you can see from the above, there are multiple line breaks in between what should be paragraphs. I was thinking of the line break / capital letter combo for the RegEx so as to only put in one <p> tag and also target specifically the <content:encoded> XML tag so that I don't add tags elsewhere in the XML file. One other issue to make things more complicated is that some paragraphs already have <p> tags where the editor added in a custom class like <p class="myclass">.
This issue was discussed on StackOverflow somewhere before. Problem is, that Wordpress doesn't store the p tags in its database (if you use its WYSIWYG editor), these tags are created upon rendering by wpautop() function (instead of breaks). So I edited the export.php file (running WP 3.4.1) and added the function there. You can see the result on Pastebin (changes are on lines 375 and 376).
<content:encoded><?php echo wxr_cdata( apply_filters( 'the_content_export', wpautop( $post->post_content ) ) ); ?></content:encoded>
<excerpt:encoded><?php echo wxr_cdata( apply_filters( 'the_excerpt_export', wpautop( $post->post_excerpt ) ) ); ?></excerpt:encoded>
You can copy and paste the whole code in file [root]/wp-admin/icludes/export.php and run the export again. Don't forget to backup the file before - I don't guarantee it will work other versions, but you can get the idea how to edit the export.
What would be the best method for replacing variables/words/lines of text in a larger "paragraph" of code?
Example:
Lorem ipsum dolor $SIT amet, consectetur adipiscing elit. Aliquam condimentum dolor ut est faucibus dapibus. Donec molestie dictum nisi, eu euismod $SAPIEN gravida in. Aliquam dictum, tellus eu facilisis laoreet, sapien nunc placerat turpis, eu pretium augue eros vel lectus. Quisque condimentum lorem $EROS, vel pharetra tortor.
I want to be able to enter text in a textbox/prompt to replace the "Variables" $SIT, $SAPIEN, $EROS with actual values automatically.
I trust I've made myself obscure? :P
I'm n00b at any sort of coding. I only know some basic HTML, PHP, and Java. But please give me a clear solution with an example or link or more help.
Thanks so much!
You must utilize JavaScript if you want to do it client-side, and any of the server-side ones [PHP, Python, Ruby] if you want to do it that way. In all of these languages there are equivalents of "string replace" functions, that'll take list of strings to search, list of strings to replace and subject that they will be working on. Solution for JS and PHP:
http://php.net/manual/en/function.str-replace.php
http://www.w3schools.com/jsref/jsref_replace.asp
The way that you'll do it is up to you.