Home >Web Front-end >CSS Tutorial >How to enlarge div in css3
Method: 1. Use the transform attribute and scale() function to enlarge the div. The syntax is "Element {transform:scale (magnification)}"; 2. Use the width and height attributes to achieve the effect of enlarging the div. The syntax is: "Element {width: width; height: height}".
The operating environment of this tutorial: Windows 10 system, CSS3&&HTML5 version, Dell G3 computer.
How to enlarge div in css3
In css, if you want to enlarge a div, you can use the transform attribute and the width and height attributes. accomplish.
1. Use the transform attribute with the scale() function to achieve the effect of enlarging the div
The transform attribute applies 2D or 3D transformation to the element. This property allows us to rotate, scale, move or tilt the element.
The example is as follows:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> *{ margin:0 auto; } .div1{ width:150px; height:100px; background:pink; transform:scale(1.5); } .div2{ width:150px; height:100px; background:pink; } </style> </head> <body> <div class="div1"></div> <br><br> <div class="div2"></div> </body> </html>
Output result:
2. Use the width and height attributes to achieve the effect of enlarging the div.
The example is as follows:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> .div1{ width:300px; height:200px; background:pink; } .div2{ width:150px; height:100px; background:pink; } </style> </head> <body> <div class="div1"></div> <br><br> <div class="div2"></div> </body> </html>
Output result:
(Learning video sharing: css video tutorial)
The above is the detailed content of How to enlarge div in css3. For more information, please follow other related articles on the PHP Chinese website!