如何在一个相对点css上完全修复图像

时间:2017-05-07 17:40:20

标签: html css3 css-position

我不确定如何解决此问题:图像直接位于某些文本下方,并在调整窗口大小时直接停留在该文本下方。我的问题是我不能只是浮动图像,它需要更远,并与一些文本内联移动。就像对中图像一样,即使页面调整大小,也会始终保持在相对中心。

编辑:我认为问题是我有3个格式的文本,这样的格式是这样的,当页面调整大小时它们会移动:

<!DOCTYPE html>
<link rel="stylesheet" type="text/css" href="example.css"/>
<p>this is the text which the image should follow (stay inline with)
</p>
<p>third section middle</p>
<p>third section right</p>
<img src="https://codepo8.github.io/canvas-images-and-pixels/img/horse.png"/>

CSS:

p{
  float:left;
  width:33.33333%;
  text-align: center;
  color: #2A3132;
}
img{
  width: 10%;
}

我希望在调整页面大小时该图像保留在该文本的中心。我希望这会有所帮助。

1 个答案:

答案 0 :(得分:0)

放在父content

&#13;
&#13;
.content{
  background: yellow;
  padding: 5px;
  border: 1px solid red;
}
p{
  display: inline-block;
  margin-right: -4px;
  width:33.33333%;
  text-align: center;
  color: #2A3132;
  background: red;
  vertical-align: top;
}
img{
  display: block;
  margin: 0 auto;
}
&#13;
<div class="content">
  <p>this is the text which the image should follow (stay inline with)</p>
  <p>third section middle</p>
  <p>third section right</p>
  <img src="http://devimg.com/100x100/"/>
</div>
&#13;
&#13;
&#13;