【问题标题】:Creating a Drupal theme. How do I prevent my divs from wrapping to content size?创建 Drupal 主题。如何防止我的 div 换行到内容大小?
【发布时间】:2014-11-11 13:45:15
【问题描述】:

我正在开发我的第一个 Drupal 主题,到目前为止我只遇到了一个问题。我为我的所有 div 设置了百分比大小,以使网站更具响应性。然而,他们似乎忽略了大小,只是包装到他们的子内容。我该如何解决这个问题?

CSS

#wrapper {
  padding: 5%;
  width: auto;
  height: auto;  
  position: relative;
}
div {
margin: 0px;
padding: 5px;
}
#sidebar-first {
  float: left;
  display: inline;
  width: 19%;
  height: 79%;
  background-color: orange;
}
#header {
  float: right;
  display: inline;
  width: 79%;
  height: 19%;
  background-color: purple;
  text-align: right;
}
#sidebar-second {
  float: right;
  display: inline;
  width: 19%;
  height: 79%;
  background-color: red;

}
#content {
  float: left;
  display: inline;
  background-color: green; 

}
#footer {
  float: left;
  display: inline;
  width: 79%;
  height: 19%;
  background-color: pink;
}

PHP

<div id="wrapper">

    <?php if ($page['sidebar_first']): ?>    
    <div id="sidebar-first">
      <?php print render($page['sidebar_first']); ?>
    </div>
  <?php endif; ?> 

  <div id="header">
    <a href="<?php print $front_page;?>">
      <h1><?php print $site_name; ?></h1>
    </a>

    <?php if ($main_menu): ?>
      <?php print theme('links', $main_menu); ?>
    <?php endif; ?>

  </div>

  <?php if ($page['sidebar_second']): ?>    
    <div id="sidebar-second">
      <?php print render($page['sidebar_second']); ?>
    </div>
  <?php endif; ?>  

  <div id="content">
    <?php print render($title_prefix); ?>
      <?php if ($title): ?><h1><?php print $title; ?></h1><?php endif; ?>
    <?php print render($title_suffix); ?>

    <?php print render($messages); ?>
    <?php if ($tabs): ?><div class="tabs"><?php print render($tabs); ?></div><?php endif; ?>
    <?php if ($action_links): ?><ul class="action-links"><?php print render($action_links); ?></ul><?php endif; ?>

    <?php print render($page['content']); ?>
  </div>

  <div id="footer">
    <?php if ($page['footer']): ?>    
      <?php print render($page['footer']); ?>
    <?php endif; ?>  
  </div>

</div>

这是现在的样子: 希望它看起来与此类似,但他们在静态页面上使用了表格。

【问题讨论】:

    标签: html css drupal drupal-themes


    【解决方案1】:

    你可以试试 box-sizing。

    html {
      box-sizing: border-box;
    }
    *, *:before, *:after {
      box-sizing: inherit;
    }
    

    接下来是 CSS 的其余部分

    【讨论】:

      【解决方案2】:

      我想通了。由于我在正文和 html 中有一个包装器,因此我必须将它们中的所有 3 个设置为 100% 才能达到预期的效果。以及按照 Billy_Bob 的建议使用盒子大小。

      html {
        box-sizing: border-box;
      }
      *, *:before, *:after {
        box-sizing: inherit;
      }
      html, body {
        width: 100%;
        height: 100%;
      }
      #wrapper {
        padding: 4%;
        width: 100%;
        height: 100%;
        min-height: 500px;
        min-width: 850px;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-10-16
        • 1970-01-01
        • 1970-01-01
        • 2011-03-17
        • 2013-01-04
        • 1970-01-01
        • 1970-01-01
        • 2011-09-12
        相关资源
        最近更新 更多