External CSS Not Rendering in Browser - css

Does anyone have any idea what my external style sheet isn't rendering in my browser?
Both files are in the same directory, I have tried multiple browsers, and I have cleared the cache on all of them multiple times. It is probably something small as this is my first time using an external style sheet but I am completely lost because everything seems correct.
heading {
font-family: arial;
color: red;
}
emphasis {
color: blue;
background-color: yellow;
}
<h1 class="heading">Cascading Style Sheets</h1>
<h2>Benefits</h2>
<p>Cascading Style Sheets offer many benefits to web designers. <em class="emphasis">CSS lets you separate style information from HTML</em>, allowing you to provide style sheets for different destination media as your web site requires. You can control the
display characteristics of an entire web site with a single style sheet, making maintenance and enhancements of display information a less taxing chore. You can express a wide range of style properties that increase the legibility, accessibility, and
delivery of your content. You can build page layouts, either flexible, fixed, or responsive to suit your user and content needs. As you will see in this chapter and through the rest of the book, CSS is easy to learn and apply to your web design projects.</p>

Solution provided by Micheal Platt:
In the external CSS, each class should be preceded with a .
Therefore:
.heading{
font-family: arial;
color: red;
}
.emphasis{
color: blue;
background-color: yellow;
}
Is the correct solution.

missed the dot at the beginning of the statement in css.
.heading {
font-family: arial;
color: red;
}
.emphasis {
color: blue;
background-color: yellow;
}

Related

CSS Master Styling Clarification

I have seen conflicting information about how to use a master style sheet and have experienced some bugs when testing methods. Just want to get clarification on the proper way to do this.
I would like to store cross website branding styles in a master global.css sheet and make page specific adjustments on a second .css file.
For example, this code would live on the master sheet:
#headline1{
font-family: 'Roboto', sans-serif;
font-size: 96px;
letter-spacing: -1.5px;
}
and this code would be page specific:
.headline {
color: #FFFFFF;
text-align: center;
}
I have recently read something that said you should not use ID in this manner. I've also run into issues when using it multiple times in the same grouping. I initially tried doing this using just classes instead of the ID, but it never worked. Not sure why.
Is this method considered proper? If not what is the proper way to do this?
If you create a master.css with:
.headline {
font-family: 'Roboto', sans-serif;
font-size: 96px;
color:#000
letter-spacing: -1.5px;
}
You can build upon/replace it per page as long as your custom css comes after the master.css
.headline {
font-size: 45px;
color: #FFFFFF;
text-align: center;
}
Quick example of a page:
<link rel="stylesheet" type="text/css" href="master.css"/>
<style>
.headline { //
font-size: 120px; // size overides master
color: #FF0000; // color overides master
text-align: right; // added alignment, which is overiding the browsers base css
}
</style>
I'm not sure if this is quite what you are looking for, but I hope it helps
In the example you provided a can only assume you have something along the lines of:
<div id="headline1"><span class="headline">Title</span></div>
This would basically mean any style applied to the div, the span would inherit unless told otherwise.
To further expand on this, you can also use inline styles <span style="color:#FFF"> which will dominate any other styling UNLESS an !important; has been added to a style element.

Bootstrap compiling both default and customized styles

I'm trying to modify my website based on a CMS which relies mostly on Bootstrap. I saw that after compiling sass files, in the compiled CSS I have both the default css selectors and the overridden ones. For example:
template.css?d544b92…:12881
a {
color: #1d60a1;
text-decoration: none;
background-color: transparent;
}
template.css?d544b92…:264
a {
color: #1d60a1;
text-decoration: none;
background-color: transparent;
}
The overridden ones are used, as expected but, though, having both in the compiled file makes it much larger. If someone could give me a little help I would really appreciate it. This is the normal behavior of bootstrap( v4) or am I doing something wrong?

Writing CSS for different brands

This is a somewhat abstract question but here goes.
A company recently partnered with another company for a small project but their brands are not aligned, so in certain areas of their site the pages need to respect the brand guidelines of whatever company they represent.
Currently all of the CSS is geared towards a singular brand e.g.
.solution-featured-video__title {
font-family: CircularStd;
font-size: 40px;
font-weight: 500;
line-height: 1.33;
color: #fff;
}
This is a piece of styling for the title of a solution video.
If the other brand wanted an identical component and I stick loosely to BEM, would it be appropriate to just use modifiers?
E.g.
.solution-featured-video__title--other-brand
In light of the comments I ask because there is also a business rule: whenever someone types easy in any form i.e. Easy, easy, EASY, it needs to be changed to easy.
My idea was to programmatically wrap a span around each instance.
Under BEM (Block, Element, Modifier), I think it would be perfectly acceptable to use the modifier as a means of adding brand specific styling to the element.
.solution-featured-video__title {
font-family: CircularStd;
font-size: 40px;
font-weight: 500;
line-height: 1.33;
color: #fff;
&--brand1 {
color: #000
}
}
You are effectively just modifying the styling of the block based on brand

