This question concerns using the CSS counter feature in HTML5 inside a list (e.g. <ul>).
Given this in the .css file:
body {
counter-reset:figCounter;
counter-reset:figRefCounter;
counter-increment: figRefCounter;
}
.caption {
counter-increment: figCounter;
}
.figNumber:before {
content: "Figure";
}
.figNumber:after {
content: counter(figCounter);
}
The example below works correctly, that is, the divs generate "Figure 1" and "Figure 2" respectively:
<div class="caption">
<p><span class="figNumber"> </span>: First Caption</p>
</div>
<div class="caption">
<p><span class="figNumber"> </span>: Second Caption</p>
</div>
On the other hand, the counter does not increment -- both divs end up generating "Figure 1" -- if I put the first div inside a list, like so:
<ul>
<li>
<div class="caption">
<p><span class="figNumber"> </span>: First Caption</p>
</div>
</li>
</ul>
<div class="caption">
<p><span class="figNumber"> </span>: Second Caption</p>
</div>
How can I get the counter to increment inside a list, so that the second div generates "Figure 2" like it does without the list?
When using multiple Counter-resets, you should define them in one line:
body {
counter-reset:figCounter, figRefCounter;
counter-increment: figRefCounter;
}
jsFiddle
Note it is not neccesary to increase the counter at the body, it will be one by default for the first time
Your code as is working just fine.
See this fiddle: http://jsfiddle.net/SrewW
Moreover, if you make the list-style-type to none, then it looks seamless:
See this fiddle: http://jsfiddle.net/SrewW/1/
Result in both cases:
1 : First Caption
2 : Second Caption
And,
If you remove the trailing comma after .figNumber:before, then the result is like this:
Figure 1 : First Caption
Figure 2 : Second Caption
See this fiddle: http://jsfiddle.net/SrewW/2/
Update: (Moving the comments here for easy ref)
You do not actually need to put colons and spaces in your html markup. Also, you do not need counter-increment on caption. You can do that on your fignumber span itself.
Please understand the counters. This link will help you: https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Counters
You can have many counters. You can reset them anywhere, but safe would be to reset in body. But you increment those on an element where you want to show the counter.
Please see this fiddle for reference: http://jsfiddle.net/m6u6a/4/
For example:
body {
counter-reset: figCounter 10 figRefCounter 0;
}
.figNumber:before {
counter-increment: figCounter 2;
content: "Figure " counter(figCounter) ": ";
}
Here, figCounter is initialized to 10 and figRefCounter is initialized to 0 in body. However, on the span with class figNumber, the figCounter is incremented to 2 and displayed with supporting text in the:before` pseudo-class.
The result:
Figure 12: First Caption
Figure 14: Second Caption
Hope that makes it clear to you.
Related
Maybe this is not possible in CSS3 but I'm trying to automatically insert comma separators when there is multiple consecutive instances of footnotes within a paragraph.
The problem occurs when there is another footnote later on in the paragraph. You'll notice in Example 2 that the comma get's inserted after Footnote 2.
I've tried to switch it around and use first-child but this just ends in a reverse of the same problem.
sup:not(:first-child)::before {
content: ",";}
sup:last-child::before {
content: "";
}
Anyone know of a way to target the last-of-type when it's succeeded by any other content other than another of the same type?
sup:after {
content: ",";
}
sup:last-of-type:after {
content: "";
}
<h2>Example 1</h2>
<p>lorem upsum<sup>1,2</sup></p>
<h2>Example 2</h2>
<p>lorem upsum<sup>1,2</sup> flotsam jetsum<sup>3</sup></p>
You already have the answer: all you need to do is remove ALL your CSS as it's practically doing nothing.
sup:after {
content: ",";
}
sup:last-of-type:after {
content: "";
}
In your html, your code is <sup>1,2</sup> , which means you are already manually inputting the , for multiple values within <sup>.
That particular , within a <sup> with multiple values is not being generated by the above CSS but rather, is there only because you are manually typing it in.
In a <p> with only a single <sup>, the reason why it does not have a , is because of your class sup:last-of-type:after. Since that there is only a single instance of <sup> it is considered the last one too, thus, it adds content of "" to the end of it. Which once again is doing nothing since by default it's empty.
<h2>Example 1</h2>
<p>lorem upsum<sup>1,2</sup></p>
<h2>Example 2</h2>
<p>lorem upsum<sup class="sup-multiple">1,2</sup> flotsam jetsum<sup>3</sup></p>
I have to make text wrap convert into into two line and ellipse will add if the text is more than two line.
Currently it's wrap in multiple line and view look so weird.
What i have done so far in css:
<div class="list card item-text-wrap" ng-click="getNewsDetail(new)">
<a class="item item-thumbnail-left" href="#">
<img src="http:{{new.thumbnail}}">
<h2>{{new.summary}}</h2>
<p style="padding: 0;">{{new.date | date:'EEE, MMM d yyyy'}} {{new.date |
date:'shortTime'}}</p>
</a>
</div>
This is work perfectly when text length is short but i want to make it consistent in two line and rest of part is append with dot(...).
Any help would highly appreciate.
So you cannot accomplish this using only CSS because you must use white-space: nowrap; to be able to use text-overflow: elipsis; and nowrap will not let the words wrap down multiple lines.
Here is a similar question with a Jquery solutions: CSS word ellipsis ('...') after one or two lines
Here is a page dedicated to different version of text-overflow and the different ways to handle it: http://dotdotdot.frebsite.nl/
You are going to need JQuery to do this, but luckily you gain a lot of control and may find a better visual design rather than the ellipsis.
Of course, apply any styles to the parent elements holding the text.
e.g.
<!-- HTML -->
<!-- Give class of "date" -->
<p style="padding: 0;" class="date>{{new.date | date:'EEE, MMM d yyyy'}} {{new.date | date:'shortTime'}}</p>
// Jquery
if ($('.date').height() > 50) {
var words = $('.date').html().split(/\s+/);
words.push('...');
do {
words.splice(-2, 1);
$('.date').html( words.join(' ') );
} while($('.date').height() > 50);
}
I've searched for this but I couldn't find anything similar to my problem.
Basically what I have is a counter called page and I'm setting up a page counter like this:
content: "Page " counter(page);
that is displayed like this on screen -> Page 1
Everything is working fine, but what I need is to set the page counter to start from 0 instead of 1
I'm using a Wiki (confluence) and I don't have access to where page is defined, because it's just a variable meant to be used for CSS counters like before.
I tried to following, but with no luck at all:
content: "Page " counter(page) - 1;
content: "Page " counter(page - 1);
content: "Page " calc(counter(page) - 1);
I've also tried to prepend counter-reset:
counter-reset: page -1;
content: "Page " counter(page);
Now my question is, can I set the counter to start from 0 without using any counter-reset property? Or, in the previous example where I actually tried to use the counter-reset, did I make any mistake? Am I missing something?
If you have landed on this page looking for help on usage of CSS counters with the confluence tool, please make note of the comment by Nick:
I wrote a thread in confluence support forum, but apparently what I want to do it's not possible.
Here is one way to make it start from 0 without using counter-reset: [counter-name] -1. Basically what we are doing is incrementing the counter only from the second occurrence of the div class='page' so that the counter value for the first instance always remains 0.
counter-reset does not seem to be a mandatory property*. When there is no reset mentioned, 0 is taken as the default value and the below code still works.
* - Can't find any reference in W3 docs or in MDN that counter-reset is optional but browsers seem to support it.
body {
counter-reset: page;
}
.page:before {
content: "Page " counter(page);
}
.page ~ .page {
counter-increment: page;
}
<div class="page"></div>
<div class="page"></div>
<div class="page"></div>
<div class="page"></div>
I have posted the above only for a sample and I don't think it is the correct way to do it. The recommended approach would be the below where while resetting the counter, we set the start value as -1.
body {
counter-reset: page -1;
}
.page {
counter-increment: page;
}
.page:before {
content: "Page " counter(page);
}
<div class="page"></div>
<div class="page"></div>
<div class="page"></div>
<div class="page"></div>
Create a var called Time or whatever, it will be your last number showed on your Timer, then after restart check the var and if it is 9 or the number before the restart number, then set the showing number to 0
This question already has answers here:
CSS data attribute new line character & pseudo-element content value
(5 answers)
Closed 9 years ago.
I have CSS that is using Data Description to display text on a page.
Code:
CSS
#nav a:after {
text-align:center;
content: attr(data-description);
display: block;
}
HTML
<li><a data-description="The Thinking Man,The Artist, The Philosopher" href="#">The Renaissance Man</a></li>
What I am having trouble with and would I would like to do is to have each part of the sentence on its on line. In other words
The Thinking Man
The Artist
The Philosopher
But when I insert a <br /> it doesn't creat a break it just displays <br /> in the code. How would I create line breaks in a data description using the following code?
You can add a new line by combining \A with white-space:pre-wrap;, for example:
p:after {
content:"Line 1\ALine 2";
white-space:pre-wrap;
}
/* Line 1
* Line 2 */
JSFiddle example.
Unfortunately it doesn't seem you can do this using attr().
<p data-description="Line 1\ALine 2"></p>
p:after {
content:attr(data-description);
white-space:pre-wrap;
}
/* Line 1\ALine 2 */
JSFiddle example.
What you could do to get around this is to use multiple data-* attributes:
<p data-description1="Line 1" data-description2="Line 2"></p>
p:after {
content:attr(data-description1) "\A" attr(data-description2);
white-space:pre-wrap;
}
/* Line 1
* Line 2 */
JSFiddle example.
I don't know if this is a usable solution to your problem, however.
The content attribute won't ever interpret your Html as markup, so you'll need to go about this another way.
One way would be escaping the newline and setting white-space: pre; in your pseudoelement. This value is an abbreviation for 'preserves,' which means the newline will be rendered by the browser.
The Thinking Man,\AThe Artist,\AThe Philosopher
View on JSFiddle
For more on the white-space property, refer to the MDN article on it..
For more on escaping new lines in content, check out the CSS2 specs on strings.
So I want to rig up some css rules for interview transcripts. The format I have in mind looks something like this:
<h2 class="interviewer">Alice: [00:00:00]</h2>
<p>Is it ok if I ask you a question now?</p>
<h2 class="interviewee">Bob: [00:00:03]</h2>
<p>Sure go ahead.</p>
I'd like the paragraph to be a particular colour based on the class of the preceeding heading. Is there a way to do this, as it would make the html markup significantly simpler.
You can use following-sibling combinator: +
h2.interviewer + p { /* style goes here */ }
Sure:
h2.interviewer + p {
color: red;
}
I'm not entirely sure how to do it with multiple paragraphs though. Perhaps if you encased the entire set of paragraphs in a div:
<h2 class="interviewer">Alice: [00:00:00]</h2>
<div>
<p>Is it ok if I ask you a question now?</p>
<p>More text here.</p>
</div>
<h2 class="interviewee"> class="interviewee">Bob: [00:00:03]</h2>
<div>
<p>Sure go ahead.</p>
</div>
You could then do this:
h2.interviewer + div {
color: red;
}
By the way, there are better HTML elements for displaying a conversation, like the newly introduced <dialog> tag
http://www.quackit.com/html_5/tags/html_dialog_tag.cfm
UPDATE:
The <dialog> element never made it into HTML5. It does not exist.