Useful solutions for css web design

Source: Internet
Author: User
Tags relative

Directory

Introduction
Browser selector
Make IE6 support PNG transparent
Remove the dotted line of a hyperlink
Defines the width of an element in a row.
Center a fixed-width page
Image replacement technology
Minimum width
Hide horizontal scroll bar

I. INTRODUCTION

This article includes eight very useful solutions that you will use when encountering css design problems.

2. Browser selector

These selectors are useful when you need to design css for a browser.

IE6 and earlier versions
* Html {}

IE7 and earlier versions
*: First-child + html {} * html {}

Only for IE7
*: First-child + html {}

IE7 and contemporary browsers
Html> body {}


Only contemporary browsers (IE7 not applicable)
Html>/**/body {}

Opera9 and earlier versions
Html: first-child {}

Safari
Html [xmlns * = ""] body: last-child {}

To use these selectors, place them before the style. For example:

# Content-box {
Width: 300px;
Height: 150px;
}
* Html
# Content-box {
Width: 250px;
}/* Overrides the above style and changes the width to 250px in IE 6 and below */

3. Make IE6 support PNG transparent 

A Bug in IE6 has caused a lot of trouble. It does not support transparent PNG images. You need to use a css Filter.

* Html # image-style {
Background-image: none;
Filter: progid: DXImageTransform. Microsoft. AlphaImageLoader (src = "fil
Ename.png ", sizingMethod =" scale ");
}

4. Remove the dotted line of the hyperlink (only valid for FF)

In FireFox, when you click a hyperlink, a dotted line outline will appear on the periphery. This is easy to solve. You only need to add outline: none to the label style.

5. Define the width of the line element

If you define the width for an element in the row, it is only valid under IE6. all HTML elements are either in-row elements or block elements. the row elements include: <span>, <a>, <strong>, and <em>. the block elements include <div>, <p>,

Span {width: 150px; display: block}

6. Center a fixed-width page

To center the page in the browser, you need to locate the outer div and set the margin to auto.

# Wrapper {
Margin: auto;
Position: relative;
}

VII. Image replacement technology

Text is better than titles with images. Text is very friendly to screen readers and SEO.

HTML:

<H1> <span> Main heading one </span>

CSS:

H1 {background: url(heading-image.gif) no-repeat ;}
H1 span {
Position: absolute;
Text-indent:-5000px;
}

You can see that we use the standard

8. Minimum width

Another bug in IE6 is that it does not support the min-width attribute. min-width is quite useful. Especially for an elastic template, they have a width of 100%. min-width can tell the browser when it will not compress the width. for all browsers except IE6, you only need one min-width: Xpx. For example:

In order for him to work in IE6, we need some extra work. At the beginning, we need to create two divs, one containing the other:

<Div class = "container">
<Div class = "holder"> Content </div>
</Div>

Then you need to define the min-width attribute of the outer div.

. Container {
Min-width: 300px;
}
 

This is the time for IE hack to show off its skills. You need to include the following code:

* Html. container {
Border-right: 300px solid # FFF;
}
* Html. holder {
Display: inline-block;
Position: relative;
Margin-right:-300px;
}

As the browser window is resized the outer div width ces CES to suit until it shrinks to the border width, at which point it will not shrink any further. the holder div follows suit and also stops shrinking. the outer div border width becomes the minimum width of the inner div.

9. Hide the horizontal scroll bar

To avoid horizontal scroll bars, add overflow-x: hidden to the body.

Body {overflow-x: hidden ;}

This technique is useful when you decide to use an image or flash that is larger than the browser window.

Responsible editor: silvia Time: July 15, March 14, 2008

. Container {
Min-width: 300px;
}

A {
Outline: none;
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.