aboutsummaryrefslogtreecommitdiffstats
path: root/docs/customising/css.md
blob: e444bb778bf0ce767393c83c3f347b1df4c906ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
---
layout: page
title: Customising the design
author: dave
---

# Customising the design

<p class="lead">
  This page describes how to change the directionality and colour scheme of
  your installation &mdash; which is a good starting point for further
  customisations.
</p>

## Background

The CSS is stored in `web/cobrands/` under which there are directories for
Cobrands. Note that FixMyStreet uses SCSS and Compass to generate its CSS so
there are no CSS files until `bin/make_css` has been run as the site user.

The CSS provided with FixMyStreet uses CSS3 media queries in a mobile-first
format order to adapt the layout to work on different devices. It is structured
into these main files:

* `base.css` --
  all the styling for the content of the pages in a mobile sized browser.
* `layout.css` --
  all the styling for the content of the pages in a desktop sized browser.
* `_colours.css` --
  basic settings information, so you can easily make a site that
  looks different simply by copying these files to your own cobrand CSS
  directory, and changing the contents, as we will describe below.

Our `.gitignore` file assumes that any CSS files directly in a `cobrands/*`
directory are generated from SCSS - if you have CSS files that you want to use
directly, put them in a `css` directory within your cobrand directory.

# Tutorial

You can override any of the CSS or HTML templates of your FixMyStreet
installation, but to begin with it's a good idea to just change the colours.
That way you can learn how FixMyStreet customisation works, before tackling
more complex layout, design, or code changes.

## Start simple!

FixMyStreet's default CSS comes with a few basic colour settings which you can
change. Remember that ultimately **you can override any styling for your own
site** but most of this page shows how to set your own colours *without adding
any new HTML or CSS*. We know that you'll want to change more than just the
default colours: but this is the best way to start.

Once you've done this, you'll have your own <a href="{{ "/glossary/#cobrand" | relative_url }}"
class="glossary__link">cobrand</a>, and can start changing other stylesheets and
templates in the same way.


## Why you should create a cobrand

A cobrand is just FixMyStreet's way of separating your customisation from
everybody else's. To start with, this is almost as simple as putting what you
need in its own directory.

<div class="attention-box warning">
  You <em>can</em> simply edit the default settings (just edit the values in
  <code>web/cobrands/default/_colours.scss</code> and run
  <code>bin/make_css</code>) but we <strong>strongly recommend</strong> you do
  not do that. It's OK if you just want to play with the settings to see what's
  possible, but the right way to change how your site looks is to make a
  cobrand.
</div>

By making your own cobrand you'll be keeping your changes separate from the
core code, but also keeping it within the main repository. This has serious
benefits later on: it means you can easily update the FixMyStreet code (we
frequently add new features, for example) while retaining your changes.


## How to change the colours


This is the process:

1. pick a name for your cobrand
2. update your config to use the new cobrand
3. create a directory for it in `web/cobrands`
4. copy the default cobrand's CSS into it
5. edit the colours
6. run `bin/make_css`


The rest of this page describes each step in detail.


### Pick a name for your cobrand

Choose a name for your cobrand. In the examples below, we've used `fixmypark`,
but you can use anything provided it's not a cobrand already in use in the
code. Only use lower case letters. This name is never seen by the public &mdash;
it's FixMyStreet's internal name for it.

### Update your config to use the new cobrand

You need to tell FixMyStreet to use your cobrand instead of the default one.

FixMyStreet uses the 
<code><a href="{{ "/customising/config/#allowed_cobrands" | relative_url }}">ALLOWED_COBRANDS</a></code>
config variable to decide which cobrand to use. In `conf/general.yml`, set it to your new cobrand like this:

    ALLOWED_COBRANDS:
      - fixmypark

In fact, `ALLOWED_COBRANDS` is 
[a little more complex that it looks]({{ "/customising/config/#allowed_cobrands" | relative_url }}).
If you give it a list of cobrands, it will decide which one to use depending on string
matches on the incoming URL *for every request*  But for most cases you don't want it to switch.
So if you just specify just one cobrand like this, FixMyStreet will simply use it.

### Create a directory for your cobrand in web/cobrands

Make a new directory with your cobrand's name in `web/cobrands/` For example,
on the command line, do:
   
    cd fixmystreet
    mkdir web/cobrands/fixmypark


### Copy the default cobrand's CSS into yours

