CSS 101: Block & Inline elements
By ezra vancilPlay with Display
If your new to CSS, you've probably stayed away from the "Display" property. Well you might be missing out on a powerful tool. It only has to values, or three things it can do, so it's easy to remember .
- display: inline;
- display: block;
- displa; none;
All three of these values are extremely useful. Think of the display:none that we used in last weeks tip on hiding elements on a page, like the birthday element that so many ladies hate... display:none; You can even hide sorts of stuff you don't want on your page and is not yet an option in the layout manager.
Block and Inline are just as powerful. Lets say you want the background color of a DIV with a ad or image in it to automatically span the width of your text, so as not to worry about setting an exact pixel width. You would use the INLINE value to do this, because a DIV is a block element.
The difference between Block and Inline These are the most common elements that are blocks, and it's pretty easy to see this because they are usually designed visually as blocks.
-
Tame your posts: Part 2 - Images
By ezra vancilThe problem with playing to much with individual page element styles, such as the "blog-post img" instead of broad site wide elements, such as just "img" is that your probably going to effect something somewhere you didn't want to. This is the case with our "img" style we did on the .blog entry in part 1 of this "tame your post" series. If you jumped right in with our tutorial and have already styled your blog post images, you may not know it, but you have a problem. here it is:
When we styled our blog-entry images, we inadvertently styled the icons in our "comments view."See the problem? When we styled our blog-entry images, we inadvertently styled the icons in our "comments view." Just click to comment on any of your posts and you will see the mess we have created in the individual post page. Hey don't get mad at me! I warned you at the end of the last tutorial.
We better fix this problem before your members see it. Here is how.
Each page in our socialgo templates has a individual body tag. Take our welcome page for instance, the individual body is "id=magazine." Wasn't that nice of them to do that for us. Now we can control each page with precise properties that only effect it's tag, and not the rest of the template. Don't go trying to do this all over the place just this minute, there are some problems with this especially in the forum and groups pages. I'll post on it later. for right now lets fix this image problem.
To remove the styles from the icons above we will use the "body id="read" to zap the styles on the "h3 img" and the "p img" where the icons reside.
It goes like this:
The code for the title and date looks something like this:
Tame your post: part 1
Published Saturday 24th January 2009
The only place these icons show up is on the individual posts
pages and the body id for these pages is "read." We're going to
override or image styles that effect all images in a post by
stylying all .'s and the
We could just style the 's id of
"entry-stats" But, I also don't want the image styles to effect
andy inline images that might be in between
styles in the body of my blog.
.blog-entry img {
padding: 10px;
background: #ebf1cf;
border: 1px solid #e2e7b1;
}
In the first copy insert a h3:
.blog-entry h3 img {
padding: 10px;
background: #ebf1cf;
border: 1px solid #e2e7b1;
}
In the second copy insert P:
.blog-entry p img {
padding: 10px;
background: #ebf1cf;
border: 1px solid #e2e7b1;
}
Mow on both H3 and P styles change all values to zero or none, this will override the global "img" styles and tell just the h3 and p styles to zap the image styles. Here is the final product:
.blog-entry h3 img {
padding: 0px;
background: none;
border: 0px solid #e2e7b1;
}
In the second copy insert P:
.blog-entry p img {
padding: 0px;
background: none;
border: 0px solid #e2e7b1;
}
With a comma, you could also do it in one declaration like so:
.blog-entry p img, .blog-entry p img {
padding: 0px;
background: none;
border: 0px solid #e2e7b1;
}
Next time we are going to look at the Comments link on our main blog page and see if we can make it a bit more noticeable.
<101 Fundamentals: Selectors
By ezra vancilI've had allot of questions from other Socialgo'ers that smelled strangely of my early days and I want to scream stop! go back to go and collect $200. I decided to create a ground zero fundamentals series, and I hope it's helpful to those brand new to code, and those looking to sturdy their foundation.
A huge mistake I made, and still constantly make, is the lust for instant gratification at the expense of knowing what I'm consuming. Translated to XHTML and CSS this seemingly ambitious drive to get to the good stuff, causes what I call Rat's nest Code. Hey, but it does the trick right? Maybe, kinda like duck tape does the trick.
The problem with racing down the road with out knowing what all the road signs mean is you'll eventually collide head first with a pedestrian, and that pedestrian is usually one of your pissed off users, a client or a boss. How this happened to me, countless times, is I got the site going, looking good -- by the skin of my teeth. Then 4 months later, after I had done twenty more sites, tragedy struck. Something goes wrong, someone sneezed on your CSS or something and you got to go rescue the site. Well I would open up those four month old sites and nearly collapse. I didn't remember what I did, or how I did it. I had ripped most of the code from other sites and the rest ducked taped together with 20 different tutorials from 20 different versions of how to code. I can't tell you how many cuss words I learned back then, some of them would make the 18+ sights blush.
For you as a socialgo network owner,it probably will mean loss of members, loss of profits, loss of confidence.I've only been at socialgo for a short time, and I have already broken my sites, in a big way, accidentally. ( Usually because if you have several networks, whenever you go to admin it still pops back to your first network on the list. well, I'd go in the wrong network and start deleting stuff and so on..)
The malfunction, for me at least, was simply that I didn't know what the hell I was doing and didn't want to admit it. I'd learned how to steel code and make it work, but I never learned how to write code and understand how it was supposed to work together.
I finally forced myself to re-read all those books on my shelf and pay attention to the 90% I skipped over.
(By the way, after my little sermon, my code is still ratty... I'm working on it)
This is the real beginning fundamentals, so if you know all this please skip to the next blog.
SIMPLE SELECTOR
A HTML page is made up of ELEMENTS and ELEMENTS are different structures like buildings.
Here is a
ELEMENT:
I talk to my dog because Farty the cat has bad breath
With a CSS SELECTOR, I can grab hold of a TAG by it's NAME Like this:
p {}
Thats it!
'sp is name. This is a
SIMPLE SELECTOR because it's so damn simple. Now
I can tell this p what to do with CSS.
ID SELECTOR
But, hell there are like two thousand's
in my network, what if I just want to
grab hold of one element that talks about my dog's breath. Just
like I my State ID refers to me in a broad term saying that I am a
MALE- and then in a specific term, that I am EZRA. The element
works the same. I just have to give it the specific name, we'll
call it Hara because that's my dogs name.
#hara {}
That's it! This is a ID SELECTOR.Class SELECTOR
Now, lets say my Network is all about dogs and cats and I want all the Cat Elements to be orange and the dog Elements to be blue. Because dogs and cats are two different CLASSES of animals; I have to give them a CLASS so instead of a specific name ID like
I'll give them a class so I can call all the dogs and cats:
Think of it this way:
= animal
= dog
= my dog
now I'll call the cats with CSS:
.cat {}
Thats it. This is a CLASS SELECTOR.
Wrap it up Now
To close it all up I'll show you what it looks like when I order my dogs and cats to be orange and blue. We'll do this by commanding the selectors with Properties and Values which we will be covering in the next lesson. Here is a peek at how it looks all together:
.cat {
color: orange;
}
.dog {
color: blue;
}
and i'll make my dog pink.
#hara {
color: pink;
}