css - 如何让我的 div 与标题在同一行?

标签 css html

HTML:

<h2> RAN sends fake news report on Hershey's Oil Commitment</h2>   
<div class="date">  
<div class="number">27</div>
<div class="month">Oct</div>  </div> 
<p>The Rainforest Action Network sent out a fake news report about Hershey's Oil   
Commitment. It stated that Hershey will remove palm oil from all of their products and 
a few news sites fell for it including Hershey's own hometown newspaper. On top of  
that, the people from RAN crashed Hershey's Halloween party with a very special   
orangutan! 
<a href="hershey.html">Want to know more?</a> </p>

CSS:

.date {
  width:50px;
  height:50px;
  background-color:orange;
  border-radius:1em;
  margin-left:75%;
}

.number {
  color:white;
  text-align:center;
}

.month {
  text-align:center;
  background-color:#E68A00;
  color:white;
}

h2 {
  font-size:1.2em;
  color:#007e7e;
}

我试图让新闻文章的日期和标题在同一行。这是现在的样子:

News Article

最佳答案

将日期和标题放在同一个 div/容器中并向左浮动 + 使用 clearfix 来避免父容器大小问题。

或者简单地使用 left/top 相对定位它们

关于css - 如何让我的 div 与标题在同一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19648067/

相关文章:

javascript - 隐藏和显示 WinJS.UI.PivotItem

html - Bootstrap 和 CSS - 修复药片的格式

html - 奇怪的 CSS 问题 - 在 Safari 上运行正常,在 Chrome 上运行不正常

javascript - 如何在 jquery datepicker 的禁用日期上显示工具提示

jquery - 软键盘在显示时调整移动网络的大小

css - 让背景图像显示在 Bootstrap 轮播的第一张幻灯片上

jquery - Textorientation jquerymobile按钮文本输入

javascript - 使用 jquery 根据包含类选择父 DIV 内容

javascript - 如何将 CSS background-position 属性从百分比转换为像素?

css - 标签背景颜色滑动过渡到下一个标签