Copy the contents of `web/cobrands/default` into that directory.

    cp web/cobands/default/* web/cobrands/fixmypark
   
This puts the stylesheet files you need into your cobrand.
At this point, your cobrand is effectively a copy of the default one.

### Edit the colours

The default cobrand's colour scheme, which you have copied, will be blue and
orange &mdash; we picked startling colours to force people to want to customise it.

We use SCSS (instead of CSS) because it's a more powerful way of defining and
managing styles. This means that when you make any changes, FixMyStreet needs
to compile those SCSS files to rebuild the CSS &mdash; see the following
section.

You can edit the colours defined in `web/cobrands/fixmypark/_colours.scss`.
You'll need to use [web colour
codes](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_started/Co
lor) to specify the colours you want.

Be careful: if you're not familiar with SCSS, the syntax of that file is a
little strict. Typically, those colours *must* always be either exactly three
or six hex characters long. And there must be a `#` before and a semicolon after each one.

These are the colours which you can easily change within your copy of the
stylesheet:

<table class="table">
    <tr>
        <th>
            variable
        </th>
        <th>
            examples of where it's used in the default cobrand
        </th>
    </tr>
    <tr>
        <td>
            <code>$primary</code>
        </td>
        <td>
            the front page's main banner background
        </td>
    </tr>
    <tr>
        <td>
            <code>$primary_b</code>
        </td>
        <td>
            border around the the front page street/area input
        </td>
    </tr>
    <tr>
        <td>
            <code>$primary_text</code>
        </td>
        <td>
            text on the front page banner
        </td>
    </tr>
    <tr>
        <td>
            <code>$base_bg</code><br>
            <code>$base_fg</code>
        </td>
        <td>
            Large width page background/foreground (bleeding to edge)
        </td>
    </tr>
    <tr>
        <td>
            <code>$nav_background_colour</code><br>
            <code>$nav_colour</code>
        </td>
        <td>
            Mobile width, the header's colours; large width, the navigation's
            foreground colour
        </td>
    </tr>
    <tr>
        <td>
            <code>$menu-image</code>
        </td>
        <td>
            “Hamburger” menu colour (<code>menu-black</code> or
            <code>menu-white</code>)
        </td>
    </tr>
    <tr>
        <td>
            <code>$col_click_map</code><br>
        </td>
        <td>
            background of the "click map to report problem" banner on the
            map page
        </td>
    </tr>
    <tr>
        <td>
            <code>$col_fixed_label</code><br>
            <code>$col_fixed_label_dark</code>
        </td>
        <td>
            background of the colour of the "fixed" label that appears on
            fixed reports, and its darker underside
        </td>
    </tr>
    <tr>
        <td>
            <code>$col_big_numbers</code>
        </td>
        <td>
            Colour to use for the step numbers on the front page.
        </td>
    </tr>
</table>

SCSS supports functions such as `darken` so you can specify colours that are
calculated from other colours like this:

    $col_click_map: #ee6040;
    $col_click_map_dark: darken($col_click_map, 10%);

For more about SCSS, see [the SASS website](http://sass-lang.com).


### Run make_css so FixMyStreet's CSS uses the new values

FixMyStreet now needs to absorb those changes by rebuilding the CSS. There's a
task in the `bin` directory called `make_css` that will do this for you. You'll
need to be logged into your shell in the `fixmystreet` directory as the site
user, then do:

    bin/make_css

This will update the CSS files. You can run the command just for your cobrand
by specifying the path to your cobrand’s SCSS as an argument, e.g.:

    bin/make_css web/cobrands/fixmypark

Keep an eye on the output of that command &mdash; if there's a problem (for
example, if you've made a mistake in the SCSS syntax, which is easy to do), it
will report it here.


### See the new colours

If you look at your site in a browser, you'll see the new colours. Remember
that every time you edit them, you need to run `bin/make_css` to make
FixMyStreet include the changes, or run `bin/make_css --watch` to have it
monitor for changes itself.


## Or... use your own CSS and HTML

Remember that *all* you've done here is change the colours, **using the
existing default CSS and HTML**. Of course any and all of this can be
overridden (by overriding CSS files and overriding the bits of HTML that you
want to change in the <a href="{{ "/glossary/#template" | relative_url }}"
class="glossary__link">templates</a>) but this is just so you can get going.

# Directionality

If you wish to use FixMyStreet in a right-to-left layout, this is very
straightforward and involves two steps:

* First, uncomment the line in your cobrand’s `_colours.scss` file as explained,
  so that the `$direction` variable is set to `right`.
* Secondly, create a copy of the `templates/web/base/header.html` in
  your own cobrand if you haven’t already (see
  [template customising]({{ "/customising/templates/" | relative_url }}) for more
  details) and uncomment the `SET` line that sets `dir="rtl"`.

That’s it; recompile your CSS, reload your site and you will find that
FixMyStreet has switched to a right-to-left layout. Your next step will
probably be to [change the language]({{ "/customising/language/" | relative_url }})
used by your site.

# Next steps...

If you want to customise the logo, [we have a tutorial for that](../logo/).

Now you have your own cobrand, adding your own HTML <a
href="{{ "/glossary/#template" | relative_url }}" class="glossary__link">templates</a> is straightforward.

Please see our separate page on [customising templates]({{ "/customising/templates/" | relative_url }}).

### Feeding back changes

Finally, when you've finished creating your cobrand you should consider
[feeding it back to us]({{ "/feeding-back" | relative_url }}) so it becomes part of the FixMyStreet repository.