| div中分两左右两块,一个左对齐,一个右对齐,其中右边为图片 
 复制代码<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>左右对齐示例</title>
<style>
  .container {
    overflow: hidden; /* 清除浮动 */
    width: 100%;
  }
  .left {
    float: left; /* 左对齐 */
    width: 50%; /* 或您希望的宽度 */
    background-color: #ffdddd;
    padding: 10px;
  }
  .right {
    float: right; /* 右对齐 */
    width: 50%; /* 或您希望的宽度,但确保两者之和不超过100% */
    text-align: right; /* 如果图片后还有其他文本内容,可以设置文本右对齐 */
  }
  .right img {
    max-width: 100%; /* 图片最大宽度为容器宽度 */
    height: auto; /* 图片高度自动以适应宽度 */
  }
</style>
</head>
<body>
<div class="container">
  <div class="left">
    <p>左侧内容</p>
  </div>
  <div class="right">
    <img src="your-image-url.jpg" alt="描述性文字">
    <!-- 如果图片后还有其他文本内容,可以放在这里 -->
  </div>
</div>
</body>
</html>
请注意,您需要替换 src="your-image-url.jpg" 为您自己的图片URL,同时提供适当的 alt 属性文本以描述图片内容,这对于屏幕阅读器和搜索引擎优化(SEO)都是很重要的。 此外,.right img 样式规则设置了 max-width: 100%; 以确保图片不会超出其容器宽度,同时 height: auto; 保持图片的原始纵横比。这样,图片就可以根据容器的大小自动调整尺寸了。 
 |