Same CSS style formatting differently based on pattern - html

Is it possible to define a style that assigns one set of formatting rules for non-parenthesized text and another for parenthesized? The reason for this is to avoid cluttering of format tags (like <b> or <span>). E.g if I have something like
<B>Item1</B> (expl), <B>Item2</B> (expl2), ..., <B>ItemN</B> (explN)
It would be cleaner to state it as
<span class="myClass">Item1 (expl), Item2 (expl2), ..., ItemN (explN)</span>
Where myClass is defined as formatting parenthesized text under a set of rules different from non-parenthesized (bolding non-parenthesized in this example).

I don't think this can't be done in HTML/CSS but can be achieved by using Javascript. Once the page is loaded (onLoad), you can scan for items (may be using a regex) and then surround the text with custom tags.

Related

Which HTML5 tag to use for emphasizing and discussing a word?

When I want to emphasize or discuss a word that is related to computer code inside a block of normal text, I use the <code> tag. For example:
If you set the variable foo to the value 'bar', then something will happen. If you set foo to any other value, then nothing that's any good will happen.
What is the best semantic HTML5 tag to use to emphasize or discuss a word that is not related to computer code? The way I am thinking of this, it would be (or could be) styled like <code> but not monospace. For example:
The word math is a shortened version of the word mathematics, which has its root in some ancient language that I am not going to research right now.
If you're looking for the tag indicates that its content is being referenced / used as an object for discussion
you can use <dfn> tag. According to MDN:
The HTML Definition element (<dfn>) is used to indicate the term being defined within the context of a definition phrase or sentence.
I just found the updated meaning of the <i> tag for HTML5. From MDN:
The HTML <i> element represents a range of text that is set off from the normal text for some reason. Some examples include technical terms, foreign language phrases, or fictional character thoughts. It is typically displayed in italic type:
Musa is one of two or three genera in the family Musaceae; it includes bananas and plantains.
It is a good idea to use the class attribute to identify why the element is being used, so that if the presentation needs to change at a later date, it can be done selectively with style sheets.
So, this is what I am going to do for this case... <i class="example"> or similar.

Terminology - The types of elements in HTML

A while ago there was a term that I remembered that described two categories of elements. I forgot the term and I want to know what that term was. The information I can remember is that the first category of elements get their values from within HTML like <p> or <a> or <ul> but there is another category of elements which get their values from "outside" of HTML like <img> or <input type="textbox">. I want to know the terminology for these types.
Edit - I've went through Zomry, Difster and BoltClock's answers and didn't get anything. So I remembered some extra piece of information and decided to add it. The two categories are Lazy Opposites of each other. For example if one is called xyz, then the other is called non-xyz.
Probably you mean replaced elements (and non-replaced, respectively)?
However, the distinction between them is not so unambigous. For example, form controls were traditionally considered replaced elements, but the HTML spec currently explicitly lists them as non-replaced (introducing the "widget" term instead).
The HTML specification mentions for tags like <img> and <input> the following: Tag omission in text/html: No end tag.
Tags with an end tag are defined as: Tag omission in text/html: Neither tag is omissible.
So as far as I can find, the HTML spec does define a technical name for this, apart from void versus normal elements, so what Watilin pointed out in the comments should be fine: standalone vs containers.
As an added side-note: HTML has a lot more HTML content categories. You can find a complete overview at the HTML spec here: https://html.spec.whatwg.org/multipage/indices.html#element-content-categories
Also interesting to read to visualize that a bit better: https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories
Elements whose contents are defined by text and/or other elements between their start and end tags don't have a special category. Even the HTML spec just calls them normal elements for the most part in section 8.1.2.
Elements whose primary values are defined by attributes and that cannot have content between their tags are called void elements. img and input are indeed two examples of void elements. Note that void elements are not to be confused with empty elements; see the following questions for more details on that:
Are void elements and empty elements the same?
HTML "void elements" so called because without content?
<input type="text" id="someField" name="someField">
With an input selector, you can get a value from it like so (with jQuery):
$("#someField).val();
Where as with a paragraph or a div, you don't get a value, you get the text or html.
<div id="someDiv">Blah, blah, blah</div> You can get that with jQuery as follows:
$("#someDiv").html();
Do you see the difference?

How do I add two CSS rules to one html element

<p class="smallText">{{vehicleItem.registration}}, {{vehicleItem.colour}} {{vehicleItem.make}} {{vehicleItem.model}}</p>
I'd like to capitalize vehicle registration and model and make should be camel case
I will suggest wrapping registration and make with a span containing different classes e.g.
<p><span class="capitalize">{{vehicleItem.registration}}, {{vehicleItem.colour}} <span class="camel-case">{{vehicleItem.make}} </span> {{vehicleItem.model}}</p>
This way you are adding "two" css rules to one element. I also recommend you achieve the camelcase style using Javascript.
You can write as many classes into an HTML tag as you want, thereby applying as many CSS rules as you want. Example:
<p class="smallText myclass_1 myclass_2">
I'm not experienced with angular but you should be able to use different functions like
capitalizeFirstLetter(vehicleItem.registration)
and
camelize(vehicleItem.model)
Converting any string into camel case
How do I make the first letter of a string uppercase in JavaScript?

Can I store Markup within a HTML5 data-attribute tag?

I am wondering, if/how I can add Markup to a data-attribute tag? Like:
<i data-description="<h5>Head</h5><p>Content</p>">Foo</i>
I am using this info later on (from David Walsh) with:
i:hover::after{content: attr(data-description);}
And it outputs the Markup as plain text. Is there any chance I could use Markup-tags in a data-attribute though?
Text inside data attribute values will be interpreted like any other text in an attribute value. Markup will be parsed as normal for an attribute value.
You can store any text you like in the attribute. That can include content that you intend to have interpreted as markup in other places (watch out for & and " characters which will need representing as entities).
You cannot use markup in a CSS pseudo-element. This has nothing to do with where you get it from.

How do I customise the HTML Filter from Power-Mezz?

I'm experimenting with the HTML Filter module from the PowerMezz library and would like to customise the filter rules for a particular instance of the function. Is this possible?
For example, by default the style attribute is permitted, however I'd like to have this attribute stripped:
>> filter-html {<p style="color:red">A Para</p>}
== {<p>A Para</p>}
As well as limiting some other tags/attributes that are otherwise allowed.
After studying the filter-html module it looks like the immediate answer is no --- there appears to be no way to change the filter options for a particular instance.
After some experimentation, however, I discovered that you can make small change to make something like this possible. Most attribute handling can be customized by changing the attributes-map block, but inline style attributes are not handled in that block. They are dealt with specifically in the check-attributes function.
I commented out these lines in check-attributes which then causes all style attributes get stripped out by default:
if value: select attributes 'style [
append style value
]
You would need to add the ones you didn't want filtered back in to the specific html tags in attribute-map. I make a copy of the original attribute-map, make my changes, run filter-html, then revert back to the original before the next filtering instance.