change the style of the forms been render in the httml?

23 views
Skip to first unread message

dk

unread,
May 20, 2015, 7:00:50 PM5/20/15
to django...@googlegroups.com
I did a form class and renders fine in the html.
but look ugly, I do have another field directly done directly in the HTML with a style like this and look pretty how can I put it to the form?
can I override the "style"? or can I change the class? so I can change the look?   thanks guys.

.text_line {
 -moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
 -webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
 box-shadow:inset 0px 1px 0px 0px #ffffff;
 background-color:#ededed;
 -moz-border-radius:6px;
 -webkit-border-radius:6px;
 border-radius:6px;
 border:1px solid #dcdcdc;
 display:inline-block;
 cursor:pointer;
 color:#777777;
 font-family:arial;
 font-size:20px;
 font-weight:bold;
 padding:6px 24px;
 text-decoration:none;
 text-shadow:0px 1px 0px #ffffff;
}

Galia Ladiray

unread,
May 21, 2015, 3:42:12 AM5/21/15
to django...@googlegroups.com
What you want to do is to add a class attribute to your django widget using attrs so that they will be rendered with this class, then to add the style you want to this class in your CSS section,
This doc shows how to do it:

You can of course override the style as well, for example using the rendered id of your field, but it is less cleaner, since you will need to repeat this for every field

dk

unread,
May 21, 2015, 11:06:51 AM5/21/15
to django...@googlegroups.com
Thanks Galia, since I only have 2 fields, I think the second options will be the faster,   do you have an example? no how to override the id? or the class?

in the template I am doing  {{ form }}   I even try to do something like   <p style="font-size:150%">{{ form }}</p>
but that doesn't change it =(  thanks.

Luis Zárate

unread,
May 21, 2015, 11:15:48 PM5/21/15
to django...@googlegroups.com
It is easy, you only need to put id attribute to form statement like this

<form id="my form" ...> {{form.as_p}}</form >

In CSS use cascade starting by #myform.

Other thing I was used form.as_p for printing as <p>, but you could used form.as_ul or form.as_table too.  By default as_table is set when you do {{form}}
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2824dccf-ac12-4183-8ced-f4ec1917e49a%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

--
"La utopía sirve para caminar" Fernando Birri



dk

unread,
May 22, 2015, 2:12:30 PM5/22/15
to django...@googlegroups.com

yea doing it like its easier =)
mucho mas facil.
Reply all
Reply to author
Forward
0 new messages