IT.COM

Is it possible to apply CSS to half of a character/word?

NameSilo
Watch

protekconsulting

New Member
Impact
0
Is it possible to apply CSS to half of a character/word?
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Not that I know of...but you'd be surprised with what kind of crazy tricks people are doing with CSS nowadays. Google it and if you have already and didn't find a solution, it's likely that even if it does exist it may not be broadly supported.
 
0
•••
yes, but only by modifying the HTML. Just wrap the text you wish to affect in inline tags, such as a <span>:

So in the HTML: someword becomes

some<span="red">word</span>

And then in the CSS you can reference the class name red or whatever you wish:

.red {color:#f00;}
 
0
•••
You can use @Dominium example to apply for half of word. There is no css available for half of a char
 
0
•••
You could use javascript, or as has been said, modfiy your word /sentence to break it up using a span.
 
0
•••
I would avoid using java, as it's blocked on most of the PCs, CSS is much better
 
0
•••
Java is not the same thing as JavaScript, and JavaScript is not blocked by most browsers.

In fact, 90% of websites use JavaScript: (see: w3techs.com/technologies/details/cp-javascript/all/all)
 
0
•••
In my opinion, it's better to keep pages as simple as possible. There was a simple task in this question, and CSS will work like a charm, with no need in any OOP.

... and, no, many users disable java / javascripts by default. This is just wise :)
 
0
•••
I get your point, but in order to eliminate misinformation, we should be aware that only approx. 1% of users aren't able to support JavaScript in their browsers :)

Source: gds.blog.gov.uk/2013/10/21/how-many-people-are-missing-out-on-javascript-enhancement/
 
0
•••
This one per cent of users (that 'are not able to support') could be potential customers... Again, if the finding is right, and there is such a low percentage of UK users, people are probably just unaware about vulnerability? I keep it off, so my customers do, and I think we loose nothing. That's up to a webmaster (or what's more right - up to his client) what to choose. If this lad asks about CSS - he needs CSS / HTML solution for a reason.
 
0
•••
Yes, I agree with you that CSS is the best approach for this scenario.

I don't think you want to use JavaScript for everything, but if it's non-critical and the page would work gracefully and acceptably in cases where JavaScript is disabled then I think that's fine. JavaScript is very much on the rise with frameworks like Node and Angular surging in popularity.
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back