스킨을 바꾸고, 제목 크기를 바꿔볼까하고 style.css 파일을 살펴보던 중 em 이라는 단위가 보여, 찾던중 발견한 글
링크
CSS tips and tricks
September 8, 2006 | By Ben Bleikamp | Filed Under Blog Design
Welcome visitors from Digg. The Blog Herald is one of the largest sites covering the blogosphere - and has been so for more than four years.
You can subscribe to our feed and visit our archives for more stories.
I’ve been writing CSS for about 2 years now and I still feel like every time I open up a blank file and begin writing CSS for a new design I learn something new.
For those of you that are new to CSS or experts always looking for a new trick, here are some of things I do on a regular basis to keep my code organized (kind of).
1. Size text without using pixels
If you’re wondering how some designers get font sizes to work using em as a unit rather than px, it’s easy. There is a trick that was written about a while ago (maybe on ALA) that resets the font sizes for the entire site so that 1.0em is the same as 10px.
body { font-size: 62.5% }
Simply throw the font-size: 62.5% bit into your body styling and you’re done. Now you can use ems to sizes your fonts rather than pixels.
So your paragraph styles might look something like this:
p { font-size: 1.2em; line-height: 1.5em; }
You might be wondering why it matters how you size fonts? Bulletproof design. Any major site needs to be able to withstand a user enlarging text (old people use the web too!), and setting absolute sizes is not good practice.
2. Make your code easy to read
When I was looking at some of the CSS coded by Rundle I noticed that he separated his heading tags nicely. It looked something like this:
h1 {}
h1#logo { font-size: 2em; color: #000; }
h2 {}
h2.title { font-size: 1.8em; font-weight: normal; }
Quickly scanning the CSS for the different heading tags is a breeze if you use this technique. It is also helpful if you’re sharing code or working on a large site where you are using the same heading tags (say, h2) in multiple places since you’ll be able to style each one independently and not worry about child classes inheriting attributes from the parent class.
I also use similar techniques for paragraph tags, anchor tags, and any other tag that requires multiple classes to look correct in every instance.
3. Separate code into blocks
This might be common sense to some of you but sometimes I look at CSS and it’s not broken down into “sections.” It’s easy to do an it makes working with code weeks, months, or years later much easier. You’ll have an easier time finding classes and elements that you need to change.
This is how I usuall break down my site:
/* Structure */
This is where I’d put the primary site structure divs and classes.
/* Typography */
This is where I would list things like paragraphs, headings, and other miscellaneous font styles such as small and strong tags.
/* Links */
This one is simple - all the styling for anchor tags.
/* Lists, images, etc. */
This is where I would style images, lists, and any other elements that didn’t fit into the rest of the section. If I have an unordered list for the navigation I might setup a new section for navigation and setup all the styles for the navigation, including the list and link styles, in this section - it makes editing the navigation much easier.
4. Stop using so many divs!
This has been echoed by a lot of coders and standards nuts, and while I don’t think there is anything wrong with using a lot of block level elements, I laugh a little when I see someone style their article headlines using a div rather than a heading tag. Some people even style their bylines using a div! Try using the small tag or the a span for goodness sake.
5. Style everything at once
I noticed that I was typing “margin: 0; padding: 0;” in just about every element. I remembered seeing someone use “*” to style everything on a page at once. I decided it didn’t make much sense to define margin and padding over and over when I always gave them the same parameters.
It’s easy to do:
* { margin: 0; padding: 0; }
Now you only have to define margin and padding on elements where you actually want some.
Know of any other tips or tricks? Let me know :)
'형상관리' 카테고리의 다른 글
엔터프라이즈 클라우드 컴퓨팅을 구성하는 4개의 이용 모델 (0) | 2010.10.27 |
---|---|
웹 프로그래밍 언어 비교 (1) | 2008.03.04 |
영문 수학 용어 정리 (4) | 2006.06.20 |
한국전통 표준 색명 및 색상 (0) | 2006.01.04 |
색상선택에 도움을 주는 색상표 (2) | 2006.01.04 |