CSS: is splitting layout and look and feel a good idea?

One of the things I find hard to work with in CSS is how rules mix layout (ie: position, sizing) and look and feel (color, shadows, fonts, etc.).
We're working in a 'reskin' project, where we want to keep the layout of our solution, but change the look and feel. To this end I'm thinking of splitting the current styles in two: one stylesheet for layout and the other for skin, and then replace the latter with the new, reskinned one.
Just to illustrate my point. A current CSS rule could look like this:
Styles.css:
.my-class {
/* layout rules */
width: 100px;
height: 50px;
float: left;
/* look and feel rules */
border: 1px solid red;
font-weight: bold;
}
My idea would be to split this into 2 individual rules, in 2 files:
Layout.css:
.my-class {
width: 100px;
height: 50px;
float: left;
}
Skin.css: (could be replaced with a different 'skin' file)
.my-class {
border: 1px solid red;
font-weight: bold;
}
Is there any reason why this would not work? Does this have any drawbacks (other than the increased page load time?)
If you have a clear way of separating the CSS you can do it this way. In our company it is separated the same way, you just have to pay attention when adding new CSS so you don't mix it up.
There is no increase in page load time, when you use PHP to merge the files together and minimize it when the user visits your website.
Check out this link, there is an explanation on how to combine and minify CSS with PHP.

OOCSS Separation of Container and Content?

Question: Is the second OOCSS principle really valid?
According to the OOCSS second principle you're not supposed to have location dependent styles:
Quote from https://github.com/stubbornella/oocss/wiki
Essentially, this means “rarely use location-dependent styles”. An object should look the same no matter where you put it. So instead of styling a specific h2 with .myObject h2 {...}, create and apply a class that describes the h2 in question, like h2 class="category".
Lets take a practical example of this. Say I have a standard 2.0 setup with a normal body (white background) and a huge footer (black background). In the body we have black links and in the footer of course we need white. Isn't the simplest and most intuitive way to achieve this simply to:
a{ color: #000; }
.footer a{ color: #FFF; }
If I where to follow OOCSS principles I'd have to first create a class:
.inverted{ color: #FFF; }
Then proceed to add that class to every link I want inverted. That seems like a hassle.
Isn't the purpose of the whole language that styles are made to Cascade?
Am I misunderstanding something here?
I think you are right in the sense that yes, in your specific example.. perhaps doing it your way would be easier. But then again, if you look at the first sentence in the OOCSS page:
How do you scale CSS for thousands of pages?
In that context.. the second principle makes perfect sense.. so using your same example (ie let's assume we implemented your solution).. let's say that a year down the road your company decides to create light grey buttons in the black footer having black text:
<!-- inside footer -->
<a class="button lightGrey">link</a>
in this case.. all the a tags will be white because they're covered by your cascading. So then we will have to go create another sytle just to undo what your solution did:
.footer a.button.lightGrey {
color: #000; /* huh? but i thought we did this before with a {color: #000;} ?*/
}
where as if we simply made a decision that all a tags by default are black (see last note):
a{ color: #000; }
then in the footer we will create a special type of link that are supposed to be white:
.footerLinks { color: #FFF }
then a year later some of the links are still white.. others within the greyLight button will be black:
<a class="button lightGrey">link</a>
then here we don't have to worry about undoing anything.. a tags have a default color.. and that's it. if 2 years later someone decides that the links inside the lightGrey buttons (anywhere on the site, not only withen the footer.. which is the whole point of OOCSS) should be red.. then this would be the OOCSS approach:
.redLink {
color: red;
}
and the html will be
<a class="button lightGrey redLink">link</a>
in this case it won't matter if we take out the .lightGrey class, or we can have this code within or not within a footer .. it's all the same.. it results in more predictable and re-usable code.. which is OOCSS (I'm very glad that they're finally formalising this.. thanks a lot for the post btw).
One last note: To be pure OOCSS, one shouldn't change the default color of a ie a {color: #000;} is wrong!, it should be left to it's default color (which is blue).. whenever anyone wants to change that color.. then they must specify it ie
<a class="redLink">..</a>
so in this case it's more like the default a is the parent class.. and everything else subclasses it and overrides its default behaviour..
update - response to comments:
reputable site argument:
such initiatives are almost always driven by the community then adopted by reputable companies.. and even when they are adopted by larger companies it usually happens from the bottom up through enthusiastic developers who advocate for such change.. I for one was such an advocate when I was working in Amazon. And even when it's adopted.. it's usually at a small scale and not across all units in the org. it wouldn't even be a good idea for the Googles and the Amazons and the facebooks etc to enforce such a rule b/c there will always be a difference of opinion.. not to mention that such micromanagement would constrain the engineer's creativity.. there could be a guideline in a wiki for a team (ie we had one for the Amazon Kindle Touch app store) but to enforce that rule across 10,000 engineers working across the company wouldn't be practical nor desirable.
So in short if you see value in OOCSS, and start implementing on your site, and advocating it to your fellow web devs, and then it becomes a trend, that's when it eventually becomes an industry wide best practice and that's when you can expect to see it on facebook etc.
example:
take a look at this:
simple: http://jsfiddle.net/64sBg/
a bit more detailed: http://jsfiddle.net/64sBg/2/
without going too much detail (I'm sure you will see the pattern) you can see that the granularity in css descriptions allows for subtle changes without any redundancy in style definition. So notice the left arrow vs right arrow.. also the .red and .blue styles can be subsequently applied to tables etc..
also notice that there isn't a single cascading in my css.. so my styles can be completely independently applied (ie implementing the rule An object should look the same no matter where you put it)
lastly.. there is still use for cascading.. you can definitely use it in your jQuery selectors for example.. also cascading happens by default (ie without you having to explicitly set it in your css styles).. so if you take look at the css below.. you will notice that the font properties of body has cascaded down to all the buttons.
<a class="button blue dark">
<div class=" arrowDownWhite rightArrow">Analytics</div>
</a>
<a class="button red dark">
<div class=" arrowDownWhite leftArrow">Actions</div>
</a>
<a class="button grey light">
<div class=" arrowDownRed leftArrow">options</div>
</a>
and css:
body
{
font-family: Trebuchet MS,Liberation Sans,DejaVu Sans,sans-serif;
font-size: 15pt;
}
.button
{
padding: .5em 1em;
display: inline-block;
text-decoration: none;
}
.dark {
color: white;
}
.light{
color: #E40E62;
}
.blue
{
background-color: #51C8E8;
}
.red
{
background-color: #E40E62;
}
.grey
{
background-color: #E0E0E0 ;
}
.arrowDownWhite
{
background-image:url(http://s2.postimage.org/ywam7ec4l/small_Arrow_Down_White.png);
background-repeat:no-repeat;
}
.arrowDownRed
{
background-image:url(http://s2.postimage.org/je5743t2d/small_Arrow_Down_Red.png);
background-repeat:no-repeat;
}
.leftArrow
{
padding-left: 1em;
background-position: left center;
}
.rightArrow
{
padding-right: 1em;
background-position: right center;
}
It is worth the hassle of separating your skin from the container.
Lets look beyond colors. I wish Nicole Sullivan provided better examples than she does. I have 23 web sites that an contain
Menus
Tabs
Toolbars
Horizontal and Vertical Lists of Links
All of them are Skins of the Nav abstraction
I started off created an abstraction class to handle the common code between all of them. I added a few modifiers to change the orientation from horizontal to vertical, and also the floated position of it. I kept all colors out of the abstraction as well as css rules that can change based on the skin I apply to it.
/* Object */
.nav
{
margin-bottom: 1.5em; margin-left: 0; padding-left: 0; list-style: none;
}
/* Modifier */
.nav--stack .nav__item
{
display: block;
}
.nav--right
{
float: right;
}
/* Elements */
.nav__item
{
float:left
}
.nav__item__link
{
display:none;
}
Menu Skin
I needed a skin that made the .nav abstraction look like a sidebar menu. In case you are wondering, I did not put the padding for .nav_item_link above is because it can change based on the skin. The tabs skin has it set for 2px.
/* Object */
.menu
{
}
/* Elements */
.menu .nav__item--current.nav__item__link
{
color: #fff; background: blue;
}
.menu .nav__item__link
{
padding: 4px; border-radius: 4px;
}
.menu .nav__item__link:hover
{
background: #eee
}
Notice to keep things location-independent - I have 0 tag names. I don't style li and a children on .nav like bootstrap does. This code could be used on dls or even divs and has better performance based on how selector engines read rules.
To me the benefit of just having to skin the objects I have for all 23 sites I have is worth any hassle.

Resources