CSS page x of y for #media print - html

I'll preface this question by saying I know this question has been asked before, but all the answers I can find for these appear to reference an obsolete solution that no longer works (At least in Firefox 56 [64 bit])
The obsolete method is that there used to be an automatically instantiated CSS counter named pages, so a simple bit of CSS generated from this SASS:
footer {
position: fixed;
bottom: 0;
left: 20px;
&:after {
counter-increment: page;
content: "Page " counter(page) " of " counter(pages);
}
}
Used to do what I want. Now it displays "Page [x] of 0".
I have tried using this bit of CSS to recreate my own max-page counter:
#page {
counter-increment: maxpage;
}
However this also returns 0 when used in my footer.
Is there any reasonably cross-browser friendly means of getting this functionality?

As of CSS3 you can specify counters in the #page rule. Here is an example:
#page { counter-increment: page }
The above rule instructs the layout engine to create a counter called "page" (it is called page by convention, it can be anything). This counter is incremented for each page. As with any counter, you can then use the current value of the counter anywhere in the document
For example with this CSS rule:
#pageNumber { content: counter(page) }
and this piece of HTML:
<span id="pageNumber"></span>
You can use the current page number counter as content in the HTML document. You can even go further. Say you want to start your page number at 10. You can then use the #page:first rule to reset the counter for the first page to value 9.
#page { counter-increment: page }
#page:first { counter-reset: page 9 }
The combination of both rules will reset the counter for the first page to 9. Then for each page (including the first) it will increment the counter. This results in a counter value of 10 for the first page, 11 for the second and so on.
You can also use pure css
Example:
#page {
counter-increment: page;
counter-reset: page 1;
#top-right {
content: "Page " counter(page) " of " counter(pages);
}
}
... in theory. In real world only PrinceXML supports this.

Not using #page, but I have gotten pure CSS page numbers to work in Firefox 20:
The CSS is:
#content {
display: table;
}
#pageFooter {
display: table-footer-group;
}
#pageFooter:after {
counter-increment: page;
content: counter(page);
}
And the HTML code is:
<div id="content">
<div id="pageFooter">Page </div>
multi-page content here...
</div>
It works on most major browsers

According to mozilla docs,
CSS counters let you adjust the appearance of content based on its
location in a document.
So, if your css rule applies to multiple element, it will count all that elements.
If you are using header and footer element which basically appear 1 time in document and multiple time in print, counter-increment won't work because in document it has only 1 appearance.

Related

Contact Form 7 checkboxes: how to put them in vertical order

In my Contact Form 7 on WordPress, I would like to put checkboxes, only for some specific ones, in this way:
The official resource shows a simple css instruction to do it:
span.wpcf7-list-item { display: block; }
This instruction I have used it together with an ID selector as Contact Form 7 requires:
[checkbox test1 "option1" "option2" "option3" id:namefield]
To do that I have create an instruction in css file
#namefield.span.wpcf7-list-item { display: block; }
It is not working. Using browser inspector the code rendered is taken from /wp-content/plugins/contact-form-7/includes/css/styles.css?ver=5.1.9 and it is:
span.wpcf7-list-item {
display: inline-block;
margin: 0 0 0 1em;}
Instructions from my ID they are not showed.
I'm looking to understand the reason why and what it should better to do to put checkboxes in vertical order.
It's working with the code
#namefield span.wpcf7-list-item { display: block; }
without dot after ID
In WordPress menu, go to appearance -> customize -> custom CSS
Now write below code in custom css area
span.wpcf7-list-item { display:block; }

Convert arabic numerals in roman numerals in pure CSS

I'm writing a custom theme for a website, so I cannot use Javascript. I would like to convert some numbers to roman numerals.
I tried this:
.score:before {
counter-reset: mycounter attr(score number, 0);
content: counter(mycounter, upper-roman) " ";
}
<p><span class="score" score="11">points</span></p>
Alas, it seems that "attr(score number, 0)" is always 0. It's not because of a fallback, since when I change the fallback number to 42, the result stays 0. It's not a problem somewhere else in the code, because it works fine when I replace attr(...) by a number like 42.
So why isn't this code showing what it should?
Even today, attr() is still only supported for content: usage, not for anything else, as you can see from all the red flags here: https://caniuse.com/#feat=css3-attr
Screenshot:
You can use var to pass proper values to your css files and counter, for example:
.score {
counter-increment: my-awesome-counter 0;
counter-reset: my-awesome-counter var(--data-score);
}
.score:before {
content: counter(my-awesome-counter, upper-roman);
margin-right: 5px;
}
<p><span style="--data-score:11" class="score" score='11'>points</span></p>

