Formatting checkboxes in django - css

i'm trying to add some checkboxes into my form and to make them look nice. The thing is that when I use {{form.checkBoxFilter}} the output is like:
I would like to have them inline and readable, unfortunately using crispy forms renders them too close to each other.
I found that looping through elements will place them inline but still they're close to each other (their labels are much longer than shown below).
{% for x in filter.weights%} {{x}} {%endfor%}
Where to put my css in this case?
filters.py:
weights = django_filters.MultipleChoiceFilter(
label = "Filter by weight",
required=False,
widget=forms.CheckboxSelectMultiple,
choices=OZ,
method = 'filter_by_checkbox'
)
Adding directly into static/css won't work :
input[type=checkbox]
{
padding: 20px;
margin: 20px 15px 0px 3px;
}

You could use css to seperate them. For example you could use a bootstrap stylesheet in your base.html (read here).
when installed you could do it like this:
<div class="container">
<div class="row mb-1">
{% for x in filter.weights %}
<div class="col-sm-XX">
{{x}}
</div>
{%endfor%}
</div>
</div>
where XX should be a suitable size. Keep in mind bootstrap divedes the page in 12 parts. Also it comes with some css features.
Update for your edit:
assign a class to your checkbox and go for the class in the css. You can also use the built in x.as_p to display it as <p> element.

Related

Creating a tag cloud with bootstrap

I have a page where I can view all tags.
Some tags might be more popular thus they will be displayed slightly bigger than the tag elements that are not as popular.
Right now when one line cant fit anymore tags, flexbox puts them on the next line:
But as you can see theres a lot of empty space,
What I would like is to have the tags in a bit more scattered manner like so:
This is my code:
<div class="row" style="align-items: flex-start;">
#foreach($tags as $tag)
<a href="#"
style="
font-size: {{ ( 15 * $count }}px;
display: flex;
align-items: center;
justify-content: center;
margin: 0;
"
class="m-3 btn btn-secondary ">
Tag Name
<span class="badge badge-light mx-1">2</span>
</a>
#endforeach
</div>
I have tried cycling through different flex properties, but I can't seem to get any results.
I also am not sure how to phrase this type of styling method for research so any references to something similar will help.
EDIT:
After a bit of digging, I found out that tag clouds is what I am trying to achieve.
Most what I have found are either too over styled or include a library, but I believe I just need to find the correct properties to align the tags.
Here is the very barebones version of what I am trying to achieve
you might want to take a look at css grid. You can create grid areas and place your large tags over multiple grid cells.
https://css-tricks.com/snippets/css/complete-guide-grid/

Position of "like" and "reblog" buttons on tumblr

I tried to add some buttons under posts on my tumblr page but they are displaying incorrectly. Like button has right position but reblog appears at the beginning of the post (and on the next posts reblog appears even outside post block). Also after first post text in the other posts moves to the left side. I don't know how to solve this problem.
Blog with problem: http://rkhmlvch.tumblr.com
Original code:
https://github.com/xSOADx/The-Default-Network/blob/master/Theme%20code
Fragment with needed code:
<div id="buttons">{likebutton}</div>
<div id="buttons">{reblogbutton}</div>
Images
First, if you're planning to use styles in a specific element, use ID. If you're planning to use styles repeatedly in multiple elements use Class. I will recommend that you change the ID's to class instead.
Example: <div id="post">...</div> to <div class="post">...</div> same goes to <div id="buttons">...</div>.
Anyway, back to your question.
Your first <div id="post">...</div> is inside <div id="wrapper"> then the rest are outside it. Put the rest of your post inside <div id="wrapper"> and all of them will be the same.
Next, for your buttons. Change it to this <div class="buttons">...</div> instead of <div id="buttons">...</div> then add styles to your CSS:
.buttons { display: inline-block; margin: 5px; }

How to Disable CSS of one of two col-md-12 divs

I have made 2 Divisions out of bootstrap property <div class="col-md-12" > on the same page. In the first one, I have added a different Background and some hover property, now in the second one I have to make a "Sign Up" Div but with other properties with the same <div class="col-md-12" > ie. Full page width row. But the changes are happening on both the Divisions.
Can somebody Help ?
I am using Visual Studio 13 for aspx webpage.
Sorry if it is a silly question.
Thanks In Advance.
You can append another class to the ones you want to style:
<div class="col-md-12 styleme">
Content
</div>
CSS:
.styleme {
background-color: #000;
}
This way, you can style the div using your own custom class as opposed to overriding BootStrap's native one.
NOTE: ensure to place the custom style in your own custom CSS file and ensure it is referenced in your site AFTER the BootStrap CSS file.

Rails 3.1 - Fields With Errors

I'm using Rails helper methods to build a form, and using validations.
Whenever one of these validations fails, rails wraps the corresponding inputs and labels in a field_with_errors tag. Which is fine.
However, for some reasons rails is wrapping both the input AND the label in different divs, making styling really hard:
eg:
<div class="field">
<div class="field_with_errors">...label...</div>
<div class="field_with_errors">..input ...</div>
</div>
and what I need is:
<div class="field">
<div class="field_with_errors">...label & input...</div>
</div>
Does anyone know how I would achieve this?
One way is to replace the divs with spans, which don't break formatting as they're not block level elements. To do so, put this somewhere in an initializer:
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
"<span class=\"field_with_errors\">#{html_tag}</span>".html_safe
end
Another way would be to simply make the original divs not display as block level elements, with this line in your CSS file:
.field_with_errors { display: inline-block; }
but this is not fully supported by some of the older browsers (looking at you IE6 and 7).

Wrong font size when using jqGrid inside jQueryUI tab

I have a jqGrid which works fine when displayed on a page on its own.
If I try to display the same grid inside jQueryUI tab, it still works fine – except that font size is wrong. What is happening is this:
When everything is working on a standalone page, the font size is picked up as follows:
Inherited from div#gbox_datatable.ui-jqgrid.ui-widget.ui-widget-content.ui-corner-all, in file ui.jqgrid.css line 2
.ui-jqgrid{
font-size:11px;
}
When the grid is placed inside a jQueryUI tab, howerver, it is overridden by a higher priority CSS command as follows:
Inherited from div#gbox_datatable.ui-jqgrid.ui-widget.ui-widget-content.ui-corner-all, in file jquery-ui-1.8.9.custom.css line 60
.ui-widget .ui-widget{
font-size:1em;
}
In other words, the fact that I have a ui-widget inside another ui-widget is overriding the desired font specifier.
How can I avoid this overriding?
I found same question at here without any answers.
Any help will be appreciated...
ui.jqgrid.css has the following definition
.ui-jqgrid {position: relative; font-size:11px;}
So if you add class "ui-jqgrid" to the div which holds the tabs the problem will be solved:
<div id="tabs" class="ui-jqgrid">
<ul>
<li>Results</li>
<li>Software</li>
</ul>
<div id="results" class="tabcontain"></div>
<div id="log" class="tabcontain">
<table id="grid"><tr><td></td></tr></table>
<div id="pager"></div>
</div>
</div>
In the example above div with two tabs will be used: one with some general information and another with the the id="grid".
One more simple way will be just set
html, body { font-size: 75%; }
which set will reduce default font size of the page (1em) to the same which jqGrid uses (11px).
See one more way in the resent question.

Resources