Set input-suffix for certain input fields with CSS [duplicate] - html

This question already has answers here:
Can I use a :before or :after pseudo-element on an input field?
(22 answers)
Closed 8 years ago.
I am working on an input form, with different input fields. They all get an attribute with their form.
Eg:
<input class="input-text" form="price">
or
<input class="input-text" form="percent">
I would like to add a suffix with the pseudo element ::after but cannot figure out how.
Ive already tried this CSS:
input[form="price"]::after{
content: "€";
}
and this:
input::after[form="price"]{
content: "€";
}
The problem seems to be with the ::after itself, but i cannot figure out what it is.

Pseudo classes like after and before cannot work on input elements. Why so?
Because they work only on elements which can contain html markup. An input tag doesn't.
Robert Koritnik explained this quite good in this question.
There're other questions like that and like this:
CSS :after input does not seem to work
Add CSS content image after input

Clearly saying no you cannot do that in non container tags.
According to w3 standard :after or :before can be used in only container element.
So you will have to use javascript.
See specification http://www.w3.org/TR/CSS2/generate.html#before-after-content
But there is an alternative you can use contenteditable property which makes div editable & then you can use after tag. But contenteditable is introduced in html5.
Here is a js fiddle http://jsfiddle.net/madterry/W4Y58/ . Down side is you cannot use this as form field & it is not widely supported.

The problem is, that pseude elements are only supported on container elements, but not on allready replaced elements like images or input fields.
This is because they get rendered in the element itself, which is clearly impossible on input elements.
In the W3C specification it is even defined.

Related

What does "pseudo" mean in CSS? [duplicate]

This question already has an answer here:
What is it in a pseudo-element that makes the pseudo-element pseudo?
(1 answer)
Closed 6 years ago.
When I read about CSS and HTML I cross the word pseudo-elements.
I haven't found a good short explanation for what pseudo means. Could someone please explain this to me?
psuedo-elements allow you to style specific parts of an element. Some examples of pseudo-elements are:
::after
::before
These specific ones allow you to add style to just after, or just before an element.
for example:
.test {
background-color: gray;
}
.test::after {
content: ' some more text';
color: red
}
<div class='test'>
testing...
</div>
Here, we style the .test element normally
BUT, then we add a bit more after it using the pseudo-element selector ::after to let us add more text and change the colour.
You can read more and see more examples at https://developer.mozilla.org/en/docs/Web/CSS/Pseudo-elements
Supposed or purporting to be but not really so; false; not genuine:
— https://en.oxforddictionaries.com/definition/pseudo-
A pseudo-element is something that acts like an element, but is not an element.
In a word, "fake".
A more complete definition can be found here: http://www.dictionary.com/browse/pseudo
A pseudo element is a CSS-generated non-DOM element that is rendered as if it was a DOM element in the browser. But it doesn't actually add a node to the DOM. So if you inspected it in, say Chrome Dev Tools, you won't see it as a regular node.
Interestingly some screen-readers read pseudo-element content and others don't.

Does an HTML tag exist that is defaulted as an inline-block? [duplicate]

This question already has answers here:
HTML element which defaults to display:inline-block?
(10 answers)
Closed 8 years ago.
I'm well aware of applying display: inline-block; in CSS, but I'm curious if there is a HTML tag that displays as inline-block by default. Complementary to div & span.
div = block
span = inline
??? = inline-block
In the case that there is not a default tag, would be ok to create my own tag?
Ex)
<indiv></indiv>
indiv { display: inline-block; }
the only html elements with default style of inline block are button, textarea, input, and select . About creating your own tag, there are ways to do it, but think that most browsers will miss it.
Additionally, you can play with rarely used elements, like hr or i. Simply change the attributes for these elements and make them work as you want. This is very common in Bootstrap, where th <i> tag is used to display icons in the nav
By the way, can't understand why when you can simply add a class to any element, apply the inline-block style and be a happy man. But well, there goes the answer to your question.
Note: Marquee is also an inline-block element, but it's obsolete in HTML5. However, if you are one of those still using HTML4.x or XHTML, maybe it's of use

Add css elements inside "content" [duplicate]

