Loading...

Top
PFQ Banner

This is PokéFarm Q, a free online Pokémon collectables game.

Already a user? New to PFQ?

Single post in Guide to CSS: Beginner to Expert

Forum Index > PokéFarm > Guides > Guide to CSS: Beginner to Expert >

Aemilia's Avatarhypermode-12.pngAemilia
Aemilia's Avatar
booster.pnghypermode.pngarceus.pnga.png
Intermediate to Expert Codes
  • Selectors
  • HR
  • Columns
  • @Media
  • Positioning
  • Z-Index
  • Display
  • Visibility
  • Fonts
  • Transform
  • Animations
  • Navigation

Selectors

Miscellaneous

Before I get into some of the selectors, I'm going to throw these miscallenous ones here. First, you can do
.class element
to select element with the parent of .class. This can be two elements, two classes, so long as one is a parent of the other. If you do this, this would include elements further in the code, such as if you do links inside of a .body class. This would affect ALL links, including those inside a class that's still within the .body class. If you don't want it to affect those inside of another class within the .body class, for example, then you can do
.body > a
to affect only links that are direct descendents of the .body class, with no other classes in between them. Often you may find yourself wanting to affect a different class when hovered over (hover is explained below), you can use
.class1:hover + .class2
where when the first class is hovered, it will affect the second class that is listed (which can still be swapped out for elements instead of a specific class). This selects the
.class2
placed immediately after
.class1
. If they aren't necessarily placed after each other, but are in the same parent component, you can use the sibling selector:
.class1:hover ~ .class2
. Understanding these means you can make some really intricate hover effects and even create your own tooltips, for example, from scratch without using the built in BBC if you wanted.
Adjacent classes are classes that come after each other, each class is opened and closed outside of each other. This means one is not opened inside of the other. Parent/child classes, however, are opened inside of the other.
[sc=class1][/sc][sc=class2][/sc]
is an example of adjacent classes, while
[sc=class1][sc=class2][/sc][/sc]
is an example of child/parent classes (class1 is the "parent" or first class and class2 is the "child" or inner class.

:active

Used for links and selects the current active link (the exact moment that you are clicking it), used like this:
a:active

::after

Used to insert something after an element or class. If I wanted to add an image after using a class, I can do this:
.class::after { content: url('IMGURL'); }
and style it as necessary such as modify size or padding. Using
content: 'stuff here';
can add text after the element, or an image similar to the example code above. The property
content
can be used in any block of code to add some sort of content there, but most commonly used alongside the
::after
or
::before
selectors.

::before

Used to insert something before an element or class. I've been using this every time I add a note:
[sc=note]My note![/sc] [style].note::before { content: url('https://pfq-static.com/img/farmbtns/farm_news.png'); margin-right: 2px; }[/style]
My note!

:first-child

Selects every element or class that is the first in its parent, such as
.note::first-child
which would only select the first
.note
within each tab as it would be the first within its parent class (in this case
.tab
).

:hover

Hover effects! You can mix these with transitions to create a cool effect. You can make a link change colour or design when hovered over using
a:hover
for example, but this is not limited to just links.

:last-child

Similar to
:first-child
except it selects the last element within its parent class or element.

:link

Selects all unvisited links using
a:link
, which is the same as just using
a
to select them.

:not(selector)

Selects everything except the class or element specified, such as
li:not(.tab-active)
which would select all tabs except for the currently active tab.

:nth-child(n)

This is similar to both
:first-child
and
:last-child
, except it gives you a little more control. The
n
is a counter and you can modify this variable to say
3n + 1
which would modify every third of its type starting with the first one. You can also use the values
even
or
odd
to select every other one rather than figuring out the equation to use.

::selection

Modifies the colour and design of text selected by a user. I use this in my personal site skin to change the colour of the text and the background that is used rather than the default from the browser.

:visited

Selects every link that has been visited using this:
a:visited
.

Horizontal Rule

To modify horizontal rules made using
[hr]
, you select it using
hr
from which you can recolour the line using both the
border
and
background
properties (you need to include both or on mobile there will be a gap in the middle!). You can also set it to an image! Make sure to set the height of the horizontal rule to the same size of the image or it will cut off. There are many effects you can do with these. I personally love the faded effect because it's simple looking and not terribly distracting. All of these codes are here for you to use if you wish. Change the colours to match your template! Fade effect:
hr { border: 0; height: 2px; background-image: linear-gradient(to right, rgba(214, 228, 49, 0), rgba(214, 228, 49, 0.75), rgba(214, 228, 49, 0)); }

Double curved effect:
hr { overflow: visible; /* For IE */ height: 30px; border-style: solid; border-color: black; border-width: 1px 0 0 0; border-radius: 20px; } hr:before { display: block; content: ""; height: 30px; margin-top: -31px; border-style: solid; border-color: black; border-width: 0 0 1px 0; border-radius: 20px; }

Curved effect:
hr { height: 30px; border-style: solid; border-color: #8c8b8b; border-width: 1px 0 0 0; border-radius: 20px; } hr.before { display: block; content: ""; height: 30px; margin-top: -31px; border-style: solid; border-color: #8c8b8b; border-width: 0 0 1px 0; border-radius: 20px; }

Columns

Everything about columns and using them can be found in my journal at this post. Adding it directly to this post messes with the tabs due to how it is styled, but feel free to ask any and all questions you have here or message me directly. There's another way to use columns but is a lot less flexible and cannot be used as easily as a result, but you can read more about the properties here.

@Media

To make things mobile friendly, you can use
@media
queries. For more details, you can read about it here, but I recommend using the built in classes through PFQ rather than media queries, which are outlined in the PFQ Codes section of the guide.

Positioning

Sometimes you may need to move something or move it in some way. There are a few different values for it, but two of them are not allowed on PFQ and will not be discussed as a result. To use,
position: static;
is the property and the default value. Static just means that the elements are rendered in order of flow and cannot be modified. Changing the value to
absolute
renders the element or class relative to its first positioned non-static parent/ancestor element (as it may not necessarily be the direct parent). Using the
relative
value allows you to position the element or class relative to its original position using the following properties:
left
,
right
,
top
, and
bottom
. For example,
left: 25px;
adds 25px to the left position, effectively moving it right 25px. You can use percentages instead. Be careful using this property as it can affect child elements.

Z-Index

Z-index is used for layering. Sometimes you to hide something under another element and on hover show it. You can use the z-index property and change it when something else is hovered over it to show it, or to layer something above or below another element. Use
z-index: #;
to change the ordering. There are no units used and the number can be negative.

Display

I'm going to list each value used for the property
display
and then the use of each with the exception of two that I will be going more in depth with at the end. There's
inline
, displays an element as an inline element and any height and width properties will have no effect (links are an example of an inline element);
block
, displays an element as a block element, it starts on a new line, and takes up the whole width (headers are an example of a block element);
inline-block
, displays an element as an inline-level block container, the element itself is formatted as an inline element, but you can apply height and width values; and
none
which hides the content completely and is removed from the flow.

Flex

Flex is a really handy tool that allows things to be curated for mobile and PC. It's amazing for anything that could use a table or has content formatting similar to a table. The first thing you want to do is create a container to contain all of the flex items, which are classes within the container class:
[sc=container][sc=item][/sc][sc=item][/sc][/sc]
I've also already added two styleclasses to represent two items within the flex box. Some properties you must apply to the parent container while others you can apply to the individual items. I'll start by listing everything that goes in the parent container. First, you must set the display:
display: flex;
. Next establish which direction you want the items to flow in using
flex-direction: row;
. The value
row
flows in a row in the same order it is listed,
row-reverse
flips the order but still flows in a row,
column
flows in a column in the same order it is listed,
column-reverse
flips the order but flows in a column. Now you can set how it wraps. By default, it will try to fit everything on the same line, but you can change that using
flex-wrap: nowrap;
which is the default I just mentioned,
wrap
value will allow the items to wrap to the next line or column if there isn't enough space available, and
wrap-reverse
will wrap into multiple lines or columns from bottom to top instead of top to bottom. Generally,
wrap
is the best value for this. You can combine these two properties into
flex-flow: column wrap;
for example, or whichever two values you need. Now you can choose how to align the items using
justify-content: center;
which centers the items,
flex-start
is the default value and packs them at the top left corner and flows in the direction as you specified without modifying,
space-between
evenly spaces the items on each line with the first item on the starting line and the last item on the final line,
space-around
gives each item the same space on each side (which means double the space between middle items due to both having that unit of space on their left and right), and
space-evenly
which spaces everything equally. Next is
align-content: center;
which centers everything vertically even if the items are not the same height. The only only other value I would consider using is
stretch
to make each item the same height. You can use
column-gap: #px;
and
row-gap: #px;
or simply
gap: RG#px CG#px;
to determine the exact spacing between items. RG is short for row-gap and CG is short for column-gap, though if the values are the same, you only need to list it once. Now you can modify the individual items. Using
order: #;
you can set the order that they display in the flex box instead of reorganising the code to be in that order. Next is
flex-grow: 1;
for each item. If you need one to be larger than the others, you can raise the number to be bigger by that amount (a value of 2 would be as close to twice as large as it can make it). Similarly,
flex-shrink: 1;
allows an item to be slightly smaller. The
flex-wrap
property is what allows the items to be "flexible" and move to a new line as necessary. A good guide to using flexbox and some of the other values not mentioned can be located here.

Grid

Grids are good for things that are two dimensional, while flex is better for simple layouts. Grids are great alternatives to using a table as it will automatically place as many items in a row as can fit on the viewer's display port (monitor/screen). Similar to flex box, you set up a container class and then the items within it. There's a lot of elements to setting these up and using so I will be offering free to use grid tables in the future, but a detailed guide to setting up your own can be loacted here.

Visibility

Visibility is used to show or hide an element or class. Note that even if you use
visibility: hidden;
, the space that the element or class takes up is still present. To completely hide the element and remove from the space, use
display: none;
instead.
.class { visibility: hidden; height: 30px; width: 75px; }
Hover over me to show the hidden text!
Hidden!

Fonts

You can use non-websafe fonts as well, however it can be a little more complicated to use. While there are other ways to have custom fonts, I recommend using Google Fonts to find them.

QUOTE originally posted by Niall

Using fonts on PFQ is a little buggy; instead of posting the font src you need to post the actual code. So copy the “fonts.googleapis.com” website, open it in your browser (it’s code) and paste the code over the code you posted below. Since this is an English website you only need Latin and Latin extended if they have it. Don’t forget to add the font family to your body CSS. Example:
[style].class { // Latin @font-face { } (The rest of your code) }[/style]

Transform

You can modify an element using transform. Note that whatever effect you use still needs to meet all legibility guidelines! The property
transform
has several values it can take. Some examples are
translate(#)
,
rotate(#deg)
, and
scale(#)
. You can read about each type of value here as there is quite a list, but these three are the most common of them and do exactly as they sound.

Animations

This is one section that I want to get someone else to assist with explaining as it is rather complex and a good portion of it does not work on PFQ.

Transitions

The first way is to use the
transition
property, which allows for something to ease into another version. This gets mixed with the
:hover
selector to transition, for example, text from white to pink. You can also do something more complex like this about me that I made, where the image turns over like a card. To use place in the block that does NOT have the hover selector used. It functions like this:
transition: property duration timing-function delay;
where property is the property you would like to transition (color for the example I gave above) or use the keyword all to affect every property, duration is how long you want the transition to last (I recommend around .5s for most transitions, though it may be slower or faster), timing-funtion can be a number of values (most commonly used are linear, ease-in, ease-out, and ease-in-out, the full list can be found here), delay (which is optional) can delay the start of the transition by however long you set it.

Animation

The other way is using the
animation
property. PFQ has some animations that it uses. The name of each animations is: pulse, fade, pling, spin, nice_mainstar, nice_star, nice_popin, and nice_popout. These can be used within a post, however, make sure not to use it in a way that could be too quick and flash rapidly. To create your own animations, you would create a
@keyframes
declaration. These cannot be used within a post, but only in your site skin. To set up the animation you wish to create, use one of the following:
@keyframes animationName { from{property: value;} to{property: value;} } @keyframes animationName { 0%{property: value;} 50%{property: value;} 100%{property: value;} }
The first version is useful for when you have just the start and stop properties you want and only want those two values. The second is used for multiple stops so it does a few things (such as change text from a purple to pink to green) before it hits the end. The numbers for it can be changed, but the 0% and 100% need to be present. It can have more values in between (such as 82% if you wanted) with the same set up within it. After creating the animation, you need to apply it to something. Within the declaration block that you want it to apply to, use
animation: name duration timing-function delay iteration-count direction fill-mode play-state;
. You can read more about each property here. Here's an example for skins that spins eggs when hovered over them (which is free to use):
@-ms-keyframes spin // for Explorer { from { -ms-transform: rotate(0deg); } to { -ms-transform: rotate(360deg); } } @-moz-keyframes spin // for Firefox { from { -moz-transform: rotate(0deg); } to { -moz-transform: rotate(360deg); } } @-webkit-keyframes spin // for Chrome/Safari/Opera { from { -webkit-transform: rotate(0deg); } to { -webkit-transform: rotate(360deg); } } @keyframes spin // for Edge { from { transform:rotate(0deg); } to { transform:rotate(360deg); } } #shelterpage #shelter #shelterarea > .pokemon[data-stage*="egg"] > img:hover { -webkit-animation-name: spin; -webkit-animation-duration: 4000ms; -webkit-animation-iteration-count: infinite; -webkit-animation-timing-function: linear; -moz-animation-name: spin; -moz-animation-duration: 4000ms; -moz-animation-iteration-count: infinite; -moz-animation-timing-function: linear; -ms-animation-name: spin; -ms-animation-duration: 4000ms; -ms-animation-iteration-count: infinite; -ms-animation-timing-function: linear; animation-name: spin; animation-duration: 4000ms; animation-iteration-count: infinite; animation-timing-function: linear; }
Buying: summon_los.png BSDs 20 ZC summon_nec.png Prisms 70 ZC
Icons/Template by Aemilia

by Kaede

© PokéFarm 2009-2024 (Full details)Contact | Rules | Privacy | Reviews 4.6★Get shortlink for this page