JVDB
JVDB

Reputation: 11

urlize colour change Django

I am using 'urlize' in django (4.0.1) as follows in a 'project description' field and it works great.

<h6>{{ project.description | urlize }}</h6>

Is there a simple way to include a different color style for the url that urlize identifies ? For example, standard text in black and the url in say blue

Thank you.

EDIT The above code evaluates to:

<h6>Amazing art by:
<a href="http://www.instagram.com/paint_the_reflection" rel="nofollow">www.instagram.com/paint_the_reflection</a>
</h6>

so following on from @sc_props suggestion, i suppose something in the h6 tag that will conditionally add style to the tag if it happens to exist (as created by the urlize).

Upvotes: 0

Views: 105

Answers (1)

Milo Persic
Milo Persic

Reputation: 1118

By giving a special class to your <h6> (or whatever header or div) wraps these links, could do something like this to target them with some custom CSS.

<h6 class="myStyledLink">Amazing art by:
<a href="http://www.instagram.com/paint_the_reflection" rel="nofollow">www.instagram.com/paint_the_reflection</a>
</h6>

...And some CSS examples: (these are all just random colors, but you get the point)

<style>
.myStyledLink a {
   color: rgb(100,100,300);
}

.myStyledLink a:link {
   color: rgb(91, 79, 185);
}

.myStyledLink a:visited {
   color: rgb(101, 60, 241);

}

.myStyledLink a:focus {
   color: rgb(68, 25, 4);

}

.myStyledLink a:hover {
   color: rgb(211, 208, 4);

}

.myStyledLink a:active {
   color: rgb(99, 214, 33);
}
</style>

Upvotes: 0

Related Questions