2016-11-17 56 views
2

嗨,我试图把图像的正确的地方旁边有一个中心如何将图像在中心一个

的代码如下所示:

<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> 

但是第二图像将会在第一个和第二个之下进行。我希望它位于中心位置的右侧。

任何选项?谢谢

回答

0

试试这个:

<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> 
+0

元素,因此我想你的选项,这是行不通的。除了我在中使用的唯一的css外,我的css表单中还有一个背景颜色。 – Goog1eIt

+0

我编辑了我的答案。将两个图像放在中心标签内。 – borbesaur

+0

好了,以便解决这个问题,但这意味着最初居中的图像在中心左侧稍微有一点点...... – Goog1eIt

-1

您可以使用CSS浮动。

见例如在https://jsfiddle.net/z3kwx1x5/1/

了解更多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> 

两个图像向左浮动。如果要将第一个图像居中,则可以将margin-left添加到内联样式属性中。保证金左的价值将取决于DIV#body3

+0

-2已经?任何人都在关注我的回答吗? – derekcbaldwin

+0

Downvote并不是从我这里来的,但似乎你是为了漂浮而使用漂浮物。将剩下的第一张图像浮动需要OP进行额外的工作,以便将图像重新放回到他/她已有的图像中。基本上向后一步,然后向前。你的策略是有优点的,但是OP没有要求一个新的策略,他问如何将第二个图像放在已经居中的第一个图像的右侧。 – borbesaur

+0

Gotcha。我真的不支持使用已弃用的标签,尽管... http://www.w3schools.com/TAgs/tag_center.asp。我想你总是可以使用表格或绝对定位,但这只是粗略的。 – derekcbaldwin

0

的宽度如果我明白你的问题,你想在以后的大箱子和向右轻微框对齐?并且不想“扩大”主框宽度。如果这是你的问题,这是你的解决方案:

1-将你的#body3视为一个包装,以避免你的div退出所需的位置。

2 - 对齐你有margin: 0 auto;text-align:center;

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

<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/

相关问题