html - 内联放置两个元素

标签 html css iframe

我正在尝试将 iframeimg 内嵌到 div 中。我发布的代码将 img 放在 iframe 下方。我已经尝试过 positionfloat 元素,但似乎没有任何效果。我还查看了关于 SO 的其他帖子,但似乎没有任何效果。如果需要,我愿意从头开始。

如果有人能指出我的错误并告诉我如何更正以使其正常工作,我将不胜感激。我看过其他帖子,但似乎没有任何效果。

谢谢。

@media (min-width: 1200px) {
  .container {
    max-width: 1080px;
  }
}
.hero-unit {
  background-color: #000000;
  border: 1px solid #252525;
  margin-bottom: 30px;
}
.hero-unit img {
  display: inline-block;
}
.fp-block {
  padding: 5px !important;
  padding: 0;
}
/*** CUSTOM CODE FOR YOUTUBE VIDEO DISPLAY ***/

.inner {
  float: left;
  width: 49%;
  margin: 0;
}
.holder {
  height: 0px;
  width: 100%;
}
<div class="container">
  <div class="hero-unit fp-block">
    <div id="ut-wrap">
      <div class="inner">
        <div class="holder">
          <iframe src="https://www.youtube.com/embed/_VRXrp_AfMM" frameborder="0" allowfullscreen></iframe>
          <img src="http://placehold.it/150x150">
        </div>
      </div>
    </div>
  </div>
</div>

最佳答案

问题

问题是 .innerwidth49%,这会将图像推到新的一行。如果您向 .inner 添加背景颜色和高度,则可以看到这一点。

@media (min-width: 1200px) {
  .container {
    max-width: 1080px;
  }
}
.hero-unit {
  background-color: #000000;
  border: 1px solid #252525;
  margin-bottom: 30px;
}
.hero-unit img {
  display: inline-block;
}
.fp-block {
  padding: 5px !important;
  padding: 0;
}
/*** CUSTOM CODE FOR YOUTUBE VIDEO DISPLAY ***/

.inner {
  float: left;
  width: 49%;
  margin: 0;
  background-color: red;
  height: 100px;
}
.holder {
  height: 0px;
  width: 100%;
}
iframe {
  opacity: 0.5;
}
<div class="container">
  <div class="hero-unit fp-block">
    <div id="ut-wrap">
      <div class="inner">
        <div class="holder">
          <iframe src="https://www.youtube.com/embed/_VRXrp_AfMM" frameborder="0" allowfullscreen></iframe>
          <img src="http://placehold.it/150x150">
        </div>
      </div>
    </div>
  </div>
</div>

如何修复

选项1

whitespace: nowrap; 添加到 .holder 以阻止图像换行到下一行

@media (min-width: 1200px) {
  .container {
    max-width: 1080px;
  }
}
.hero-unit {
  background-color: #000000;
  border: 1px solid #252525;
  margin-bottom: 30px;
}
.hero-unit img {
  display: inline-block;
}
.fp-block {
  padding: 5px !important;
  padding: 0;
}
/*** CUSTOM CODE FOR YOUTUBE VIDEO DISPLAY ***/

.inner {
  float: left;
  width: 49%;
  margin: 0;
}
.holder {
  height: 0px;
  width: 100%;
  white-space: nowrap;
}
<div class="container">
  <div class="hero-unit fp-block">
    <div id="ut-wrap">
      <div class="inner">
        <div class="holder">
          <iframe src="https://www.youtube.com/embed/_VRXrp_AfMM" frameborder="0" allowfullscreen></iframe>
          <img src="http://placehold.it/150x150">
        </div>
      </div>
    </div>
  </div>
</div>

选项 2

.inner 上设置更大的 width

@media (min-width: 1200px) {
  .container {
    max-width: 1080px;
  }
}
.hero-unit {
  background-color: #000000;
  border: 1px solid #252525;
  margin-bottom: 30px;
}
.hero-unit img {
  display: inline-block;
}
.fp-block {
  padding: 5px !important;
  padding: 0;
}
/*** CUSTOM CODE FOR YOUTUBE VIDEO DISPLAY ***/

.inner {
  float: left;
  width: 100%;
  margin: 0;
}
.holder {
  height: 0px;
  width: 100%;
}
<div class="container">
  <div class="hero-unit fp-block">
    <div id="ut-wrap">
      <div class="inner">
        <div class="holder">
          <iframe src="https://www.youtube.com/embed/_VRXrp_AfMM" frameborder="0" allowfullscreen></iframe>
          <img src="http://placehold.it/150x150">
        </div>
      </div>
    </div>
  </div>
</div>

关于html - 内联放置两个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41978129/

相关文章:

javascript - 强制内部 iframe 内容在页面加载时滚动到顶部

javascript - 获取不包括滚动条的整个 iframe 内容的大小

html - 我怎样才能右对齐我的div

html - 事件页面不工作

javascript - 如何将D3js图表放置在网格系统中?

css - 你能在背景图像重复之间创建空间吗?

javascript - 如何正确地将 youtube iframe 嵌入到 Angular2 View 中?获取不安全值错误

html - 尝试播放视频时,iframe 不断打开另一个选项卡上的链接

每次点击时 Jquery 触发动画(问题)

html - 隐藏相对位置和溢出的容器没有高度