简体   繁体   English

如何将图像放置在居中图像的右侧

[英]How to place an image at the right of a centered one

Hi I'm trying to put an image next to a centered one 嗨,我正在尝试将图片放在居中的图片旁边

the code looks like this : 代码看起来像这样:

<div id="body3" >
    <center><img  HEIGHT="700" WIDTH="600" src="Logo.jpg"></center>
    <img height="40" width="220" ;" src="reserver.png" style="float: right;">
</div>

but the second image will go underneath the first one and to the right.I want it to be to the right of the centered one. 但第二张图片将位于第一张图片的下方,并位于右侧。我希望它位于居中图片的右侧。

Any options? 有什么选择吗? Thank you 谢谢

Try this: 尝试这个:

<div id="body3" >
    <center><img  HEIGHT="700" WIDTH="600" style="display: inline-block;" src="Logo.jpg">  <img height="40" width="220" style="display: inline-block;" src="reserver.png">  </center>

</div>

If I understood your question you want the minor box being aligned at after the big box and to the right? 如果我理解您的问题,您希望将次要框对齐在大框之后并向右对齐吗? And don't want to "expand" the major box width. 并且不想“扩展”主要的盒子宽度。 If is this your question, here's your solution: 如果这是您的问题,这是您的解决方案:

1- Treat your #body3 as a wrapper to avoid your div quit the desired position. 1-将您的#body3视为包装器,以避免div退出所需位置。

2- Align your elements with margin: 0 auto; 2-将元素与margin: 0 auto;对齐margin: 0 auto; or text-align:center; text-align:center;

CSS 的CSS

 img:nth-of-type(1){
        margin:0 auto;
        background:red;

    }
     img:nth-of-type(2){
        float:right;
    }

    #body3{
       margin:0 auto;
       width:600px;
    }

HTML 的HTML

<div id="body3" >

    <img height="700" width="600" src="http://placehold.it/600x700">
     <img height="40" width="220" src="http://placehold.it/220x40">

</div>

https://jsfiddle.net/fvcee05a/1/ https://jsfiddle.net/fvcee05a/1/

You can use css floats. 您可以使用CSS浮点数。

see example at https://jsfiddle.net/z3kwx1x5/1/ 参见示例https://jsfiddle.net/z3kwx1x5/1/

Learn more at https://css-tricks.com/all-about-floats/ https://css-tricks.com/all-about-floats/了解更多

<div id="body3" style="width:1200px;">
    <img style="float:left;margin-left: 220px;" height="700" width="600" src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png">
    <img style="float:left;margin-top:330px;" height="40" width="220" src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png">
</div>

Both images are floated left. 两个图像都向左浮动。 If you want the first image to be centered, you can add margin-left to the inline style attribute. 如果要使第一个图像居中,则可以在行内样式属性中添加margin-left The value of the margin-left would depend on the width of the div#body3 左边距的值取决于div#body3的宽度

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM