如何相对于另一个div元素减小div元素的高度

时间:2014-01-31 16:43:08

标签: html css height

我正在尝试减少包含内容的div元素的高度,使其略小于其对应的div,以便内容不会溢出到其他元素中,这是他们执行此类问题的方法。

<!DOCTYPE html>

<html>
  <head>
   <script>
        .atlas.region-map
    {
    border: 2px solid #716E64;
    max-width: 500px;
    overflow: hidden;
    margin: 0;
    float: left;
    }

   .atlas .map-content .info-col
   {
    margin-left: 549px;
    width: 335px;
   }

  .atlas .map-content .info-col p
   {
   color: #5c5642;
   margin-top: 15px;
  font-size: 12px;
   }
  .Atlas_Test
  {
      height: 300px;
      font-size: 14px;
      overflow-y: scroll;
  }
  </script>
  </head>

  <body>
    <div class="info-col">
    <p>Content will go here</p>
    </div>

 </body>

1 个答案:

答案 0 :(得分:0)

如果那不起作用,那么它实际上没有执行!

您需要在style元素中放置CSS编码而不是script。脚本元素用于JS代码。

但是,为了减小div的大小,您可以尝试以下代码:

max-height: 90%; // shorten it!

这样你可以阻止div变得比这个大。内容不会移出。使用此代码,元素将获得父元素高度大小的90%!因此不会移出解决方案盒。

要提供滚动条,请使用:

overflow: scroll;