Best replacement for font tag in html
The span
tag would be the best way.
Although inline CSS is typically not recommended, here is an example:
<p>
This is my <span style="font-weight:bold">paragraph</span>.
</p>
span
and div
are similar, but the div
tag is a block element, so it will cause line-breaks. span
is an inline tag that can be used inline with your text.
HTML replace Font tag
You should use css to style your content. Like so:
<p style="font-family:Arial; font-size:2em; color:#ff0000;">some text here</p>
What is best replacement for font size=X in CSS?
from W3C
http://www.w3.org/TR/html4/present/graphics.html#edef-FONT
size = cdata [CN] Deprecated.
This attribute sets the size of the font. Possible values:
- An integer between 1 and 7. This sets the font to some fixed size, whose rendering depends on the user agent. Not all user agents may
render all seven sizes.- A relative increase in font size. The value "+1" means one size larger. The value "-3" means three sizes smaller. All sizes belong to
the scale of 1 to 7.
front this peice you could clearly see that equivalent to size will be large or x-large .. etc
explanation :
<font size="3">
is just as if you used font-size: medium ;
<font size="4">
is just as if you used font-size: large ;
<font size="5">
is just as if you used font-size: x-large ;
<font size="6">
is just as if you used font-size: xx-large ;
<font size="7">
is just as if you used font-size: -webkit-xxx-large;
update :
i think i have got it wrong the first time it's not em's (although they work similarly). please see the update :)
Replacement For font
<font>
is pretty pointless without size, face, color, etc. attributes. So in your example just remove the tags.
If you want to actually style the text use CSS styles.
.someclass {
font-family: "Times New Roman", Georgia, Serif;
}
<span class="someclass">This is where you would enter text</span>
Replacement for pre and/or code tags?
They are not ignored. The <code>
element has nothing to do with preformatted text, but it by default sets the font to monospace. The <pre>
element works universally. But neither of these elements overrides the normal HTML rule that the <
character followed by a letter starts a tag; they are not defined to do so, and they do not actually do so in browsers. I suspect a misunderstanding of this is the background to your question.
Thus, within these elements, as elsewhere, to display <
as data, write <
, and to display &
as data, write &
.
The <xmp>
element is different. Within it, no markup is recognized, i.e. all characters are shows as-is; the end tag </xmp>
is recognized, of course. Though this element was deprecated in HTML 3.2 and removed from later specs (though it is mentioned as obsolete in HTML5), it still seems to have support in all browsers. There was also a very similar element, <listing>
, for wide listings, but support to it has been dropped.
How to replace text containing string with a HTML tag?
I assume you don't literally mean all text on a page, but rather all text inside of a given element. DucFilans is right on the money with regex, I'll slightly modify his answer to provide a complete working solution:
var parserRules = [ { pattern: /bold\("(.*?)"\)/g, replacement: '<b>$1</b>' }, { pattern: /italics\("(.*?)"\)/g, replacement: '<i>$1</i>' }];
document.querySelectorAll('.parse').forEach(function(tag) { var inner = tag.innerHTML; parserRules.forEach(function(rule) { inner = inner.replace(rule.pattern, rule.replacement) }); tag.innerHTML = inner;});
<div class='parse'> <div>bold("Hello") world <p> Rose italics("pink") slow bold("!") </p> </div> <div>bold("astiago") cheeeeeeese!</div></div>
HTML Style tag equivalent of font size+2
CSS is the better way to do this.
<span style="font-size: 120%;"></span>
Replace style tag with javascript equivalent
The answer was to use document.head.innerHTML += in an inline script block to add HTML representing the STYLE block and style. This is added to the DOM immediately after the SCRIPT tag that creates it. Using backticks for the HTML template containing the font size would have made it even easier, though in the end I had to support IE 11 so backticks were out.
The solution:
<script>
var fontSize = //font size retrieved here;
document.head.innerHTML += "<style type=\"text/css\"> \nbody { font-size: ".concat(fontSize, "em } \n</style>");
</script>
Related Topics
Hide Div on Mobile Devices, Using CSS
Font Weights Differing in Webkit and Firefox
Best Replacement for Font Tag in HTML
Can Background Image Extend Beyond Div's Borders
Why Is There a Pesky Little Space Between <Img> and Other Elements
Is It Acceptable to Use Tables for Forms? or Is It Still More Correct to Use Divs
Do <Span> Elements with "Position: Absolute;" Behave as Block-Level Elements
HTML/CSS Buttons That Scroll Down to Different Div Sections on a Webpage
Print Page Count with Total Number of Pages Using CSS
Remove Dotted Outline from Range Input Element in Firefox
How Come My Float Elements Aren't Within Their Parent
Center an Image in a Div Too Small for It
How to Place The Cursor (Auto Focus) in Text Box When a Page Gets Loaded Without JavaScript Support
Styling Dropdowns (Select) Boxes