简体   繁体   English

在同一行上左对齐图像,文本中心,右对齐图像

[英]Have align image left, text center, image right on the same line

I am trying to align two images one to the left and the other to the right of text. 我正在尝试将两个图像对齐到文本的左边,另一个对齐到文本的右边。 then have the text flow down the middle not underneath the images. 然后让文字顺着中间流到图片下方。 I figured this should be fairly easy but cant get it to work. 我认为这应该很容易,但是无法正常工作。 https://jsfiddle.net/b9nc02cu/ https://jsfiddle.net/b9nc02cu/

<div style="width:100%">
<div style="float:left"><img style="width: 150px; height: 150px;" src="https://pbs.twimg.com/profile_images/378800000442759461/b483cdd049f470928e7b20051f95b8cc.jpeg"></div>

<div style="float: left; top: 150px; left: 5px;"><span style="font-size: 30px;">Today is September 12, 2015. It's a saturday partly cloudy</span></div>

<div style="float: right;"><img style="width: 150px; height: 150px;" src="https://pbs.twimg.com/profile_images/378800000442759461/b483cdd049f470928e7b20051f95b8cc.jpeg"></div>
</div>

I think you need something like this one. 我认为你需要像一个。

 #container { width: 100%; } #container > div { display: table-cell; } #left { min-width: 150px; height: 150px; } #middle { vertical-align: top; height: 150px; } #right { min-width: 150px; height: 150px; } 
 <div id="container"> <div id="left"> <img style="width: 150px; height: 150px;" src="https://pbs.twimg.com/profile_images/378800000442759461/b483cdd049f470928e7b20051f95b8cc.jpeg"> </div> <div id="middle"> Today is September 12, 2015. It's a saturday partly cloudy </div> <div id="right"> <img style="width: 150px; height: 150px;" src="https://pbs.twimg.com/profile_images/378800000442759461/b483cdd049f470928e7b20051f95b8cc.jpeg"> </div> </div> 

img and span elements have an inline display. img和span元素具有嵌入式显示。

Removing the parent divs for each of the 3 elements will give you the result you are looking for 删除3个元素中每个元素的父div,将为您提供所需的结果

You should set the width of the middle column. 您应该设置中间列的宽度。 If you're aiming at newer browsers you could set it to calc(100% - 300px); 如果您是针对较新的浏览器,则可以将其设置为calc(100%-300px);

<div style="width:100%">
    <div style="float:left"><img style="width: 150px; height: 150px;" src="https://pbs.twimg.com/profile_images/378800000442759461/b483cdd049f470928e7b20051f95b8cc.jpeg"></div>
    <<div style="float: left; top: 150px; width: calc(100% - 300px);"><span style="font-size: 30px;">Today is September 12, 2015. It's a saturday partly cloudy</span></div>
    <div style="float: right;"><img style="width: 150px; height: 150px;" src="https://pbs.twimg.com/profile_images/378800000442759461/b483cdd049f470928e7b20051f95b8cc.jpeg"></div>
</div>

https://jsfiddle.net/b9nc02cu/1/ https://jsfiddle.net/b9nc02cu/1/

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

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