How to set the css image size: 1. Image size setting introduced through the img tag, the syntax is [img{width:150px;height:60px}]; 2. Use the [background-size] attribute to specify the background The size of the image.
The operating environment of this tutorial: windows7 system, css3 version, DELL G3 computer.
How to set the css image size:
1. Image size settings introduced through the img tag
We can directly Set the width and height in the image tag. It should be noted here that directly setting the width and height values in the HTML img tag does not require html units. The default is PX pixels.
The advantage of setting the height and width in the img tag is intuitive. For inserting pictures into articles, you can use this method to control the height and width of the picture. The disadvantage is that if the picture list is formatted like this, a lot of HTML code will be added, making it inconvenient to modify it uniformly.
css Set img image size syntax:
img{width:150px;height:60px}
Here, set the CSS width to 150px, and the css height to 60px. Note that the values of css width and css height in the CSS style have units and must be remembered. Be sure to bring your unit with you when you live.
If we set the style directly on img, this will control the width and height of the image in the entire web page. In order to control the image width and height style within the specified object, we usually add the object CSS name before img.
2. Set the background image size with css:
The background-size attribute specifies the size of the background image.
Grammar:
background-size: length|percentage|cover|contain;
Example:
<!DOCTYPE html> <html> <head> <style> body { background:url(/i/bg_flower.gif); background-size:63px 100px; -moz-background-size:63px 100px; /* 老版本的 Firefox */ background-repeat:no-repeat; padding-top:80px; } </style> </head> <body> <p>上面是缩小的背景图片。</p> <p>原始图片:<img src="/static/imghwm/default1.png" data-src="/i/bg_flower.gif" class="lazy" alt="Flowers"></p> </body> </html>
Rendering:
Related tutorial recommendations:CSS video tutorial
The above is the detailed content of How to set css image size. For more information, please follow other related articles on the PHP Chinese website!

Yes,youshouldlearnbothFlexboxandGrid.1)Flexboxisidealforone-dimensional,flexiblelayoutslikenavigationmenus.2)Gridexcelsintwo-dimensional,complexdesignssuchasmagazinelayouts.3)Combiningbothenhanceslayoutflexibilityandresponsiveness,allowingforstructur

What does it look like to refactor your own code? John Rhea picks apart an old CSS animation he wrote and walks through the thought process of optimizing it.

CSSanimationsarenotinherentlyhardbutrequirepracticeandunderstandingofCSSpropertiesandtimingfunctions.1)Startwithsimpleanimationslikescalingabuttononhoverusingkeyframes.2)Useeasingfunctionslikecubic-bezierfornaturaleffects,suchasabounceanimation.3)For

@keyframesispopularduetoitsversatilityandpowerincreatingsmoothCSSanimations.Keytricksinclude:1)Definingsmoothtransitionsbetweenstates,2)Animatingmultiplepropertiessimultaneously,3)Usingvendorprefixesforbrowsercompatibility,4)CombiningwithJavaScriptfo

CSSCountersareusedtomanageautomaticnumberinginwebdesigns.1)Theycanbeusedfortablesofcontents,listitems,andcustomnumbering.2)Advancedusesincludenestednumberingsystems.3)Challengesincludebrowsercompatibilityandperformanceissues.4)Creativeusesinvolvecust

Using scroll shadows, especially for mobile devices, is a subtle bit of UX that Chris has covered before. Geoff covered a newer approach that uses the animation-timeline property. Here’s yet another way.

Let’s run through a quick refresher. Image maps date all the way back to HTML 3.2, where, first, server-side maps and then client-side maps defined clickable regions over an image using map and area elements.

The State of Devs survey is now open to participation, and unlike previous surveys it covers everything except code: career, workplace, but also health, hobbies, and more.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver CS6
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download
The most popular open source editor
