Archive

Posts Tagged ‘Cascading Style Sheets’

Tips – CSS Selectors and HTML Branches

August 14, 2014 Leave a comment

As i mentioned in a previous post, I’m learning HTML/Javascript at the moment via Codecademy and will post stuff I have learnt, so others who follow/Google can learn. These are just snippets, but the site is a great learning tool.

So CSS Selectors – CSS is a very powerful way of styling and positioning your HTML elements. The syntax is simple, you use the HTML element as the selector! Good example is if you want all your list elements to have a red background color:

 

Full code can be found here on JSFiddle.

 

li {
 background-color: red;
}

So the above example will highlight any list (li) element red, What if you want to more selective of what you want as red, say for example just any ordered (ol) list (li) elements red? Easy:

 

Full code can be found here on JSFiddle.

 

ol li {
 background-color: red;
}

So the above example will highlight any list (li) element that is child of a parent ordered list (ol) elements. This small example shows branching works within HTML documents and how CSS selectors traverses the tree using the simple parent/sibling relationships. This is very powerful. And as mentioned in a previous post, you can be more specific by giving a more specific branching.

 

Full code can be found here on JSFiddle.

 

 

ol li {
    background-color: red;
}
div ol li {
    background-color: purple;
}

Images courtesy of Codecademy.

 

 

 

[CSS] inner Container – float issue

October 7, 2011 Leave a comment

An age old problem apparently where a inner div is attached to a outer div element in the DOM tree. Now usually when the inner div grows in size (i.e. content is added), the outer div will size accordingly. The issue is when a float is applied to the inner div. This causes the container div to ignore what is happening to the inner div element, thus it will not resize based on the inner div.

 

Right, confused? Too many div’s to!  Here is an example of a page with float:left applied to the list elements (li):

 

 

 

 

As you can see, the list elements are floating left, BUT the outer div container (white block), hasn’t resized. Now removing float:left shows you how i want the container div (outer) to behave:

 

 

 

 

 

Unfortunately my lists are not behaving correctly. Now because im new to HTML/CSS i added a forum post to asp.net forums, where a kind chappy told me about the clearfix resolution.

http://forums.asp.net/t/1727780.aspx/1?float+left+issues+lists+

 

On Googling this fix to locate what it is doing, i found the following post which mentions an even cleaner fix adding overflow:auto to my outer container div:

http://www.sitepoint.com/simple-clearing-of-floats/

And like magic, this has worked! And here is the proof:

 

 

 

 

 

 

 

Enhanced by Zemanta
Follow

Get every new post delivered to your Inbox.

Join 281 other followers

%d bloggers like this: