I'd like to style niqqud characters inside html differently than the letter.
Suppose I'd like to have Hebrew letter Bet black while Dagesh in it green.
How can this be made in html+css?
This doesn't do the task:
<div style = "font-size: 500%">
<span style = "color: black">ב</span><span style = "color: red">ּ</span>
</div>
It results in : http://jsfiddle.net/nv7ja459
(link with bigger font: http://jsfiddle.net/nv7ja459/1/)
So the dagesh is no more inside the letter.
Link to screenshot https://drive.google.com/file/d/0B4SYIrNV4hXYZ0ZyWXZnZWg4OGc/view?usp=sharing
The main issue here is that when you wrap the dagesh, niqqud or other diacritic in a span (to style it) - the browser no longer knows which consonant it was attached to.
Because of this, it cannot position it correctly. For example, vav is much narrower than shin. Let's say the browser positions qamats 5px to the right when attached to a vav and 10px to the right when attached to a shin. When you wrap qamats in a span the browser does not know which consonant it is attached to and therefore does not know how far to move it to the right. So it just gives up and doesn't move it to the right at all. Hence, why, when you wrap vowels, etc in a span the position is messed up.
You can color different letters differently without messing up positioning as long as each consonant is inside the same span as any any attached vowels / diacritics. You can also color the first letter (including its vowel) differently using the ::first-letter CSS selector.
Finally, you can use a layering approach as discussed in Jukka's answer when a consonant and its attached diacritics need to be colored differently. I have added a more thorough example to my code snippet.
I tried with SVGs to see if they offered a better solution. But SVG's suffer from the exact same problem.
PS Can you spot the deliberate spelling mistake in shalom? :D (AKA I cannot be bothered to fix it)
.example-one {
font-size: 100px;
}
.example-one .one {
color: red;
}
.example-one .two {
color: green;
}
.example-one .three {
color: pink;
}
.example-one .four {
color: blue;
}
.example-two {
font-size: 100px;
}
.example-two::first-letter {
color: orange;
}
.example-three-a, .example-three-b {
font-size: 100px;
position: absolute;
right: 0;
}
.example-three-a {
color: red;
z-index: 1;
}
.example-three-b {
color: green;
}
<div class="example-one" dir="rtl">
<span class="one">שָׁ</span><span class="two">ל</span><span class="three">וּ</span><span class="four">ם</span>
</div>
<div class="example-two" dir="rtl">שָׁלוּם</div>
<div class="example-three-a" dir="rtl">שלום</div>
<div class="example-three-b" dir="rtl">שָׁלוּם</div>
The example is displayed in different ways in different browsers, depending on many things including the font(s) used. For example, in my test on Win 7, Firefox shows a bet with dagesh in all black, whereas Chrome and IE show a black bet with a red dagesh that is badly or very badly displaced.
There is no reason why your approach would not work. Neither is there any specification requiring that it should work. Browsers (and other rendering software) can display the combination using a single precomposed glyph, in which case the glyph will obviously be in one color. They can also display the base character and the diacritic mark separately; this could result in the desired rendering, but positioning a diacritic mark is a real challenge, and browsers often fail.
This means that you need a trick of some kind.
A relatively simple trick is to have content that has both the base character (bet in this case) and a combination of the base character and a diacritic mark (here dagesh), set different colors on them, and superimpose them so that the base character is topmost. The main objection is logical: the document then contains the base character appearing with no reason (except the visual rendering). Assuming this is acceptable, here’s how to do it:
[Code edited Dec 16, 2020, to make both of the inner elements absolutely positioned.]
<style>
.colcomb { position: relative }
.colcomb .base, .colcomb .combined { position: absolute; left: 0; top: 0; }
.colcomb .base { z-index: 200; }
.colcomb .combined { z-index: 100; }
.colcomb .combined { color: red; }
</style>
<div style = "font-size: 500%">
<span class="colcomb">
<span class="base">ב</span>
<span class="combined">בּ</span>
</span>
</div>
This will work:
<font color='green' size='12'>ּ</font><font color='black' size='12'>ב</font>
tested on chrome and firefox, if its red you want the dot instead of green just change the green to red
the font size is at 12 just to make it visible, you can remove that also
http://i.imgur.com/smkx3MN.png - Screenshot for how it looks for me
Related
I'm trying to do somewhat of the opposite of the <q> tag. The q tag visually displays quotes in the web page, but if you copy paste the text, the quotes are not present in the pasted text. I want the opposite - no visual quotes in the web page, but quotes are present in the copy pasted text.
Why? Because I sometimes prefer to use other visual styles in my webpage instead of quotes. But when a user copies the text, since I cannot rely on them pasting the text into something capable of preserving the rich formatting/styles, I wish to revert to using quotes because they're simple ascii characters which will work in any plain text context.
I'll give a concrete example to help clarify.
Given:
.qq { background-color: yellow; }
I am <span class=qq>some quoted</span> text.
When the user views the page, they should see:
But if they were to copy the text and then paste it somewhere, the pasted text would be:
I am "some quoted" text.
Is it possible via just css? I'd prefer not to use js.
I don't really care what the html/css needs to be, so if quotes, or the q tag etc... need to be present in the html source instead of a span, that's totally ok.
The only way I can think of without JS is to put the quotes in the markup and hide them using CSS. The markup will get a bit messy though. Something like:
.lq,
.rq {
font-size: 0;
color: transparent;
}
I am <i class="lq">“</i>some quoted<i class="rq">”</i> text.
using JS you can do this way
window.addEventListener("copy", (e) => {
event.preventDefault();
const selection = document.getSelection();
let selectedText = selection.toString();
let selectedTextWithQuotes = `"${selectedText}"`;
// FOR SAVING IN CLIPBOARD
event.clipboardData.setData("text/plain", selectedTextWithQuotes);
});
Using only css you could use transparent double quotes:
.qq { background-color: yellow; }
quote {
display: inline-block;
width: 0px;
color: transparent;
}
I am <quote>"</quote><span class=qq>some quoted</span><quote>"</quote> text.
UPDATE
A not recommended alternative. It is compatible with 75% of browsers. (I'm referring to the # font-face: size-adjust property), but it's an alternative.
For the main font you create a character set that includes only the double quote, but with the size-adjust property at 0%. The remaining text will be rendered with the secondary font.
I am "some quoted" text.
#font-face {
font-family: 'myFont';
src: url(https://fonts.gstatic.com/s/crimsonpro/v23/q5uUsoa5M_tv7IihmnkabC5XiXCAlXGks1WZzm1MP5s-.woff2) format('woff2');
unicode-range: U+0022;
size-adjust: 0%;
}
.yourBody {
font-family: myFont, 'courier new';
}
.qq { background-color: yellow; }
<div class="yourBody">
I am "<span class=qq>some quoted</span>" text.
</div>
.quote-character-left {
margin-right: -0.5em;
opacity: 0;
}
.quote-character-right {
margin-left: -0.5em;
opacity: 0;
}
.quote-text {
display: inline;
background-color: yellow;
}
<p>I am <span class="quote-character-left">"</span><span class="quote-text">some quoted</span><span class="quote-character-right">"</span> text.</p>
I have this simple html code:
span{
outline: none;
}
hello
<span contenteditable="true">
world
</span>
And I noticed that every time I press ENTER in the contenteditable span, the cursor goes to a new line as expected, but when pressing backspace the cursor doesn't go to it's original place, it moves more to the left + up, and only when pressing backspace again, it goes to the original place:
Is this a bug? Are there any workarounds?
Thanks
When using the Chrome debugger you will notice that upon pressing enter there are two line breaks generated within the span. As you noticed only when pressing backspace for the second time you delete the second linebreak which probably is the reason for the spacing irregularity you're expiriencing.
As far as i know this is normal since line breaks interact with whitespace in some way
Edit: I spent quite some time playing around with this and it turns out contrary to what you assumed there are three positions for the coursor:
With text present in the contenteditable span the coursor aligns with its content box
Without text and a line break present after it the coursor aligns with the previous text
Without text nor a line break the coursor sits slightly below the content box of your span for some peculiar reason.
Why all this happens, sadly i have no idea but hopefully you can use this information to your advantage
Edit 2: Found out where the coursor goes in the 3rd case namely it snaps to the bottom of the parents content box in your case that would be the body element
Here's the bit of code I made for you to see that for yourself:
span[contenteditable="true"] {
outline: none;
background-color: red;
border: 2px solid blue;
line-height: 2em;
}
span.first {
font-size: 0.8em;
border:2px solid violet
}
br{
border: 2px solid green;
}
body {
font-size: 10rem;
border: 2px solid aqua
}
<!DOCTYPE html>
<html>
<body>
<span class="first">
hello
</span>
<span contenteditable="true"> world </span>
</html>
Finally, I have managed to trick the browser using ZeroWidthSpace character which always being inserted to the start of the element's innerHTML. As far as I understand, the bug(?) only occurs if there is no text in the element so inserting a 'non-text' character solved it.
Here's a snippet I made using custom Web Component that automatically fixes the problem:
class CeElement extends HTMLElement {
constructor() {
super();
}
connectedCallback(){
this.addEventListener("input", function() {
if(!this.innerHTML || this.innerHTML==0) {
this.innerHTML = "";
}
}, false);
this.innerHTML = "" + this.innerHTML;
this.contentEditable = true;
}
}
window.customElements.define('ce-element', CeElement);
ce-element{
outline: none;
}
<span style="white-space: pre;">hello </span> <! -- the span is only for the saving the space with 'white-space: pre;' -->
<ce-element>
world
</ce-element>
I have set the placeholder color of an element in a HTML page to be red by the following code I acquired from here as the following:
.warningPlaceHolder::-webkit-input-placeholder {
color: #CC3300;;
}
.warningPlaceHolder:-moz-placeholder {
color: #CC3300;;
}
.warningPlaceHolder::-moz-placeholder {
color: #CC3300;;
}
.warningPlaceHolder:-ms-input-placeholder {
color: #CC3300;;
}
This works fine in chrome, firefox, and IE when I have a simple page, but it does not take effect in IE when I use it inside my main application which contains lots of other elements and styles. When I inspect the element in IE, I see the following in the computed styles:
as you see above it crossed out the placeholder color. I am not sure whether IE really ignored this or this is a bug! but in either case what matters is that it does not seem to really take effect!
The bellow is my HTML element that has assigned the class warningPlaceHolder as well as some other element:
<input class="gwt-SuggestBox pick-list warningPlaceHolder" id="authorizationNumberSuggestBoxsuggestBox" type="text" maxlength="30" placeholder="This Field is Required">
Question: What could cause IE ignore my placeholder color?
ps. I have other classes in the css of the document that they set the placeholder property; however, I simply expect that the closest class assigned to an element should take precedence. shouldn't it?
I am trying in IE version 11.
It's not pretty, but have you tried
warningPlaceHolder:-ms-input-placeholder {
color: red!important;
}
You are missing the (.) in your CSS
.warningPlaceHolder::-webkit-input-placeholder {
color: red;
}
.warningPlaceHolder:-moz-placeholder {
color: red;
}
.warningPlaceHolder::-moz-placeholder {
color: red;
}
.warningPlaceHolder:-ms-input-placeholder {
color: red;
}
Try this. It works fine for me.
Here's a Demo
I have some code which displays images from imgur.
When hovering over an image, I want the title attribute to appear at the top of the image.
I have achieved all of this, but when the text becomes visible, it only appears on one line and writes over itself when it runs out of space, as in the image.
I would like the text to start on a new line once it reaches the end of it's container.
I have tried adding word-wrap: break-word; to each of the CSS selector below, as well as to a P selector (as the link is wrapped in a p-tag).
Any advice on how to resolve this is much appreciated!
I have the following html:
<section id='photos'>
<p>
<a class='hovertext' href='http://i.imgur.com/gallery/eWlGSdR.jpg' title='Opened my window shade while flying over Japan, noticed a volcano was erupting. (OC) [2448x2448]'>
<img src='http://i.imgur.com/eWlGSdR.jpg' alt=''>
</a>
</p>
And the following CSS:
a.hovertext {
position: relative;
text-decoration: none !important;
text-align: left;
}
a.hovertext:before {
content: attr(title);
position: absolute;
top: -1;
padding: 0.5em 20px;
width: 90%;
text-decoration: none !important;
color: red;
opacity: 0.0;
}
a.hovertext:hover:before, a.hovertext:focus:before {
opacity: 1.0;
}
As Dinesh said in the comments, this was caused by poor code awareness, as elsewhere in the code, I was calling 'line-height:0;' on the #photos element.
Removing this solved the problem.
i think you coul use some java script on this, if you only want to make it add a extra line to it, correct me if im wrong.
Here's an example what i think you mean:
First add this text next your class="hovertext" :
id="HoverText"
Add this part after your body or paste the code between script into a .js file and call it with
<script src="filename.js"></script>
<script>
HoverText=document.getElementById("HoverText");
HoverText.onclick=function(){ClickToShowText()};
function ClickToShowText(){
HoverText.innerHTML+="<br>New line with text";
}
</script>
just use the break tag at the end of the text that's supposed to be on the first line.
</br>
easy
I need to create an HTML text input element that features multicolored placeholder text. All of the text should be gray except, but a closing asterisk should be red, as in:
This strikes me as a seemingly simple task that is actually a lot more complicated because of how browsers restrict our ability to style native input elements.
I have heard of people using CSS to override native input styles so they can use custom fonts, etc., but is there away to have two special text styles (gray and red)? Or do I need to use an alternative (non-native) input?
Try something like this: http://jsfiddle.net/vmuJm/
The trick: address the placeholder text, add a "required" class to required inputs, and use the :after pseudo element to add an appropriately colored asterisk.
[EDIT] It looks like this is only working for Webkit browsers.
I have a rather fun way to do this and seems to work great in all browsers.
(Works fine in IE 8+, chrome, and Firefox.)
What I am doing is using the spans I put inside of the label to act as the value text.
Here is the html structure,
<label><span class="title">Name<span class="symbol">*</span></span>
<input type="text" />
</label>
The css,
label {
position: relative;
}
label:hover span {
display: none;
}
input[type="text"]:focus, input[type="text"]:active {
z-index: 2;
}
label input[type="text"] {
position: relative;
}
.title {
color: gray;
position: absolute;
left: 5px;
top: 1px;
z-index: 1;
}
.symbol {
color: red;
}
Last here is the jQuery I wrote to not allow the span to hover over your input if the input is filled in.
$('input[type="text"]').blur(function() {
if( $(this).val().length >= 1) {
$(this).toggleClass('active');
}
else {
$(this).removeClass('active');
}
});
Here is a JSFIDDLE to play with.