Home  >  Article  >  Web Front-end  >  How to set image position in css

How to set image position in css

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-04-20 13:56:0910749browse

Method: First use the position attribute to specify the positioning type of the element, the syntax is "position:static|relative|fixed|absolute"; then use the top, bottom, left and right attributes to define the offset position of the picture element. accurate locating.

How to set image position in css

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

The position attribute specifies the positioning type of the element. This attribute defines the positioning mechanism used to establish the layout of the element. Any element can be positioned, but absolute or fixed elements generate a block-level box, regardless of the type of the element itself. A relatively positioned element is offset from its default position in normal flow.

Elements are actually positioned using the top, bottom, left and right attributes. However, these properties will have no effect unless the position property is set first. They work differently depending on the position value.

How to set image position in css

Example:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<style type="text/css">
			img {
				position: absolute;
				left: 100px;
				top: 100px
			}
		</style>
	</head>

	<body>
		<img  src="2.jpg" / alt="How to set image position in css" >
		
	</body>

</html>

Recommended learning: css video tutorial

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

Statement:
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