Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2005-11-25 04:52:21

iamjhammons
Member
Registered: 2005-11-18
Posts: 13

how can i add a class to the p tag in articles?

hi,

i’d like to add a class to the p tag that surrounds the article body. i’ve read <a href=“http://textpattern.com/faq/83/how-do-i-change-the-article-markup”>here</a> that i can turn it off but i’d like to keep the p tag and just add a class to it. any suggestions greatly appreciated. i’m sure i’m missing something easy here. thanks, j

Offline

#2 2005-11-25 05:37:19

nardo
Member
From: tuvalahiti
Registered: 2004-04-22
Posts: 743

Re: how can i add a class to the p tag in articles?

your body might contain one or more paragraph tags…

if you only want to affect certain paragraphs (e.g. maybe just the first) you could use textile to assign a class…
p(bob). A paragraph becomes <p class="bob">A paragraph</p>

have a look here for textile examples

alternatively if you want to affect every p tag in your body, you could modify your ‘default’ form (or whichever form lays out your articles) … wrap the <txp:body /> tag with <div class="txp-body"> ... </div> and then you can style all enclosed p tags with something like this in your stylesheet:

div.txp-body p {
padding-right:13px; etc
}

Last edited by nardo (2005-11-25 05:38:10)

Offline

#3 2005-11-25 06:08:49

ian_ep
Member
Registered: 2004-02-29
Posts: 25

Re: how can i add a class to the p tag in articles?

i’d like to add a class to the p tag

Why? It’s generally better to use a contextual selector in favour of a class whenever possible.

Offline

#4 2005-11-25 19:22:09

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: how can i add a class to the p tag in articles?

Probably doesn’t know how: a lot of tutorials that float around only mention classes and ids.

nardo gave you one example, you can read up more about it.

Offline

#5 2005-11-25 20:06:19

iamjhammons
Member
Registered: 2005-11-18
Posts: 13

Re: how can i add a class to the p tag in articles?

thanks nardo. that was super helpful. as for contextual selectors? i don’t know what that is. care to explain?

Offline

#6 2005-11-25 23:56:37

nardo
Member
From: tuvalahiti
Registered: 2004-04-22
Posts: 743

Re: how can i add a class to the p tag in articles?

the link mary posted will tell you everything you wanted to know and more : )

Offline

#7 2005-11-26 02:35:25

iamjhammons
Member
Registered: 2005-11-18
Posts: 13

Re: how can i add a class to the p tag in articles?

oh hey, thanks. i didn’t see that post when i replied. thanks again. j

Offline

#8 2006-01-15 02:04:38

tcserpa
New Member
Registered: 2006-01-07
Posts: 2

Re: how can i add a class to the p tag in articles?

Why? It’s generally better to use a contextual selector in favour of a class whenever possible.

that is a bit of a snarky answer, and i think i can give you at least one reason why. you end up with a case of divitis.

Last edited by tcserpa (2006-01-16 13:37:52)

Offline

#9 2006-01-15 03:10:09

Jeremie
Member
From: Provence, France
Registered: 2004-08-11
Posts: 1,578
Website

Re: how can i add a class to the p tag in articles?

Using contextual selector is for the opposite, not bloat the html source with div, id and class that aren’t needed.

Let’s say you want a navigation menu. A lot of tutorial, examples, and so new/ill-informed webmasters would do something like :

<code><div id=“navigation-menu”>
<h2 class=“navigation-header”>Navigation</h2>
<ul class=“navigation-list”>
<li class=“navigation-list-item”><a class=“navigation-link”></code>
etc.

When all you need is the first id, and then contextual selectors like div#navigation-menu ul li a to target the links for example.

Offline

#10 2006-01-16 14:15:22

tcserpa
New Member
Registered: 2006-01-07
Posts: 2

Re: how can i add a class to the p tag in articles?

thanks Jeremie for your thoughtful and complete example/explanation. i was really just trying to stir up some debate and fishing for a nice example like the one you posted.

so, to the initial poster, if you have a specific use for a P tag, you could create a form that includes a div with a class of SpecialUse (or a better name) and append the style for P tags within that div to the CSS. that would make SpecialUse the contextual selector, like this :

<div class="SpecialUse">
<stuff />
</div>

then, in the CSS you would have something like this :

div.SpecialUse p { color: pink; }

and viola! all P’s within the SpecialUse div will be pink.

i get all ruffled by snarky answers to earnest questions when a brief example and a link to a full explanation would be so much more helpful. although by now i bet that person has it worked out.

Offline

#11 2006-01-16 18:52:13

takshaka
Archived Plugin Author
From: Below the Manson-Nixon line
Registered: 2004-06-02
Posts: 97
Website

Re: how can i add a class to the p tag in articles?

i get all ruffled by snarky answers to earnest questions when a brief example and a link to a full explanation would be so much more helpful. although by now i bet that person has it worked out.

So your first action on the forum is to troll a 2-month old thread that already has an appropriate example plus a link to comprehensive information on the subject?

Offline

Board footer

Powered by FluxBB