-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add guidance for CSS, JavaScript and images #683
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Adding CSS, JavaScript and Images | ||
|
||
The Prototype Kit comes with standard GOV.UK Frontend styles and components for you to use in your prototypes. However if you need to add your own CSS (Cascading Style Sheets), JavaScript or images, use the `/app/assets` folder. | ||
|
||
The Prototype Kit processes all the files in the `/app/assets` folder, and puts the processed files in `/public`. | ||
|
||
Do not change files in the `/public` folder because it’s deleted and rebuilt every time you make a change to your prototype. | ||
|
||
## CSS | ||
|
||
CSS lets you change how web pages look, for example text sizes, colours or spacing. | ||
|
||
To add styles use: | ||
|
||
``` | ||
/app/assets/sass/application.scss | ||
``` | ||
|
||
Do not edit the file `/public/styles/application.css` because it’s deleted and rebuilt every time you make a change to your prototype. | ||
|
||
The Prototype Kit uses [Sass](https://sass-lang.com/guide), which adds extra features to CSS. | ||
|
||
### Using import | ||
|
||
If you have a very long application.scss file, you can split it up into multiple files and import those into `application.scss`. Use an underscore (_) at the start of the import file filenames, for example: | ||
|
||
``` | ||
/app/assets/sass/_admin.scss | ||
``` | ||
|
||
Import this file into your `application.scss` file without the underscore: | ||
|
||
``` | ||
@import "admin"; | ||
``` | ||
|
||
## JavaScript | ||
|
||
You can use JavaScript to make changes to a web page without loading a new one. For example a user could enter some numbers, then JavaScript displays the results of a calculation without loading a new page. | ||
|
||
To add JavaScript use: | ||
|
||
``` | ||
/app/assets/javascripts/application.js | ||
``` | ||
|
||
Do not edit the file `/public/javascript/application.js` because it’s deleted and rebuilt every time you make a change to your prototype. | ||
|
||
## Images | ||
|
||
If you add images to `/app/assets/images` the Prototype Kit will copy them to `/public`. | ||
|
||
For example if you add an image: | ||
|
||
``` | ||
/app/assets/images/user.png | ||
``` | ||
|
||
Use it in your page like this: | ||
|
||
``` | ||
<img src="/public/images/user.png" alt="User icon"> | ||
``` | ||
|
||
Use ‘alt’ text to describe the image for screen readers. | ||
|
||
Do not put files directly in `/public` because it’s deleted and rebuilt every time you make a change to your prototype. | ||
|
||
## Other files | ||
|
||
If you need to use other files in your prototype, you can add them to `/app/assets` and the Prototype Kit will copy them to `/public`. You can use sub-folders in the assets folder. | ||
|
||
For example if you add a PDF: | ||
|
||
``` | ||
/app/assets/downloads/report.pdf | ||
``` | ||
|
||
Link to it like this: | ||
|
||
``` | ||
<a href="/public/downloads/report.pdf">Download the report</a> | ||
``` | ||
Do not put files directly in `/public` because it’s deleted and rebuilt every time you make a change to your prototype. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super non-blocking but maybe the download attribute would be useful here: https://caniuse.com/#feat=download