CSS Background-Position PropertyIntroductionIn CSS, we can use the background-position property to specify the position of the background image. We can set the position of the image at a particular position. The position we have provided is related to the position layer of the background image. Syntax:We can implement the background property with the help of the below syntax. NOTE: The CSS sets the default value for the background-position in the top-left corner of an element, which is repeated both horizontally & vertically.Properties Value
With the help of this property, we can set the image at the top left position of the webpage.
With the help of this property, we can set the image at the centre-left position of the webpage.
With the help of this property, we can set the image at the bottom left position of the webpage.
With the help of this property, we can set the image at the centre-top position of the webpage.
With the help of this property, we can set the image at the centre position of the webpage.
With the help of this property, we can set the image at the centre bottom position of the webpage.
With the help of this property, we can set the image at the top right position of the webpage.
With the help of this property, we can set the image at the centre-right position of the webpage.
With the help of this property, we can set the image at the bottom right position of the webpage.
With the help of this property, we can set the image at 25% from the left and 75% from the top of the webpage.
With the help of this property, we can set the image at 30px from the left and 80px from the top..of the webpage. Example 1:in the example below, we have created a div at the web page's top left position. Code: Output Explanation: In the above code, we use the background-position: left top; So that the position of the image is shifted to the top left position of the webpage. Example 2:in the below example, we have created a div, which is present at the top centre position of the web page. Code: Output Explanation: In the above code, we use the background position: top center; So that the position of the image is shifted to the top center position of the webpage. Example 3:in the below example, we have created a div, which is present at the left-centre position of the web page. Code: Output Explanation: In the above code, we use the background-position: left centre So that the position of the image is shifted to the left centre position of the webpage. Example 4:in the below example, we have created a div, which is present at the left bottom position of the web page. Code: Output Explanation: In the above code, we use the background-position: left button; So that the position of the image is shifted to the left bottom position of the webpage. Example 5:in the below example, we have created a div that is present at the centre position of the web page. Code: Output Explanation: In the above code, we use the background-position: centre centre So that the position of the image is shifted to the centre position of the webpage. Example 6:in the below example, we have created a div that is present at the centre bottom position of the web page. Code: Output Explanation: In the above code, we use the background-position: centre button; So that the position of the image is shifted to the centre button position of the webpage. Example 7:in the below example, we have created a div, which is present at the right top position of the web page. Code: Output Explanation: In the above code, we use the background-position: right top So that the position of the image is shifted to the right top position of the webpage. Example 8:in the below example, we have created a div, which is present at the top right centre position of the web page. Code: Output Explanation: In the above code, we use the background position: top right center; So that the position of the image is shifted to the top right center position of the webpage. Example 9:in the below example, we have created a div, which is present at the bottom right position of the web page. Code: Output Explanation: In the above code, we use the background-position: right bottom So that the position of the image is shifted to the right bottom position of the webpage. Example 10:in the below example, we have created a div, which is present at the percentage position of the web page. Code: Output Explanation: In the above code, we use the background position: centre center; So that the position of the image is shifted to the center center position of the webpage. Example 11:in the below example, we have created a div that is present at the pixel position of the web page. Code: Output Explanation: In the above code, we use the background-position in pixel value so that the position of the image is shifted according to the pixel value position of the webpage.
Next TopicCSS Before and After
|