CSS pseudo class object before and after the usage example detailed explanation

Source: Internet
Author: User
Tags html tags relative

Always feel that these two pseudo class object is not very important, and IE to its two brothers do not support, so there is no static to study, only in the clear floating clearfix will use Ha, the others are rarely used! However, recently in the study of CSS3 feel that its two collocation can not only reduce the amount of code and can be a very Bahan effect, so to study ah!

First, look at their definition ha!

1, Selector:before (srules) it to use with the Content property, set in front of the object (based on the logical structure of the object tree) what happens;

2, Selector:after (srules) and before usage, but it is set after the object (based on the logical structure of the object tree) what happens;

Look at the examples easy to understand!

Copy Code code as follows:


<style>


. div{width:350px; border:1px solid #000; line-height:50px; margin:10px;}


. divb{width:500px border:1px solid #FC0;


. after,.before,.block{border:1px solid #330;


after:after{content: ' I'm in the back. ' Color: #F00;}


before:before{content: ' I'm in front of you '; color: #F00;}


block:after{content: ' I am a block element, I take a line '; color: #F00; display:block;}


. Block{display:block}


</style>


<body>


<div class= "div" >after<span class= "after" > I was content </span></div>


<div class= "div" >before<span class= "before" > I'm inside content </span></div>


<div class= "DIVB" >block<span class= "block" > I am content </span></div>


</body>


Run the results as shown! Why do I have to convert <span class= "block" > to chunk level elements? Because the block element inserts inline element does not conform to the standard, does not have the specification, does not translate the words to show the question. I don't know.

Now let's look at the CSS3.

Copy Code code as follows:


&lt;style&gt;


. bottle{width:100px position:relative;}


. bottle_top{position:relative; width:80px; height:30px; border:1px solid Rgba (255,255,255,0.5); border-bottom:0 None border-top:0 none; margin:0 Auto;}


. Bottle_top:after,.bottle_top:before{content: '; display:block; height:10px; width:78px; border-radius:46px/10px; border:2px solid Rgba (255,255,255,.5); border-bottom:2px solid Rgba (255,255,255,.4); border-top:1px Solid Rgba ( 255,255,255,.6); Position:absolute; left:-1px;box-shadow:0px 0px 6px Rgba (255,255,255,0.6) inset;}


bottle_top:after{top:-6px;box-shadow:0px 0px 6px rgba (255,255,255,0.6) inset,0px 3px 3px-1px Rgba ( 255,255,255,0.3);}


. bottle_top:before{top:24px;box-shadow:0px 0px 6px Rgba (255,255,255,.4) inset;}


. bottle_mouth{height:52px width:44px; margin:0 auto; position:relative; background:none; border:1px Solid Rgba ( 0,0,0,0.04); border-top:none; Border-bottom:none;background:-moz-linear-gradient (Left,rgba (255,255,255,0.3), Rgba (255,255,255,0) 5%,rgba ( 255,255,255,0) 95%,rgba (255,255,255,0.3)); box-shadow:0px 0px 6px Rgba (255,255,255,0.3);}


. bottle_mouth:after{height:6px width:44px; content: '; display:block border-radius:25px/6px;border:1px solid Rgba ( 255,255,255,.4); Position:absolute; left:-1px; Top:-4px;z-index:1; box-shadow:0px 0px 3px Rgba (255,255,255,0.3);}


. bottle_top highlight{width:20px; height:30px; display:block; position:absolute; left:5px; top:5px; Moz-transform:skew (0deg,5deg); Background:-moz-linear-gradient (Left,rgba (255,255,255,0.1), Rgba (255,255,255,0.6) 4%,rgba (255,255,255,0.2) 98%,rgba (255,255,255,0));


. Bottle_top. Highlight:after{content: '; display:block; width:2px; height:30px; position:absolute; top:-1px; left : -3px; -moz-transform:skew (0DEG,5DEG); Background:rgba (255,255,255,.3);}


&lt;/style&gt;


&lt;body&gt;


&lt;div class= "main" &gt;


&lt;div class= "Bottle" &gt;


&lt;div class= "Bottle_top" &gt;


&lt;div class= "Bottle_mouth" &gt;&lt;/div&gt;


&lt;div class= "Highlight" &gt;&lt;/div&gt;


&lt;/div&gt;


&lt;/div&gt;


&lt;/div&gt;


&lt;/body&gt;


Because of the use of CSS3, so it is still recommended under the Firefox preview!

Although more abstract, I do not say that you should not know is a bottle of the lid of the body part of the code is too much to post.

So before and after the use of good can save HTML tags, and with CSS3 to make a good effect, of course, do play, not too practical.

Second, the following incidentally said some CSS3 properties, (Border-radius&box-shadow) I was just slowly groping

Border-radius started!!

1, Border-radius:none | <length>{1,4} [/<length>{1,4}]?

Related properties: Border-top-right-radius Border-bottom-right-radius Border-bottom-left-radius Border-top-left-radius, In fact, Border-radius is a shorthand for their four attributes.

Value:<length> A length value consisting of floating-point numbers and unit identifiers, which cannot be negative.

Look at this picture, otherwise it's easy to faint.

Description

1, the first value that is X is the horizontal radius.

2. If the second omission is Y, then he is equal to the first value, at which point it is a rounded corner of One-fourth.

3, if any value is 0, then this corner is a rectangle, not a circle.

4, the value is not allowed to be negative.

When border-radius:<length>{1,4} [/<length>{1,4}]?

1, if the value before and after the slash is present, then the value before the slash is set to the horizontal radius (x), and the value after the slash is set to the vertical radius (y), and if there are no slashes, the horizontal and vertical radii are equal.

It is equal to One-fourth circles. such as: border-radius:46px/10px four corner of the radius of the size of 46px/10px.

The order of 2 and four values is in accordance with Top-left,top-right,bottom-right,bottom-left (anyway, clockwise?) Counterclockwise, huh? If bottom-left omitted it is equal to Top-right,

If bottom-right omit it is equal to Top-left, if top-right omit it equals top-left (somewhat diagonal relationship)

3, the application scope: applies all elements, except the table's style attribute is boder-collapse for collapse.

What do we see in common writing? And what is the corresponding explanation?

It's all very powerful! This URL is good: http://www.designcss.org/archives/border-radius.html So when you know you want more rounded shapes, you can show them by setting the exact values, I think it's very useful to have a good geometry. Ps:radius is the meaning of the radius, so use this property to make the effect of rounded corners, of course, can also make a circular effect, the principle: the square of the incircle radius is equal to half the length of the square side. Box-shadow started!!
The simple understanding is to let your box have a shadow effect, before many designers like to do this, but now toward the flat development, with less,
But existence has its own truth. It's good to use or it's pretty.

Syntax:box-shadow:< shadow type > <x axis displacement > <y Axis displacement > < shadow blur radius "? < Shadow expansion radius >?| | < shadow color > Shadow horizontal offset value positive negative value, vertical offset value desirable.
When the shadow type is not set, the default is projection, and when set to the inset property is an inner shadow, while the x-axis and y-axis are not equivalent but similar to the angle and position in PS. The shadow expansion radius is optional, but only positive, and if 0, there is no blur effect,
The extended radius is optional, the value can be positive or negative, if positive, the shadow extends and expands, and if it is negative, it shrinks. Shadow color is optional, if not set, the browser's default color, but the default color of each browser is different, so it is best
or set up a ha.

As shown in figure:

You can practice it as much as possible. Shadow size, expansion, color, and Photoshop are all the same.
such as: Box-shadow:inset 0 0 1px #fff表示没有偏移量, 1 pixel blur white interior shadow here the #fff is hex value.
Sometimes we write this: Box-shadow:inset 0 0 1px rgba (255,255,255,.5)
The advantage of using the RGBA value, the RGBA value, is that it has an alpha-transparent value, and you can control the opacity of the shadow.

Some want to write more complex, the effect is more dazzling, you can use more shadow. But note the order of the problem, the first written shadow will appear in the outermost layer, such as

. div{box-shadow:0 0 10px #F69, 0 0 10px 10px Yellow}

The display is as follows:

Look at the #f69 color value shown above the yellow. Because the yellow shadow expands by 10 pixels. It's wider than f69, so it won't be blocked by f69.

Here we look at a four-color shadow.

. div{box-shadow:-10px 0 Red, 10px 0 blue,0-10px yellow,0 10px Green; width:200px; height:100px; background: #6C9;}

The display is as follows:

See the picture may want to say, it is how to determine the red, blue, yellow, green position, why just on the four sides of the box? In fact, we are going to design shadows on four sides of the object by changing the positive negative values of x-offset and Y-offset, where the left shadow is generated when the x-offset is negative, the right shadow is generated when a positive value is generated, and a positive value is generated for the bottom shadow, and the top shadow when negative. If X-offset and Y-offset are set to 0 then the box will have a shadow for four weeks.

Let's set the fuzzy values for each of the four edges to see the effect.

box{width:200px height:100px;background: #6C9 box-shadow:-10px 0 10px Red, 10px 0 10px blue,0-10px 10px yellow,0 10px 1 0px Green;}

The display is as follows:

So we get the result: The Red Shadow is on the top yellow shadow, the right blue shadow on the bottom green shadow. So the writing of multiple shadows must pay attention to the order of the problem.
Especially when the fuzzy value is different,
Because you need to pay attention to a detail problem when using multiple layers of shading, if the previous shadow blur value is less than the shadow blur value behind it, then the front is displayed on the back,
If the blur value of the previous shadow is greater than the trailing shadow blur, the previous shadow will cover the shadow effect behind it

is not saliva too much, write too long still not logic ah? There's a problem with the title.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.