html - 无法让图像在 UL 的右侧 float

标签 html css image css-float html-lists

我试图让图像 float 到 p 和 ul 标签的右侧...但是单个列表项总是脱离图像并出现在图像底部之后。我已经尝试了很多不同的方法(在阅读了其他人关于这个问题的问题之后),但就是无法让它与我的示例一起使用。

如有任何建议,我们将不胜感激。

请参阅下面的代码片段:

* {
  padding: 0;
  margin: 0;
}
p {
  line-height: 140%;
  color: #B4B4B4;
  font-size: 14px;
  font-weight: normal;
}
ul {
  font-size: 14px;
  line-height: 140%;
  font-weight: normal;
  list-style-type: disc;
  display: block;
  float: left;
  text-align: left;
  padding-left: 15px;
  margin-left: 15px;
  margin-right: 10px;
}
#awards {
  float: left;
  margin: 10px 0px 60px 10px;
  padding: 15px 15px 15px 15px;
  width: 650px;
  display: block;
  text-align: left;
  background-color: #000;
  font-size: 14px;
  color: #fff;
  border: 2px solid #FBDDA0;
}
p.news {
  line-height: 110%;
  font-weight: normal;
  text-align: left;
  font-size: 14px;
  color: fff;
}
p.news a {
  color: #fff;
  text-decoration: none;
}
p.news a:hover {
  color: #C0C0C0;
  text-decoration: underline;
}
#awards ul {
  margin-top: 5px;
  line-height: 110%;
  font-weight: normal;
  text-align: left;
  font-size: 13px;
  color: #fff;
}
#awards ul li {
  margin-bottom: 7px;
}
<div id="awards">
  <a href="http://www.allanzavod.com/images/Allan_OAM-med-adj.jpg" target="_blank">
    <img src="http://www.allanzavod.com/images/Allan_OAM-med-adj.jpg" width="200" height="190" style="float: right; margin-left: 10px; margin-bottom: 10px;" border="0" title="Allan Zavod awarded OAM - click to read article" alt="Allan Zavod awarded OAM - click to read article"
    />
  </a>
  <div>
    <p class="news">The late Dr. Allan Zavod received the <span style="color: #FBDDA0; font-weight: normal">Medal of the Order of Australia (OAM)</span> on January 26 2017, for service to the performing arts as a musician and composer. Here are some of his outstanding
      acheivements:</p>
    <ul style="padding-top: 7px;">
      <li>1st Australian to attend Berklee College of Music, Boston, on Duke Ellington's recommendation, 1970.</li>
      <li>1st Jazz Fusion Concerto on Australia Day for the Bicentenial at the Opera House performed by Australian Youth Orchestra in 1988.</li>
      <li>Won the Asia-Pacific Broadcasting Union (ABU) Song Contest in Kuala Lumpur (as composer), taking a very young singer Kate Ceberano on her first international performance, 1987.</li>
      <li>Awarded Doctor of Music by Melbourne University in recognition of his international achievements as a composer of Classical Jazz Fusion and for his substantial, original and distinguised contribution to music knowledge, 2009.</li>
      <li>Environmental Symphony, performed initially at The Banksia Environmental Awards in 2010. Later performed in full by the Melbourne Symphony Orchestra at Hamer Hall in 2015 - all proceeds (over $100,000.00) going to the Royal Melbourne Hospital for
        GBM Brain Cancer Research.</li>
    </ul>
  </div>

</div>
<!-- end awards -->

最佳答案

这就是 float 的工作原理。文本将环绕在 float 元素的周围和下方。

由于您的图像具有固定宽度,您可以为与图像宽度相匹配的文本包装应用边距。

* {
  padding: 0;
  margin: 0;
}
p {
  line-height: 140%;
  color: #B4B4B4;
  font-size: 14px;
}
ul {
  font-size: 14px;
  line-height: 140%;
  list-style-type: disc;
  padding-left: 15px;
  margin-left: 15px;
  margin-right: 10px;
}
#awards {
  margin: 10px 0px 60px 10px;
  padding: 15px;
  width: 650px;
  background-color: #000;
  font-size: 14px;
  color: #fff;
  border: 2px solid #FBDDA0;
}
p.news {
  line-height: 110%;
  font-weight: normal;
  font-size: 14px;
  color: fff;
}
p.news a {
  color: #fff;
  text-decoration: none;
}
p.news a:hover {
  color: #C0C0C0;
  text-decoration: underline;
}
#awards ul {
  margin-top: 5px;
  line-height: 110%;
  font-weight: normal;
  text-align: left;
  font-size: 13px;
  color: #fff;
}
#awards ul li {
  margin-bottom: 7px;
}

#awards > div {
  margin-right: 200px;
}
<div id="awards">
  <a href="http://www.allanzavod.com/images/Allan_OAM-med-adj.jpg" target="_blank">
    <img src="http://www.allanzavod.com/images/Allan_OAM-med-adj.jpg" width="200" height="190" style="float: right; margin-left: 10px; margin-bottom: 10px;" border="0" title="Allan Zavod awarded OAM - click to read article" alt="Allan Zavod awarded OAM - click to read article"
    />
  </a>
  <div>
    <p class="news">The late Dr. Allan Zavod received the <span style="color: #FBDDA0; font-weight: normal">Medal of the Order of Australia (OAM)</span> on January 26 2017, for service to the performing arts as a musician and composer. Here are some of his outstanding
      acheivements:
    </p>
    <ul style="padding-top: 7px;">
      <li>1st Australian to attend Berklee College of Music, Boston, on Duke Ellington's recommendation, 1970.</li>
      <li>1st Jazz Fusion Concerto on Australia Day for the Bicentenial at the Opera House performed by Australian Youth Orchestra in 1988.</li>
      <li>Won the Asia-Pacific Broadcasting Union (ABU) Song Contest in Kuala Lumpur (as composer), taking a very young singer Kate Ceberano on her first international performance, 1987.</li>
      <li>Awarded Doctor of Music by Melbourne University in recognition of his international achievements as a composer of Classical Jazz Fusion and for his substantial, original and distinguised contribution to music knowledge, 2009.</li>
      <li>Environmental Symphony, performed initially at The Banksia Environmental Awards in 2010. Later performed in full by the Melbourne Symphony Orchestra at Hamer Hall in 2015 - all proceeds (over $100,000.00) going to the Royal Melbourne Hospital for
        GBM Brain Cancer Research.</li>
    </ul>
  </div>

</div>

关于html - 无法让图像在 UL 的右侧 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42080081/

相关文章:

php - 将 srcset 与来自 d​​ir (php) 的随机图像一起使用

html - 为什么无序列表用于 HTML 和 CSS 中的水平菜单?

CSS flexible padding-divs with centered text inside, max-padding

java - 如何将 ImageIcon 转换为图像?

javascript - 关闭模态后页面变暗无法上下滚动

html - 背景附件图像 : fixed not working on mobile

ios - 将图像数组添加到 Realm 数据库

c# - 我的 Regex.Replace 不起作用

javascript - Angular : Calling function in factory from html ng-click

javascript - 使用 javaScript 复制时,div 之间的行高不相同