无法将图像放在文本旁边(推入下一个div)



我想在div内的一些文本旁边放置一个图像,但是图像被推到下面的下一个div中,无论我增加多少边距或填充都不会向上移动。我希望图像的中心是箭头尖端在图片中的位置:

这是图像的位置以及我想要的位置

这是CSS和HTML:

.header {
  padding: 10px 16px;
  background: #1919ff;
  color: #f1f1f1;
}
#about {
  background-color: #ccccff;
  height: 400px;
  width: 67%;
  margin: auto;
}
   
.round-border{
    border-width: 0px;
    border-style: solid;
    border-radius: 50%;
  }
.portrait-image{
    width: 25%;    
    margin-bottom: 120%;
  }
h9 {
    font-size: 142%;
    margin: auto;
    padding-right: 30%;
    padding-top: 12%;
    display: inline-block;
  
}
.header-bar{
    height: 3px;
    width: 51%;
    background: #272C31;
    margin-right: 23%;
    margin-top: 3%;
}
h10 {
    font-size: 142%;
    margin: auto;
    padding-right: 24%;
    padding-top: 5%;
    display: inline-block;
}
#image position {
  position: relative;
  z-index: 1;
  margin-botton: 40%;
  padding-bottom: 20%;
}
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css"/>
<style>
img {
    float: right;
}
.clearfix {
    overflow: auto;
}
</style>
<div class="header" id="myHeader">
  <h2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xxxxxxxxx</h2>
</div>
<body style="background-color: #5D6D7E;">
  <div id="about" align="center" position="relative">
    <h9><p align="right">xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx<br/>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx<br/>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p>
    </h9>
    <div class="header-bar"></div>
    <h10><p align="right">xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p>
    </h10>
    <div id="image position"><img class="portrait-image round-border" align="right" src="http://abload.de/img/gpuxh.png" alt="portrait">
    </div>
  </div>
 </body>

任何帮助将不胜感激,谢谢。

你的代码有很多问题,我不知道从哪里开始。没有 h9 或 h10 标头标记。我建议使用有效的标题标签并根据您的喜好修改字体大小。此外,类/ID 名称不能用空格分隔。因此,"图像位置"将不起作用。以我能做到的最好的方式修复它。

.header {
  padding: 10px 16px;
  background: #1919ff;
  color: #f1f1f1;
}
#about {
  background-color: #ccccff;
  height: 400px;
  width: 67%;
  margin: auto;
  box-sizing: border-box;
}
.round-border {
  border-radius: 50%;
}
.portrait-image {
  width: 25%;
}
.header-bar {
  height: 3px;
  width: 51%;
  background: #272C31;
  margin-right: 23%;
  margin-top: 3%;
}
#image-position {
  float: right;
  margin: 15% 5% 0 0;
}
#text {
  float: left;
  width: 57%;
  word-break: break-all;
  margin: 5%;
}
.clearfix {
  /*clear the floats here*/
}
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" />
<body style="background-color: #5D6D7E;">
  <div class="header" id="myHeader">
    <h2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xxxxxxxxx</h2>
  </div>
  <div id="about" class="clearfix">
    <div id="text">
      <p>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx<br/>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p>
      <div class="header-bar"></div>
      <p>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</p>
    </div>
    <img class="portrait-image round-border" id="image-position" src="http://abload.de/img/gpuxh.png" alt="portrait">
  </div>
</body>

您可以使用 CSS float。它适用于"浮动"到文本一侧的元素。

尝试设置:

#image-position {
  /* ... Your css here */
  float: right;
}

更多信息在这里。

使用引导程序来实现这一点,请尝试下面的代码片段。

<div class="container">
  <div class="row">
        <div class="col-md-8">
            <p>
                Your text goes here... 
            </p>
        </div>
        <div class="col-md-4">
          <img src="">      
      </div>
  </div>
</div>

我希望这有帮助,

最新更新