What we’ll cover:
- Respecting other people’s work
- Variables – Journeyman +
- Floating ‘To Top’ link – Journeyman +
- Floating Link Box/Container – Grandmaster +
- Floating Dictionary Jump Box – Grandmaster +
Respecting Other People’s Work
“But that effect is so cool!!!!’ — I get it. Really. If you admire the work, reach out to that person. Find their WA profile and see how to contact them. Many people have links for twitter and discord. Some people leave notes in their code. Case in point, as I peeked at Ademal’s CSS code, I found a note about letting them know. They also included links to their Ko-fi and Patreon account. So, I did just that. The best part? I got to know Ademal a little better, and they learned what part of the code I was most interested in.
All of this to say, please ask. The World Anvil community is amazing. Many people I’ve chatted with have been flattered and are happy to share. But it’s best to be sure! Checking with the creators you admire is part of what will help keep World Anvil awesome.
CSS Variables: For Journeyman +
Why use variables?
Let’s say we’re working on our color scheme. We have a single color for our headers, borders on boxes, and links. But we’re not sure about it. Using a variable would allow us to change it in one place. Yet, on the page it would change in all those classes at one time. Easy!
Also, variables can make your code more readable. If you have 20 lines of code, it’s not hard to keep things straight. But as you tinker more with your CSS, you’ll build up a nice set of tricks. Soon you’ll have hundreds or thousands of lines of code. Navigate that puppy without variables, I dare you.
How to define a variable
--varName: some_attribute_info;
Example: Let’s make a variable for our main accent color.
--main-color: #89012F; /* a red that tends more toward purple */
Where to Put Variables
Your vars go here
}
How To Use Variables
var(--varName)
.user-css h1, .user-css h2, .user-css a {
color: var(--main-color);
}
* Please note: CSS doesn’t bring in information. You need another language like JavaScript to do things such as retrieving the window size. Though, you can use the calc() function. It’s limited but handy.
Let’s get to the code!
Floating ‘To Top’ Link: For Journeyman +
Put this BBCode line at the top of your article to create an anchor. Edit as needed. (See the Codex for more info on anchors.)
[h1|top]Name of Top Content[/h1] /* the ‘top’ anchor is where we’ll jump to */
Note: Putting the BBCode that you’ll float in ‘Sidebar: Over panel content’ will allow you to have control where the floating link goes. The link won’t get stuck inside another HTML div element on a lower section of the page. Also, it won’t change locations if you add more information to the article.
[h4|float][url=#top]TO TOP[/url][h4] /* ‘float’ is the anchor that we give to modify the CSS for this header/link. ‘#top’ tells the link where to go */
/* -- a floating item positioned in the upper left corner -- */ .user-css #float{ position: fixed; /* it will stay in the same place when you scroll */ top: 150px; /* placed this many pixels from the top */ right: 50px; /* placed this many pixels from the right */ z-index: 10; /* place it on top of everything else. The higher the number the
closer to the top. 10 usually does the trick */ }
Floating Box with Link: For Grandmaster +
[h1|top]Name of Top Content[/h1] /* the ‘top’ anchor is where we’ll jump to */
[container:side-box][url=#top]To Top[/url][/container]
:root { /* setup variables - this needs to be above the rest of your code */ --box-pad: 20px; /* the padding (space around contents) for our box */ --sideBox-bg: #333; /* the color for the box */ } .side-box{ border-radius: 10px; /* round the corners */ top: 200px; /* placed this many pixels from the top */ right: 50px; /* placed this many pixels from the right */ padding: var(--box-pad) ; background: var(--sideBox-bg) ; position: fixed; /* position: fixed; Keep it at the top, even if we scroll */ text-align: center; /* center our text */ width: 100px; /* make it a skinny little box so it’s not obtrusive on our page */ }
Dictionary Jump Box: For Grandmaster +
In your article, you’ll need to set up the anchors like [url=#LinkName]. I’ll leave that part for you to do. (See the Codex for more info on anchors.) After setting those up, paste this BBCode in section->’Sidebar: Over panel content’. Then edit as needed.
[h1|top]Name of Top Content[/h1] /* the ‘top’ anchor is where we’ll jump to */
[container:side-box-vocab]
[center][h3]Navigate[/h3][/center]
[table][td]
[url=#a]A[/url][br]
[url=#e]E[/url][br]
[url=#i]I[/url][br]
[url=#m]M[/url][br]
[url=#r]R[/url][br]
[url=#v]V[/url][br]
[/td]
[td]
[url=#b]B[/url][br]
[url=#f]F[/url][br]
[url=#j]J[/url][br]
[url=#n]N[/url][br]
[url=#s]S[/url][br]
[url=#w]W[/url][br]
[/td]
[td]
[url=#c]C[/url][br]
[url=#g]G[/url][br]
[url=#k]K[/url][br]
[url=#o]O[/url][br]
[url=#t]T[/url][br]
[url=#y]Y[/url][br]
[/td]
[td]
[url=#d]D[/url][br]
[url=#h]H[/url][br]
[url=#l]L[/url][br]
[url=#p]P[/url][br]
[url=#u]U[/url][br]
[url=#z]Z[/url][br]
[/td]
[/table]
[hr]
[small][small][small][small]
[url=#top]return to top[/url]
[/small][/small][/small][/small]
[/container]
.side-box-vocab{
opacity: 0.5; /* makes the whole menu transparent, so you can read what’s under it */
border-radius: 10px;
top: 100px;
right: 20px;
padding: 10px;
border: 3px RGBA(30, 30, 30, 0.3)solid; /* put a border around the box 3 px wide, in a dark grey that’s mostly transparent */
background: #ddd;
position: fixed;
z-index:10;
}
Friendly Reminders
- Make backups of your CSS! I accidentally had the editor open in two tabs for the same page and made changes in both tabs. Obviously, not everything saved. But I’d made a recent backup in Notepad++. It was easy to remake the change and paste it back into the CSS editor. Name your backups logically. My files are named after my world + the date.
- Test in more than one browser, if you can. I use both Chrome and Firefox, so I’ve started looking at my pages in both.
Coming Soon
Make Your World Look Awesome!
Let us know how you use these ideas. We’d love to see. Until next time, my fellow smiths. Go light up the forge!
Update 9/17/2019 – corrected the class name on the vocab jump box BBcode.
Update 9/19/2019 – WordPress stripped out several aspects of the code like the double dash. Corrected.
Trackbacks/Pingbacks