CSS3 rounded corner, shadow, transparent, and css3 rounded corner shadow
There are many methods for CSS to achieve rounded corners, shadows, and transparency. The traditional methods are complicated and it is much easier to use CSS3. Although various Browsers Do not support CSS3 well, but in the near future, CSS3 will become popular.
1. rounded corner
CSS3 provides two methods to achieve rounded corners.
The first type is the background image. In traditional CSS, each element can have only one background image, but CSS3 allows one element to have multiple background images. in this way, four background images with 1/4 circles can be added to an element, which are located at the four corners to achieve rounded corners.
Html code
- . Box {
- /* First define the four images to be used as the background image */
- Background-image: url (/img/top-left.gif ),
- Url (/img/top-right.gif ),
- Url (/img/bottom-left.gif ),
- Url (/img/bottom-right.gif );
- /* Then define not to repeatedly display */
- Background-repeat: no-repeat,
- No-repeat,
- No-repeat,
- No-repeat;
- /* Define the four images displayed on the four corners */
- Background-position: top left,
- Top right,
- Bottom left,
- Bottom right;
- }
The second method is concise. It is implemented directly with CSS, and images are not needed.
Html code
- . Box {
- /* Define the radius of the rounded corner */
- Border-radius: 1em;
- }
However, the second method is not yet well supported. Currently Firefox and Safari (Chrome with the same core can also be used) require a prefix.
Html code
- . Box {
- -Moz-border-radius: 1em;
- -Webkit-border-radius: 1em;
- Border-radius: 1em;
- }
2. Shadow
The box-shadow attribute of CSS3 can directly implement shadow.
Html code
- Img {
- -Webkit-box-shadow: 3px 3px 6px #666;
- -Moz-box-shadow: 3px 3px 6px #666;
- Box-shadow: 3px 3px 6px #666;
- }
The four parameters of this attribute are vertical offset, horizontal offset, projection width (blur degree), and color.
3. Transparent
CSS originally supports transparency. browsers other than IE are the opacity attribute, While IE is the filter: alpha. however, this transparency has a disadvantage, that is, it will make the content of the application Element Inherit it, for example, there is a DIV,
Html code
- <Div style = "opacity: 0.8; filter: alpha (opacity = 80); font-weight: bold;">
- Content
- </Div>
If the background of the DIV is transparent, but the content is transparent, you can use RGBa.
Html code
- . Alert {
- Rgba (0.8, 0 );
- }
The first three attributes of this attribute are red, green, blue, and transparency. the values of red, green, and blue indicate black. Therefore, rgba (0.8, 0, 0.8) sets the black transparency.
CSS3 makes it very easy to achieve the previously difficult effect, and it is hoped that various browsers will provide perfect support for CSS3 as soon as possible.