[英]How do i Align image to left and text right with background included html?
我正在尝试将图像向左对齐并将文本向右对齐,我尝试过
float:left
所以我设法对齐它,但右边的文字从照片的底部开始,我希望它从照片的开头开始,留下一些空白
同样在图像和文本 div 中,我为图像和文本添加了背景,但它只跟随文本的长度。
我如何将图像左对齐,文本右对齐,背景包含 html?
有人可以帮我解决这个问题。
<html>
<head>
<style>
.item-image {
background-image: url("bkgd.jpg");
background-color: #cccccc;
float:left;
}
body {background-color: powderblue;}
h1 {color: blue;}
b {color: red;}
</style>
</head>
<body>
<div class="item item-image">
<img src="<?= $_POST['imghide']; ?>" />Texto a la derecha alineado Texto a la derecha alineado Texto a la derecha alineado Texto a la derecha alineado Texto a la derecha alineado
</div>
<br clear="all">
</body>
</html>
而不是使用float: left
on .item-image
,您应该在图像本身上使用它。 边距将对图像起作用,
img{
width: 50%;
float: left;
margin: 20px;
}
此外,要使背景尺寸增加,请向背景添加填充,如下所示:
.item-image{
padding: 10px;
}
这将在.item-image
的子元素周围增加空间,而不会增加它们的大小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.