<!DOCTYPE html
>
<html lang
="en">
<head
>
<meta charset
="UTF-8">
<meta name
="viewport" content
="width=device-width, initial-scale=1.0">
<title
>课时
1</title
>
<style type
="text/css">
div
{
width
: 100px
;
height
: 100px
;
padding
: 10px
;
background
-color
: green
;
}
div
::after
{
content
: "";
display
: block
;
width
: 50px
;
height
: 50px
;
background
-color
: red
;
}
</style
>
</head
>
<body
>
<div
></div
>
<script type
="text/javascript">
var div
= document
.getElementsByTagName('div')[0];
console
.log(window
.getComputedStyle(div
,'after').width
);
console
.log(window
.getComputedStyle(div
,'after').height
);
</script
>
</body
>
</html
>
<!DOCTYPE html
>
<html lang
="en">
<head
>
<meta charset
="UTF-8">
<meta name
="viewport" content
="width=device-width, initial-scale=1.0">
<title
>课时
1</title
>
<style type
="text/css">
.box
{
width
: 100px
;
height
: 100px
;
padding
: 10px
;
background
-color
: green
;
}
.box
::after
{
content
: "";
display
: block
;
width
: 50px
;
height
: 50px
;
background
-color
: red
;
}
.box
.active
::after
{
background
-color
: black
;
}
</style
>
</head
>
<body
>
<div
class="box active"></div
>
<script type
="text/javascript">
var div
= document
.getElementsByTagName('div')[0];
div
.onclick = function(){
this.className
+= ' active';
}
console
.log(window
.getComputedStyle(div
,'after').width
);
console
.log(window
.getComputedStyle(div
,'after').height
);
</script
>
</body
>
</html
>
```javascript
<!DOCTYPE html
>
<html lang
="en">
<head
>
<meta charset
="UTF-8">
<meta name
="viewport" content
="width=device-width, initial-scale=1.0">
<title
>课时
1</title
>
<style type
="text/css">
.box
.active
{
width
: 200px
;
height
: 200px
;
background
-color
: red
;
border
-radius
: 50%;
}
</style
>
</head
>
<body
>
<div
class="box active"></div
>
<script type
="text/javascript">
var div
= document
.getElementsByTagName('div')[0];
div
.onclick = function(){
this.className
+= ' active';
}
</script
>
</body
>
</html
>
转载请注明原文地址: https://lol.8miu.com/read-28165.html