This question already has an answer here:
Using :before and :after CSS selector to insert HTML [duplicate]
(1 answer)
Closed 8 years ago.
is there any CSS way to add div, p, span elements inside css content attribute?
I mean code like this
.textblockquote:before{
content: "<span class='green'>“</span>";
}
you won't be able to insert other things than text-element with css
BUT, what you want to do can be achieved this way :
.textblockquote:before{
color:green; /* <-- apply the styling you want */
content: "\0022"; /* <-- escaped unicode for 'quote' */
}
In the meantime, your question has already been answered (30 months ago): Using :before and :after CSS selector to insert Html
Look :
You can achive this with hexadecimal characters, but you shouldn't :)
See here: Adding HTML entities using CSS content
No, CSS is all about styling, not adding code.
You might be able to workaround this, but it's very bad practice.
It will probably be easier to achieve the requested effect or design in another way.
Its possible but its designed for text not html.
http://www.quirksmode.org/css/content.html,
Here is an example how you can achive this in Firefox. ( 2nd answer )
Insert HTML from CSS
You can add content as text for example, and customize it for you needs. In your case, you can add quotes in content of :before and :after elements, and absolute position them where you want.

Apply a class to a br tag? [duplicate]

This question already has answers here:
Can you target <br /> with css?
(16 answers)
Closed 7 months ago.
Is the following valid HTML?
<br class="something">
As an HTML element I can't see why it wouldn't be, but I don't think I've ever seen it in use.
Yes.
See the specification.
The class attribute applies to "HTML Elements" (which includes br elements).
One application I can think off is adding using it with pseudo-elements, such as :before or :after, for instance adding some text beneath a horizotal line:
hr.something:after { content: "Some text" }
Yes, is valid.
Specification tells that br accepts global and event attributes, and class is a global one.
Note that if you target HTML4 and below, there's an specific attribute for br named clear, which defines where to put the new line, as stated here, but now is deprecated and unless your DOCTYPE lets you, you should not use it anymore.
Yes, it's valid statement. you could use something like.
<br style="height: 100px; margin-top: 10000px;">
But instead using div element is recommended.
Yes you can, from the w3c specification : http://dev.w3.org/html5/markup/br.html
<br> element can make use of global attributes, and class is one of them.
It is valid in HTML 4.01, because the class attribute is allowed for the br element. It is also valid in HTML5 in HTML serialization, because the class attribute is allowed for all elements. It is not valid XHTML without a matching </br>.
Yes, you can add a class attribute to a <br> element. id as well if you want.
Sure, it's valid. A useful example would be if you wanted to visually add a little space after a line-break, without ending the paragraph. Or perhaps apply a background image. All sorts of styling options.
a br tag doesn't produce a CSS box and hence little can be done with it.
Only practical case is clear. i believe drupal used it at some time. interestingly CSS 1 spec. refrained from doing anything to br. http://www.w3.org/TR/REC-CSS1/#br-elements. no doubt applying some css on it doesn't invalidate the code but will cause little effect.
this https://stackoverflow.com/a/899359/1043824 is a good discussion on the topic.
For poetry in single line lyrics you can use br class="hanging" to cause the line to wrap only on a narrow screen such as a phone, but not on wider widths, thus preserving the line breaks of the poet, which really really matters to them, while still allowing text to flow freely, which matters to me
It does come handy when you want to omit the linebreak.e.g in a Headline when having a responsive layout and certain breakpoints.

Weird CSS :after pseudoselector issue in Chrome alone [duplicate]

This question already has an answer here:
Closed 11 years ago.
Possible Duplicate:
Combine CSS Attribute and Pseudo-Element Selectors?
I have a very different issue in Chrome. I used the pseudo selector :after to display asterisk mark on required field items. I used custom attribute 'required' to identify the labels which require asterisk symbol. It works fine in Firefox but in Chrome it behaves differently. All the fields including the not required ones now show asterisk symbol after corresponding label. The strangest fact is when I use Chrome developer tools to inspect the label, the asterisk symbol simply vanishes.
HTML:
<div class="labelbox">
<label data-required>Name</label>
<span class="float-right">:</span>
</div>
CSS:
label[data-required]:after {
content: "*";
color: red;
}
I'm seeing the same error, can't seem to figure it out. Might be a bug in chrome. Either way, I'd just use a class of required and use label.required:after as the selector. That seems to work properly.