简体   繁体   English

如何使父元素成为子元素的大小?

[英]How to make parent element to be the size of the child element?

I have iframe inside div element: 我在div元素中有iframe:

<div id="toolbarArea" class="toolbarArea"  data-Date="11/2016"> 
            <img id="toolbarTitle" width="15px" height="15px" src="../stdicons/derem/threePoints.png">
            <iframe id="frTools" style="width:94%%;height:90%%;top:0px; position: absolute;" name="tbFrame" src="/container/serol/chegsorc.aspx?LOCALE=en" frameBorder="0"></iframe>             
          </div>

.toolbarArea{   
    background-color:#ffffff;
    width:450px; 
    position:relative; 
    z-index:100;
    height:30px;

    border: solid 1px #333;
    -webkit-box-shadow: 5px 5px 5px 0px rgba(0,0,0,0.75);
    -moz-box-shadow: 5px 5px 5px 0px rgba(0,0,0,0.75);
    box-shadow: 5px 5px 5px 0px rgba(0,0,0,0.75);
}

I get scroll on the div, how to make parent element to be the size of the child element to prevent the sccroll appereance. 我在div上滚动,如何使父元素成为子元素的大小以防止sccroll出现。

Removing the width and height from the class toolbarArea should do the trick : 从类工具toolbarArea删除widthheight

.toolbarArea {   
  background-color: #ffffff;
  position: relative; 
  z-index: 100;
  border: solid 1px #333;
  -webkit-box-shadow: 5px 5px 5px 0px rgba(0,0,0,0.75);
  -moz-box-shadow: 5px 5px 5px 0px rgba(0,0,0,0.75);
  box-shadow: 5px 5px 5px 0px rgba(0,0,0,0.75);
}

You can prevent the scroll appearance with this: 您可以使用以下方法防止滚动出现:

width: auto;
height: auto;
overflow: hidden;

You need to use one of float: left/right or display: inline/inline-block for parent to be same width as it's content 您需要使用float: left/rightdisplay: inline/inline-block使父对象的宽度与其内容相同

 #toolbarArea { background-color: #aaa; position: relative; display: inline-block; border: solid 1px #333; -webkit-box-shadow: 5px 5px 5px 0px rgba(0, 0, 0, 0.75); -moz-box-shadow: 5px 5px 5px 0px rgba(0, 0, 0, 0.75); box-shadow: 5px 5px 5px 0px rgba(0, 0, 0, 0.75); } #toolbarTitle { width: 15px; height: 15px; position: absolute; left: 0; top: 0; z-index: 10; } #frTools { width:94%; height:90%; } 
 <div id="toolbarArea" class="toolbarArea" data-Date="11/2016"> <img id="toolbarTitle" src="../stdicons/derem/threePoints.png"> <iframe id="frTools" name="tbFrame" src="/container/serol/chegsorc.aspx?LOCALE=en"></iframe> </div> 


Please note that your iFrame css is not valid, as 94%% must be 94% and so on. 请注意,您的iFrame css无效,因为94%%必须是94% ,依此类推。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM