deciphering a sass mixin - sass

familiarizing myself with a code base for an in-progress project that I will be joining soon. I came across this mixin being used frequently and I have a couple of questions.
1. is this a fairly standard practice or css idiom and I am just unfamiliar with it?
2. Looks like it's adding an empty space after the pseudo element for the clearfix, but why insert one :before also?
#mixin container
&:before, &:after
content: ""
display: table
&:after
clear: both
*zoom: 1
Obviously I could just wait and ask the team when I join up but I want to know now dangit! Also, if it's an idiom I should be familiar with, maybe I have some googling to do before then lol.
Thanks everyone!

You're looking at the "micro clearfix" by Nicolas Gallagher (see: http://nicolasgallagher.com/micro-clearfix-hack/). The explanation behind the :before is as follows:
This “micro clearfix” generates pseudo-elements and sets their display
to table. This creates an anonymous table-cell and a new block
formatting context that means the :before pseudo-element prevents
top-margin collapse. The :after pseudo-element is used to clear the
floats. As a result, there is no need to hide any generated content
and the total amount of code needed is reduced.
Including the :before selector is not necessary to clear the floats,
but it prevents top-margins from collapsing in modern browsers.

Related

I just don't get it, why bother using SASS if it compiles to CSS?

So I am on the fence about learning SASS. I still don't get it. Why bother if I can write CSS and understand it and it works.
Why learn to raise chickens if all I want is the egg?
It seems as though the SASS would take longer to figure out then just writing the css.
I can use variables in CSS3. I also don't understand why you would write .foo {padding: $width/2;}
I have to figure out what padding I want then figure out the mathematical equation to write it. I just want to write padding: 12px; and be done...
Please enlighten me on WHAT Makes SASS better? quicker? easier?
thanks -
Advantages are like this
You can separate your sass files into modular areas. For instance
SASS
1. tools (put bourbon or bitters here)
2. basics (body, links or common things)
3. modules (reuasable stuff. Boxes, cards, etc)
4. layouts (your containers, footers, headers etc)
In doing this you can easily find where the CSS is that you may want to change. There are several youtube videos that discuss how to make modular sass directorys.
You can use variables. Suppose you have a color that is used several times in a CSS file. SASS allows you to change one variable and that would change all instances of that usage. $red: #ff0000 is an example of a variable. When you use it, just use
color: $red
Mixins are functions that you can use and easily create a small amount of sass that will convert into large amounts of CSS.
I suggest watching videos on youtube to learn it. You wont be sorry. Especially learn modular usage like SMACSS
Here is a link to a vid that will help you
Sass is an extension of CSS that adds power and elegance to the basic language. It allows you to use variables, nested rules, mixins, inline imports, and more, all with a fully CSS-compatible syntax. Sass helps keep large stylesheets well-organized, and get small stylesheets up and running quickly, particularly with the help of the Compass style library.
If you choose to stick with CSS, there is nothing wrong with that. (My understanding is that) People like SASS because they can type is with variables and such and it will then be converted into regular CSS. So yes, it does basically the same thing, but the improvements come as writing it, which is faster and more efficient. People that use SASS like that they don't have to write the same or similar things, they can instead just use SASS and get it converted to CSS which is faster than writing it, now I am just a SASS beginner, so please don't read into my thoughts that much, some of this may be not 100% correct, but it is my understanding. In my opinion, you should look into SASS and maybe try it a little, if you find it is more efficient and you like it more, stick with it, but if you decide it just isn't for you, then just stick with CSS.

Bold code in rst

How can I get code (monospace) text that is bold in rst (I'm using Sphinx)? Anything in :: seems to be rendered literally, as with ``, so ``**bold**`` doesn't work.
In general, nested inline markup is not possible in reStructuredText. There are more or less ugly workarounds, such as using raw HTML. Like this:
.. raw:: html
<div>Some stuff <pre>some <b>bold</b> text</pre>...</div>
Actually using raw for code is a very bad thing to do as it ignores the beautiful Pygments highlighting and complicates things to extreme. First thing to do is to play with different Pygments highlighting styles. You can find a functional demo here. Then you may set the appropriate highlighting in conf.py. If none of the styles make the desired part of your code bold, you may consider creating your own Pygments theme, which is unfamiliar territory for me, but shouldn't be that hard.
There is third thing to try though, you could look up the class of the word you need to highlight and add a rule to your CSS. Pygments produce this seemingly gibberish classes like nv, ls, etc for every type of the highlighted words. But keep in mind, that every instance of this type will be highlighted. If your chosen word is a class definition - all class definitions will be highlighted.
Only if none of these options apply should you consider using something as atrocious as raw, because every time someone uses raw, Sphinx dies a little. Do you really want Sphinx to die?
Most likely restructured text does not support formatting options you are asking for.
However you are free to add your own :: admonition directives which have custom CSS styling over them.
Example for a custom block and CSS styling. RST:
.. admonition:: foobar
My custom text here
CSS:
.admonition-foobar {
font-weight: bold;
}

CKEditor 4 uses separate span tags for each formatting action

I've been searching through a large number of CKEditor posts and have yet to find a targeted answer to this question. I know CKEditor is very configurable (which I haven't leveraged yet.)
For every formatting action performed, CKEditor wraps it in a separate span tag. So if I 1) change the font to Arial 2) change the size to 36px 3) change the color, I end up with this HTML which seems unnecessarily verbose.
<p><span style="color:#DAA520"><span style="font-size:36px"><span style="font-family:arial,helvetica,sans-serif">Hi</span></span></span></p>
I would rather it just did something like <p style="..styles list">Hi</p>
My question: Is this configurable (and how), and/or is there a rationale for them doing it this way where I should just accept the behavior?
It certainly seems like a relatively clean means of implementation on CK Editor's part, and would help it avoid conflicting logic for different styles applied to dissimilar spans.
If you as the user want consistent differences with multiple variables like size, color, or font, you should really be using classes, I would think. A WYSIWYG editor like CK is designed to implement HTML code that is readable, not pretty. If you want more elegant code, you probably need to write it yourself.
Since other adaptations from WYSIWYG editors/ word processors generate obscene looking code, e.g. Microsoft Word/ Outlook, or Adobe's new CSS from layout feature, this span output isn't actually too bad.

Block elements overlapping with singularitygs

I'm doing my first project with singularity grid system and I'm loving it so far. However, I'm having a strange problem in a section where I have an <h2> and <h3> elements overlapping... really having an hard time figuring what's the problem.
My project in development is available at:
http://senseslabv3.brunomonteiro.mixture.io/
First <section> with class=intro.
Does anyone have a clue about it's going on?
Thanks for your time.
As the others have said, you need to clear your floats. By default, Singularity's output style is "Isolation" which requires a knowledge of how floats should get cleared (clear: left, clear: right, clear: both, clear: none). Singularity assumes no clear (clear: none) which means that grid items may overlap if not properly cleared. It does this to adhere to the most common mental model for the Isolation output method, specifically placing blocks at a discrete point on the grid. Clearing your floats will clear them to an item's margin edge, most visibly by creating new rows. See the Mozilla Developer Network article on Clear.
Note, clearing your floats and clearfixing as proposed by lolmaus actually do different things. Clearing your float will clear items to margin edges, whereas clearfixing an item will ensure that all of its floated children are properly contained.
The Float output adheres to a different mental model, one of walking across a row of your grid, and therefore automatically clears your floats for you. If you'd prefer to use the Float output style as your default, simply add $output: 'float' to your Sass file before calling your grid. This will change your global output style context. Alternatively, you can use float-span to use the Float output style mental model and output on-demand instead of grid-span, or pass $output-style: 'float' as an option to grid-span.
Take a look at the documentation for Output Styles, Output Span, Float Span, and Context Overrides in grid-span for a deeper dive into the different output styles and options available in Singularity.
Clear both needs to be declared somewhere below your grid-span mixin .tag h3 {clear: both;}
instead of the ugly <div style="clear: both;"></div> consider this:
.intro h2 {
#include pie-clearfix; }
Or, if you use toolkit:
.intro h2 {
#extend %clearfix-micro; }
We might better address your problem if you share your SASS code.
This is an old question but I just ran into the problem. Snugug's answer worked perfect but I wanted to show the code that worked for me. (Couldn't put code in a comment)
//Main content container
.l-main {
#include breakpoint(80em) {
#include grid-span(16, 3, 20);
}
}
// A full width banner inside content container. I needed this to clear because there are several other smaller columns/grids above and below the banner.
.b-banner {
#include breakpoint(80em) {
#include float-span(16, 1, last);
}
}

Smart approach to CSS3

do You have any elegant approach to benefit from CSS3 features, like border radius or gradients?
I am looking for a solution that would avoid browser-specific CSS properties and browser-specific stylesheet files. I find them both hard to maintain and too verbose.
It could be a Javascript library that would take care of cross-browser compatibilit. Thus, I could use only W3C CSS3 properties support (not browser-specific) and get rid of the library when browsers will start tu support CSS3 well.
So far, I have found these resources that seem to fulfill at least some of my expectations:
eCSStender - JS that is told to imitate the CSS3 features on different browsers (even IE6), I haven't tested yet, however (read about eCSStender)
Mordernizr - JS that detects which CSS3 properties the browser supports
... I'll fiil it with your answers
Or maybe you have other approach that lets You take advantage of CSS3 without very verbose code?
You could use LESS, which has a border-radius example on their homepage:
.rounded_corners (#radius: 5px) {
-moz-border-radius: #radius;
-webkit-border-radius: #radius;
border-radius: #radius;
}
#header {
.rounded_corners;
}
However, I really don't find it that messy to use browser prefixes. For a border-radius, the only thing you need is this:
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
That will work in about a dozen browsers (if you include mobile browsers). Using indentation in this fashion also makes it easier not to forget to update one of the properties. When you decide do drop support for Safari 4 or whatever, you can simply search and replace the rules you want to remove from your CSS files.
Compare that to when we needed box model hacks, NS4, IE5/Mac fixes, and all of that crap.
This is not CSS3 specific, but as you are asking for a concise way to handle the styles and do mention modernizr (which works by adding classes like no-borderradius to your <html> element if that feature is not available), I thought it might be helpful for a generally improved way to organize your CSS.
There is LESS that allows the use of variables, mixins or nested rules in CSS (see the link for examples). This however requires you to compile your .less files into valid .css. To avoid this, there is/will be less.js (see also: Less.js Will Obsolete CSS) which enables you to include .less files directly in your page (useful at least during development).
I think LESS does not require you to learn a lot of new syntax rules and might help to organize fallback CSS right next to the "real" style.

Resources