How to set the distance of the image from the left in css

青灯夜游
Release: 2021-11-09 15:02:49
Original
7293 people have browsed it

In CSS, you can use the margin-left attribute to set the distance from the left side of the image. The function of this attribute is to set the left margin of the element. You only need to add "img{margin-left: distance value" to the image element. ;}" style is enough.

How to set the distance of the image from the left in css

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

In CSS, you can set the distance from the left side of the image through the margin-left attribute.

The margin-left attribute sets the left margin of the element. Negative values ​​are allowed.

Example:

<!DOCTYPE html>
<html>
	<head>
		<style>
			img{
				border: 1px solid red;
			}
		#img2{
			margin-left: 20px;
		}
		</style>
	</head>

	<body>
		<img  src="img/1.jpg"    style="max-width:90%" / alt="How to set the distance of the image from the left in css" >
		<img  src="img/1.jpg"    style="max-width:90%" id="img2" / alt="How to set the distance of the image from the left in css" >
	</body>
</html>
Copy after login

Rendering:

How to set the distance of the image from the left in css

Description:

margin-left attribute value Units can use px, %, em, rem, etc.

(Learning video sharing: css video tutorial)

The above is the detailed content of How to set the distance of the image from the left in css. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
css
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template