Internet Explorer Css variable content dynamically

Please I try to make the content of the pseudo class of element dynamically, it works fine with ( Google Chrome, Firefox, safari ).
Css:
.list-rank > li:before{
content: var(--rank ,'0')
}
HTML
for (var i = 0; i <res.data.rankListUser.length; i++) {
html +='<li style="--rank:\''+res.data.rankListUser[i].rank+'\'" >';
html +='name here'
html +='</li>';
}
$('#ranking_container').html(html);
IE does not support CSS variables like these, but you could potentially use a data attribute:
div:before { content: attr(data-word); }
<div data-word="Hello">World</div>
This will only work with the content property, though - it cannot be used to set colors etc... At least not currently, which means for IE it's probably a never. According to MDN this is supported on IE: https://developer.mozilla.org/en-US/docs/Web/CSS/attr

:before pseudo class not working

At this page, I'd like to add some text above the gray box containing "ADSL Broadband 1".
I've tried using the following CSS rule, but it isn't working:
.vc_tta-panels #adsl .vc_tta-panel-body:before {
content: 'text goes here';
}
Can you see what is wrong here, please?
Your other rules override this rule, you should add display property, for example:
.vc_tta-panels #adsl .vc_tta-panel-body:before {
content: 'text goes here';
display: inline;
}
The code you have written is working fine, but at the same time, it's getting hidden by your CSS written at some other place.
vc_tta-panels #adsl .vc_tta-panel-body:before {
content: 'Hello';
display: block !important;
}
Attaching a snapshot of issue, from where it gets hidden due to display:none given.

How can I select every other element that does not have a specific class?

I have a list of <div>s. Each <div> has class zebra. Until now I've used the following to stripe the list:
.zebra:nth-child(2n) { /* colors */ }
Now I'm implementing a filtering feature, such that some of these <div>s will have a class hidden. I tried updating my css to
.zebra:not(.hidden):nth-child(2n) { /* colors */ }
But that had no effect. What am I missing? How can I combine these selectors so that only the showing .zebra <div>s are considered in the :nth-child(2n)?
Here's a fiddle of what I'm describing.
UPDATE:
there is an unknown number of .hidden elements, and an unknown total number of elements. (the list is data-driven, not static).
I'd really rather not do any of:
run a javascript every time a filter control is touched, just to re-color the showing list items.
remove an element entirely when it's hiding. this makes re-adding it non-trivial (afaict).
Instead of removing the element as Justin suggested, you could replace it with an element of a different tag. We could use details, for example:
var placemarker = document.createElement("details");
node.parentNode.replaceChild(placemarker, node);
placemarker.appendChild(node);
Then, instead of using :nth-child, use :nth-of-type.
details { display:none; }
div.zebra:nth-of-type(2n) { /* colors */ }
Unhiding the element can then be done with:
placemarker.parentNode.replaceChild(placemarker.firstChild);
See this static example.
if you don't mind delving into jquery..
$('#yourHiddenElement').remove();
will remove it so that your css shades alternate.
http://jsfiddle.net/NYvcv/1/
I would suggest using this instead of applying the class 'hidden' to the element you want to hide.
If you know there will be a limited number of .hidden items, you can do something like this:
.zebra2:nth-child(2n) {
background: lightgrey;
}
.zebra2.hidden ~ .zebra2:nth-child(2n) {
background: inherit;
}
.zebra2.hidden ~ .zebra2:nth-child(2n+1) {
background: lightgrey;
}
.zebra2.hidden ~ .zebra2.hidden ~ .zebra2:nth-child(2n) {
background: lightgrey;
}
.zebra2.hidden ~ .zebra2.hidden ~ .zebra2:nth-child(2n+1) {
background: inherit;
}
And so on. This particular example breaks if there are more than 2 hidden items.
​
One possible solution:
use jQuery to change the .hidden element's type to, say, <li>. Use :nth-of-type instead of :nth-child.
http://jsfiddle.net/Nb68T/1/