Imaging this markup for a dialogue:
<p><q>Come here!</q> he said. <q>Why is taking you so long?</q></p>
Now, to punctuated this paragraph base on Spanish grammar, the output must be:
—Come here! —he said—. Why is taking you so long?
(Notice the position of the em-dashes, the spaces around them, and the period in the description.)
Is there a pure-CSS solution to output this without changing the HTML?
[In English, the quotation marks surround the spoken text. In Spanish, however, after the initial em-dash (with no spaces around it) the description is the one being surrounded, by two em-dashed with no spaces in the inside.]
You can sort of fake the quotation marks with some psuedo elements, taking care of deleting the last one.
p{font-size:1.5em;}
q:before{
content: "— ";
}
q:after {
content: " —";
}
q:last-of-type:after {
content: "";
}
<p><q>Come here!</q> he said. <q>Why is taking you so long?</q></p>
Moving the dot cannot be done with pure CSS, or I cannot think any way to do so atm. I believe you'll need to parse it either server-side or with some javascript
Edit:
Well, there might be a way, but this is ridiculously specific.
p{font-size:1.5em;}
q:before{
content: "—. ";
margin-left:-12px;
background:white;
}
q:first-of-type:before{
content: "—";
}
q:after {
content: " —";
margin-right:-4px;
}
q:last-of-type:after {
content: "";
}
<p><q>Come here!</q> he said. <q>Why is taking you so long?</q></p>
That's pulling the dashes towards the clarification (in a px based arbitrary magic number, which depends totally on the selected font and it's size), then using background-color (which should match the true background) to paint over the actual dot liquid paper style, and adding the dot after the dash on each quote start that's not the very first.
So as I said, ridiculously specific, and fragile. The moment you change the font, font-size or background-color, or simply have a clarification that doesn't end on ". ", it will break.
Related
I am studying a free css template called zerofour found at http://html5up.net/zerofour/, and running across a css coding that I have never seen before. In the HTML, some divs have class such as "4u", but when I check the css files, this is the only text section that has anything with those terms, and it looks like this:
/* Grid */
/* Cells */
.\31 2u { width: 100% }
.\31 1u { width: 91.6666666667% }
.\31 0u { width: 83.3333333333% }
.\39 u { width: 75% }
.\38 u { width: 66.6666666667% }
.\37 u { width: 58.3333333333% }
.\36 u { width: 50% }
.\35 u { width: 41.6666666667% }
.\34 u { width: 33.3333333333% }
.\33 u { width: 25% }
.\32 u { width: 16.6666666667% }
.\31 u { width: 8.3333333333% }
.\-11u { margin-left: 91.6666666667% }
.\-10u { margin-left: 83.3333333333% }
.\-9u { margin-left: 75% }
.\-8u { margin-left: 66.6666666667% }
.\-7u { margin-left: 58.3333333333% }
.\-6u { margin-left: 50% }
.\-5u { margin-left: 41.6666666667% }
.\-4u { margin-left: 33.3333333333% }
.\-3u { margin-left: 25% }
.\-2u { margin-left: 16.6666666667% }
.\-1u { margin-left: 8.3333333333% }
When I remove the 4u class using chrome developer, the page is affected. However, when I delete this section from the css file, nothing happens. I am quite stumped in this, and it is really bugging me!
Read this spec: http://www.w3.org/International/questions/qa-escapes#cssescapes. The characters following the back slash represent a unicode code point. The space is required if the next character is allowed as part of the hexadecimal values.
It looks like something similar to Foundation. I'm new to Html5up as well but that's my guess. How it normally works (in Foundation at least) you have a "row" which is the entire width of your page (normally). Within that row you have columns (or "u" here for some reason), with each column taking up the same % of width. Usually the standard for Foundation is 12 columns/row and I'm guessing its the same here. So basically if you want the first 50% of a row to be a giant div followed by two divs that split the remaining 50% it would look like:
<div class="row">
<div class="6u">
Big Div Here.
</div>
<div class="3u">
Small Div Here.
</div>
<div class="3u">
Small Div here (same size as the other small div)>
</div>
</div> (This ends the row).
The reason for all this madness being it makes it way easier to make your page responsive (which is one of the main points of Foundation and HTML5Up).
Looking into Foundation's Dev Docs for a more in-depth explanation and additional examples (despite it not necessarily being Foundation) - Here
It's the first time that I see class names like this and I wondered about the meaning. The W3C page says:
In CSS 2.1, a backslash (\) character can indicate one of three types
of character escape. Inside a CSS comment, a backslash stands for
itself, and if a backslash is immediately followed by the end of the
style sheet, it also stands for itself (i.e., a DELIM token). First,
inside a string, a backslash followed by a newline is ignored (i.e.,
the string is deemed not to contain either the backslash or the
newline). Outside a string, a backslash followed by a newline stands
for itself (i.e., a DELIM followed by a newline).
Second, it cancels the meaning of special CSS characters. Any
character (except a hexadecimal digit, linefeed, carriage return, or
form feed) can be escaped with a backslash to remove its special
meaning. For example, "\"" is a string consisting of one double quote.
Style sheet preprocessors must not remove these backslashes from a
style sheet since that would change the style sheet's meaning.
Third, backslash escapes allow authors to refer to characters they
cannot easily put in a document. In this case, the backslash is
followed by at most six hexadecimal digits (0..9A..F), which stand for
the ISO 10646 ([ISO10646]) character with that number, which must not
be zero. (It is undefined in CSS 2.1 what happens if a style sheet
does contain a character with Unicode codepoint zero.) If a character
in the range [0-9a-fA-F] follows the hexadecimal number, the end of
the number needs to be made clear. There are two ways to do that:
with a space (or other white space character): \26 B (&B) [...]
Note: Backslash escapes are always considered to be part of an
identifier or a string (i.e., \7B is not punctuation, even though
{ is, and \32 is allowed at the start of a class name, even though
2 is not). The identifier te\st is exactly the same identifier as
test.
So as far as I can understand, the \3+number+space part here is used to be able to use numbers only as class names.
html5up.net uses a framework called skel to make the layouts responsive.
If your question is "how do I make sense of these classes" rather than "how do these escape sequences work", then the reference you're looking for is at https://github.com/n33/skel/blob/master/docs/skel-layout.md#usage-1.
I think this type of css is used for mobile Compatibility.
For print styles, I am currently printing the url after the text.
Is it possible to have it appear on the next line instead of next to the text?
This is what I have so far.
a:after {
content:" (" attr(href) ")";
}
Result:
Email me(hello#email.com)
Want this instead:
Email me
(hello#email.com)
Example: http://jsfiddle.net/qesRk/
Try this -
a:after {
font-style: italic;
content: "\A and some text after."; white-space:pre;
}
Demo
You could display: block; it, like on this JSFiddle
There are various ways to make the :after pseudo-element start on a new line, as shown in other answers. But the example in your question says that the desired rendering is
Email me
(hello#email.com)
This cannot be achieved using just CSS if the the purpose is to that the address from the href attribute of a link. The reason is that a working href value would have to start with mailto:, and you cannot omit anything from the attribute value when using constructs like attr(href). What you can achieve is
Email me
(mailto:hello#email.com)
For this, given the markup Email me, you would use
a:after {
content: " (" attr(href) ")";
display: block;
margin-top: 1.2em;
}
assuming that you want an empty line too, as in your example. Replace 1.2 by the line-height value you are using.
P.S. This sounds unnecessarily complicated anyway. Using just the email address in content, optionally wrapped inside an a href element, would suffice, both on screen and on print. (On printing, you would normally want to suppress underlining of links, but that’s a general issue.) If you were thinking of preventing email address harvesters from getting the address from the content, putting the address into an attribute does not help much (they are easily processed by harvesters).
I want to capitalize the first letter of sentences, and also the first letter after commas if possible. I want to add the code in here:
.qcont {
width: 550px;
height: auto;
float: right;
overflow: hidden;
position: relative;
}
You can capitalize the first letter of the .qcont element by using the pseudo-element :first-letter.
.qcont:first-letter{
text-transform: capitalize
}
This is the closest you're gonna get using only css. You could use javascript (in combination with jQuery) to wrap each letter which comes after a period (or comma, like you wish) in a span. You could add the same css as above to that span. Or do it in javascript all together.
Here's a snippet for the css approach:
.qcont:first-letter {
text-transform: capitalize
}
<p class="qcont">word, another word</p>
This cannot be done in CSS. The text-transform property makes no distinction according to the placement of a word inside the content, and there is no pseudo-element for selecting the first word of a sentence. You would need to have real elements, in markup, for each sentence. But if you can do that, then you could probably just as well change the initial letters to uppercase in the content proper.
Capitalization at the start of a sentence is a matter of orthography and should be done when generating the content, not with optional stylistic suggestions (CSS) or with client-side scripting. The process of recognizing sentence boundaries is far from trivial and cannot in general be performed automatically without complex syntactic and semantic analysis (e.g., an abbreviation ending with a period may appear inside a sentence or at the end of a sentence).
If you need to capitalize the first letter in contenteditable container you can't use the css property
#myContentEditableDiv:first-letter {
text-transform: capitalize;
}
because when you try to delete a letter automatically you will delete all the text contained in the contenteditable.
Try instead the example provided by sakhunzai in https://stackoverflow.com/a/7242079/6411398
for a working solution.
text-transform:capitalize; will capitalize the first letter of a sentence, but if you want to also do it for commas you will have to write some javascript. I agree with #BoltClock, though. Why on earth would you want to capitalize after a comma?
Edit: For the sake of readers: text-transform:capitalize; will capitalize each word of a sentence, not the first one only.
You must use the :first-letter CSS selector with the above.
I'm trying to find some uptodate info about various possible uses for content: property in css but only find stuff in the ancients dungeons of the web dating from 2004 orso so I thought I have to ask this in 2011 again:
p:before {
content: url(dingdong.png);
}
p:before {
content: "some text ";
}
I'm very new to both the :before selector as well as the content: property and heard of it accidentally on this question which was answered very creatively by a lovely lady:
How to set Bullet colors in UL/LI html lists via CSS without using any images or span tags
Only to find out that some problems might occur concerning the actual encoding of the content:
li:before{ content: "■"; } How to Encode this Special Character as a Bullit in an Email Stationery?
And so my concrete question is: besides url() and "text", are ther other possibilities?
Thanks very much for your suggestions and ideas.
Oh, too many to list. Some of the most common cases are:
Special numbering, with the counter() function, along with the counter-reset and counter-increment properties
Pure CSS clearfix with:
.foo:after {
content: "";
display: block;
clear: both;
}
Display attributes, eg to print URLs for hyperlinks in a print stylesheet
a[href]:after {
content: ' (' attr(href) ') ';
}
Add typographic ornaments that shouldn't be in the HTML because they're presentational. For example, in my blog, I've used it for the ornaments between posts or sidebar links.
Add icons to hyperlinks, depending on where they point, like
a[href^="http://twitter.com/"]:before {
content: url('twitter-icon.png');
}
Adding a pointer to make a CSS-only speech bubble:
.bubble {
position: relative;
background: silver;
}
.bubble:after {
content: "";
border:10px solid transparent;
border-top-color:silver;
position: absolute;
bottom:-20px
}
And many, many other.
Just beware: If something is not presentational, it should probably be in your HTML. Users will not be able to select CSS generated content, and screen readers will ignore it.
You can also use a counter.
See http://www.w3schools.com/css/tryit.asp?filename=trycss_content_counter
You can also display a certain attribute of the element selected.
See http://jsfiddle.net/EcnM2/
You can also add or remove opening and closing quotes.
w3schools content property list: http://www.w3schools.com/css/pr_gen_content.asp
Generated content won't be perceived by screen readers so beware of accessibility issues.
content is very useful but there are cases where this text should be in the HTML code because it conveys information and isn't only decorative (a bit like background images in CSS vs informative img with a non-empty alt attribute)
:after and content can be used as a clearfix with no extra div
:before and :after bring multiple backgrounds (up to 3 w/ the element itself) to browsers that don't understand the CSS3 feature.
EDIT: forgot about Eric Meyer's article in A List Apart about printing the href attribute of links along with their text with the help of content (it was followed by a JS improvement, fyi)
I really dislike "smart quotes" for one simple reason - when I copy text containing them, it no longer has the original "" as was typed, instead I end up with Unicode symbols.
The smart quotes are a visual improvement, so shouldn't really be "baked into" the text, so.. I was wondering, it is possible to display the smart quotes using CSS?
Basically, the text would be displayed as..
This is an “example”
..but viewing the source, or copying and pasting would show:
This is an "example"
In theory HTML has <q> element to solve that problem.
Unfortunately in practice you'll get either no quotes copied at all (IE doesn't support it, Gecko doesn't copy quotes) or smart quotes copied.
If you style the "s with font-style: italic they appear to closely mimic the smart-quotes, but I'm not sure that you'd be any happier surrounding each and every instance with <em> and </em>.
.magic-quotes {font-style: italic; }
<span class="magic-quotes">"</span>quoted-text<span class="magic-quotes">"</span>
Or, possibly if you use the :before and :after psuedo-classes,
.stuff-to-magic-quote:before
{content: '"';
font-style: italic; }
.stuff-to-magic-quote:after
{content: '"';
font-style: italic; }
<span class="stuff-to-magic-quote">this text would be quoted</span>.
But then you're not going to get the quotes in the copy & paste.
I think you might need some form of JS to achieve what you want; to style the quotes automatically, and allow for their being copy & pasted in non-magic-quoted format.
Edited to add that I share your dislike of magic-quotes and their copy & paste issues. And later edited to amend the heinous <em> tags, and make them, instead, <span>s.
...it occurs to me, now, that perhaps you could go a little further, but it might be too much typing for too little -real- reward.
.original-quotes-open {margin: 0 -2em 0 0;
z-index: 0; }
.original-quotes-close {margin: 0 0 0 -2em;
z-index: 0; } /* the idea of the -2em and z-index is to position the original non-magic quotes behind the text, but not remove them from the document */
span.quoted-text {z-index: 2; /* or higher than the .original-quotes... classes */
span.quoted-text:before {content: "“"; }
span.quoted-text:after {content: "”"; }
<span class="original-quotes-open">"</span><span class="quoted-text">This text is quoted</span><span class="original-quotes-close">"</span>
But, honestly, I'm not seeing a positive outcome from the extra effort.