Home > Web Front-end > CSS Tutorial > How to set the image to the right in css

How to set the image to the right in css

醉折花枝作酒筹
Release: 2023-01-05 16:10:51
Original
18307 people have browsed it

In CSS, you can use the text-align attribute to set the image to the right. You only need to set "text-align:right;" to the image element. The text-align attribute specifies the horizontal alignment of the element's text. When the value is right, it means that the element is arranged to the right.

How to set the image to the right in css

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

Create a new html file, named test.html, to explain how to right-align images in divs using css. In the test.html file, create a module using the div tag and set the class attribute of the div tag to mycss. Inside the div, create an image using the img tag.

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        
    </style>
</head>
<body>
<div class="mycss">
    <img src="images/2.jpg" alt="">
</div>
</body>
</html>
Copy after login

In the css tag, set the style of the div through class, define its width as 400px, height as 300px, and border as 1px. Then set the text-align attribute to right, which is used to align the content in the div to the right, thereby achieving right alignment of the image.

<style type="text/css">
        .mycss{
            width:400px;
            height: 300px;
            border: 1px solid #ccc;
            text-align: right;
        }
</style>
Copy after login

Open the test.html file in the browser to check the effect.

How to set the image to the right in css

Recommended learning: css video tutorial

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

Related labels:
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