css - 我认为基本的 css 但仍然做不到 - 试图将两个 div 放在另一个 div 中

标签 css html

为此工作了大约两个小时。我想做这个:

enter image description here

看起来像这样:

enter image description here

这是我的代码。我一直在尝试使用 padding-bottom、margin-bottom 等,但它只是在问号 div (area_help) 下方添加像素,将下面的 div 向下推——而不是像我希望的那样将 area_help 定位在 your_area 中。任何帮助,将不胜感激。谢谢!

html/erb 文件(它是一个 Rails 应用程序,但不认为这很重要):

 <div id="your_area">
  <div id = "Address_book_area">
    <% if current_resource.name == @resource.name %>
    <%= "Your Area:" %>
    <% else %>
      <% if @resource.is_company? %>
        <%= "#{@resource.name}" + "'s Area:" %>
      <% else %>
        <%= "#{@resource.first_name.capitalize}" + " " + "#{@resource.last_name.capitalize}" + "'s Area:" %>
      <% end %>
    <% end %>
  </div>


    <div id = "area_help">
      <%= image_tag("why_fb_log_in.png") %>
    </div>
  </div>

CSS:

#your_area {
margin-top: 100px;
margin-left: 240px;
margin-bottom: 20px;

#Address_book_area {
font-size: 28px;
width: 140px;
float: left;
}

#area_help {
width: 30px;
display: inline-block;
}

}

最佳答案

这看起来像是相对定位合理的情况:

#area_help {
  position: relative; 
  top: -15px
 }

相对定位将移动元素,但保持文档流不变。

关于css - 我认为基本的 css 但仍然做不到 - 试图将两个 div 放在另一个 div 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19284476/

相关文章:

php - 用动态语言开发多个页面,但需要输出到静态 HTML 文件?

c# - 如何从C#中的网页获取所有显示文本

javascript - 如何将当前页面样式表作为字符串获取?

c++ - 如何使用 C++ 从网页中获取文本?

asp.net - 帮助设计 asp :button control using the Sliding Door technique

Javascript 函数仅适用于第二次点击

asp.net - 缓存策略、css/js/images 如何让它们在我每次完全回发时不加载?

javascript - 不应自动选择 select 的第一个选项

javascript - 在网络日历中定位 div 元素的问题

javascript - 表固定头 : Should move when scrolling horizontally