473,395 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Add semicolon after each element except last

On a couple of my pages
http://www.trimboli.name/rune/goblinmagic.html
http://www.trimboli.name/rune/labyrinth.html
I've got a number of definition lists concerning "Points Spent" and
"Points Earned."

A style sheet
http://www.trimboli.name/rune/section.css
makes the list definitions inline and adds "; " after each one (under
"Encounter costs and mechanics" in the style sheet).

I've experimented with ways to not display a semicolon after the final
item, but so far I haven't had any success. Can someone point me in the
right direction?

(I don't want to change the HTML because an inline list isn't
necessarily the only way I'd want to style the lists.)

David
Stardate 7058.0
Jan 21 '07 #1
9 7314
David Trimboli wrote:
>
A style sheet
http://www.trimboli.name/rune/section.css
makes the list definitions inline and adds "; " after each one (under
"Encounter costs and mechanics" in the style sheet).
....by using .points li:after { content: "; "; }. This doesn't work on
all browsers, BTW.
>
I've experimented with ways to not display a semicolon after the final
item, but so far I haven't had any success. Can someone point me in the
right direction?
Personally, based on your example and the kind of person I am, I'd drop
the styling and do the punctuation by hand. But I see you don't like
that idea...
>
(I don't want to change the HTML because an inline list isn't
necessarily the only way I'd want to style the lists.)
So, you really have some unknown number of <LI>s, or some other kind of
element (which you haven't named and I can't imagine), and you want a
semi-colon after each of these elements (whatever they are) except for
the last one.

How do you know when it's "the last one"?

--
John
Jan 22 '07 #2
David Trimboli wrote:
(I don't want to change the HTML because an inline list isn't
necessarily the only way I'd want to style the lists.)
How about the HTML change of adding an id to each last <lielement?

The following patch works for me.

I treated just some of your lists, not all, for brevity.

Index: trimboli/labyrinth.html
================================================== =================
--- trimboli.orig/labyrinth.html
+++ trimboli/labyrinth.html
@@ -106,7 +106,7 @@
<h4>Points Spent</h4>
<ul>
<li><span class="cost">0</span(Difficulty 6)</li>
- <li><span class="cost">25</span(10/20 falling damage)</li>
+ <li id="last"><span class="cost">25</span(10/20 falling
damage)</li>
</ul>
</div>

@@ -145,7 +145,7 @@
<div class="points earned">
<h4>Points Earned</h4>
<ul>
- <li><span class="cost">−8</span(Freestanding Difficulty
+ <li id="last"><span class="cost">−8</span(Freestanding
Difficulty
8)</li>
</ul>
</div>
@@ -195,7 +195,7 @@
<div class="points earned">
<h3>Points Earned</h3>
<ul>
- <li><span class="cost">−5</span(Freestanding Difficulty
+ <li id="last"><span class="cost">−5</span(Freestanding
Difficulty
10)</li>
</ul>
</div>
@@ -222,14 +222,14 @@
only)</li>
<li><span class="cost">15</span(3 dice damage)</li>
<li><span class="cost">10</span(armor-ignoring)</li>
- <li><span class="cost">0</span(remains in effect)</li>
+ <li id="last"><span class="cost">0</span(remains in
effect)</li>
</ul>
</div>

<div class="points earned">
<h4>Points Earned</h4>
<ul>
- <li><span class="cost">−20</span(conditionally avoidable
+ <li id="last"><span class="cost">−20</span(conditionally
avoidable
singular roll)</li>
</ul>
</div>
Index: trimboli/section.css
================================================== =================
--- trimboli.orig/section.css
+++ trimboli/section.css
@@ -27,6 +27,7 @@ a:visited, #header a:link, #title, h1, h
.points ul { list-style-type: none; margin-top: 0; }
.points li { display: inline; }
.points li:after { content: "; "; }
+.points li#last:after { content: ""; }

/* Encounter synopsis */

Jan 22 '07 #3

David Trimboli wrote:
http://www.trimboli.name/rune/goblinmagic.html
These look automatically generated ?

So stick <li class="last-item" on the last <liin each list's HTML
and make the CSS selector turn off content for this last item. It's
admittedly a change to the HTML, but it's not one that's likely to
break anything else.

Jan 22 '07 #4
David Trimboli escribió:
...
I've experimented with ways to not display a semicolon after the final
item, but so far I haven't had any success. Can someone point me in the
right direction?
Instead of adding a semicolon AFTER each item(except the last) you could
add a semicolon BEFORE each item (except the first). CSS2 has a seudoclass
selector :first-child to apply a different style to the first element of a
collection.

..points li:before { content: "; "; }
..points li:first-child:before { display: none }
But I don't know if this is supported by most browsers.
--
Manuel Collado - http://lml.ls.fi.upm.es/~mcollado
Jan 22 '07 #5
Rik
Manuel Collado wrote:
David Trimboli escribió:
>...
I've experimented with ways to not display a semicolon after the
final item, but so far I haven't had any success. Can someone point
me in the right direction?

Instead of adding a semicolon AFTER each item(except the last) you
could add a semicolon BEFORE each item (except the first). CSS2 has a
seudoclass selector :first-child to apply a different style to the
first element of a collection.

.points li:before { content: "; "; }
.points li:first-child:before { display: none }
But I don't know if this is supported by most browsers.
It isn't, and as long as we're talking about not yet supported pseudo
selectors, :last-child is also one (albeit CSS3) :-)
http://www.w3.org/TR/css3-selectors/#pseudo-classes

For reference, CSS2:
http://www.w3.org/TR/REC-CSS2/selector.html
Oh, the joy it would bring and the cleaning up for classes I could do if
only the :nth-child & E[foo] selectors were universally supported. Then
again, it's like Christmas: the anticipation is half the fun...
--
Rik Wasmus
Jan 22 '07 #6
John Hosking wrote:
David Trimboli wrote:
>A style sheet
http://www.trimboli.name/rune/section.css
makes the list definitions inline and adds "; " after each one (under
"Encounter costs and mechanics" in the style sheet).

...by using .points li:after { content: "; "; }. This doesn't work on
all browsers, BTW.
I know. It's still easily readable in those that don't support it, though.
So, you really have some unknown number of <LI>s, or some other kind of
element (which you haven't named and I can't imagine), and you want a
semi-colon after each of these elements (whatever they are) except for
the last one.

How do you know when it's "the last one"?
Exactly the problem.

David
Stardate 7060.6
Jan 22 '07 #7
Kaz Kylheku wrote:
David Trimboli wrote:
>(I don't want to change the HTML because an inline list isn't
necessarily the only way I'd want to style the lists.)

How about the HTML change of adding an id to each last <lielement?
You mean a class, right? An ID must be unique in a document.

David
Stardate 7060.6
Jan 22 '07 #8
Andy Dingley wrote:
David Trimboli wrote:
> http://www.trimboli.name/rune/goblinmagic.html

These look automatically generated ?
No, I typed 'em out by hand in Vim. I did often use global search and
replace functions to do some of the repetitive stuff, like ABBRs and CITEs.
So stick <li class="last-item" on the last <liin each list's HTML
and make the CSS selector turn off content for this last item. It's
admittedly a change to the HTML, but it's not one that's likely to
break anything else.
Yes, this seems to be the general consensus. It certainly won't break
anything, but I was trying to avoid marking things up for purely
stylistic reasons, and <li class="last-item"has no business being
there except for stylistic reasons, even if it is structurally correct.

Ah, well. Thanks for the response!

David
Stardate 7060.6
Jan 22 '07 #9
Rik wrote:
Manuel Collado wrote:
>David Trimboli escribió:
>>...
I've experimented with ways to not display a semicolon after the
final item, but so far I haven't had any success. Can someone point
me in the right direction?
Instead of adding a semicolon AFTER each item(except the last) you
could add a semicolon BEFORE each item (except the first). CSS2 has a
seudoclass selector :first-child to apply a different style to the
first element of a collection.

.points li:before { content: "; "; }
.points li:first-child:before { display: none }
Y'know, I tried something like this, but I think I got the
pseudo-selector wrong, and it didn't work. I've tried it this way, and
it works fairly nicely! Style sheet updated. Thanks!

The only thing I have to figure out how is if it's possible to get rid
of the extra space between each item and its trailing semicolon.

>But I don't know if this is supported by most browsers.

It isn't, and as long as we're talking about not yet supported pseudo
selectors, :last-child is also one (albeit CSS3) :-)
http://www.w3.org/TR/css3-selectors/#pseudo-classes
Yeah, but it's such a minor detail that I'm not going to worry about
nonconforming browsers in this case. Serves 'em right!
Oh, the joy it would bring and the cleaning up for classes I could do if
only the :nth-child & E[foo] selectors were universally supported.
Ahhh!

David
Stardate 7060.7
Jan 22 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: fritz | last post by:
Hi, When I look through the "javascript bible" I don't find any example scripts that have lines with ending semicolons. However when I peruse this newsgroup I find that sometimes there are ending...
4
by: yaffa | last post by:
dear folks, i have the following lines of python code: couch = incident.findNextSibling('td') price = couch.findNextSibling('td') sdate = price.findNextSibling('td') city =...
9
by: Russ | last post by:
Here is a question for the programming language historians out there. Can anyone tell me which "major" language first introduced the convention of terminating each statement with a semicolon? Was...
64
by: Merrill & Michele | last post by:
#include <stdio.h> int main(void) { int i = 0; ++ i; ++ i; printf("i equals %d\n", i); return 0; } I've been trying to determine the great and manifold uses of the semicolon
3
by: Dan | last post by:
I'm writing a record from an asp.net page to SQL Server. After the insert I'm selecting @@identity to return the ID of the record that I just wrote. It worked fine until I typed a semicolon into...
3
by: Ken | last post by:
Hi all, I want to printf a sentence with a semicolon, for examples: printf(" I like C language; You like C++ language."); But C compiler alway identify the semicolon as a end of a sentence and...
4
by: Bin Chen | last post by:
Hi, I don't know what's wrong with my program, it causes SIGSEGV: #include <vector> using namespace std; int main(void) {
7
by: Rehceb Rotkiv | last post by:
I want to check whether, for example, the element myList exists. So far I did it like this: index = -3 if len(myList) >= abs(index): print myList Another idea I had was to (ab-?)use the...
29
by: Virtual_X | last post by:
As in IEEE754 double consist of sign bit 11 bits for exponent 52 bits for fraction i write this code to print double parts as it explained in ieee754 i want to know if the code contain any...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.