How to auto adjust the
height according to c

2020-01-27 02:32发布

I have a <div> which needs to be auto adjusted according to the content in it. How can I do this? Right now my content is coming out of the <div>

The class I have used for the div is as follows

box-centerside  {
background:url("../images/greybox-center-bg1.jpg") repeat-x scroll center top transparent;
float:left;
height:100px;
width:260px;
}

标签: css html
20条回答
爷、活的狠高调
2楼-- · 2020-01-27 03:00

I have fixed my issue by setting the position of the element inside a div to relative;

查看更多
Summer. ? 凉城
3楼-- · 2020-01-27 03:01

simply set the height to auto, that should fix the problem, because div are block elements so they stretch out to full width and height of any element contained in it. if height set to auto not working then simple don't add the height, it should adjust and make sure that the div is not inheriting any height from it's parent element as well...

查看更多
▲ chillily
4楼-- · 2020-01-27 03:03

Try with the following mark-up instead of directly specifying height:

.box-centerside {
  background: url("../images/greybox-center-bg1.jpg") repeat-x scroll center top transparent;
  float: left;
  min-height: 100px;
  width: 260px;
}
<div class="box-centerside">
  This is sample content<br>
  This is sample content<br>
  This is sample content<br>
  This is sample content<br>
  This is sample content<br>
  This is sample content<br>
  This is sample content<br>
  This is sample content<br>
  This is sample content<br>
  This is sample content<br>
  This is sample content<br>
  This is sample content<br>
</div>

查看更多
劳资没心,怎么记你
5楼-- · 2020-01-27 03:03

I've used the following in the DIV that needs to be resized:

overflow: hidden;
height: 1%;
查看更多
smile是对你的礼貌
6楼-- · 2020-01-27 03:03

just use following

height:auto;
查看更多
可以哭但决不认输i
7楼-- · 2020-01-27 03:04

height:59.55%;//First specify your height then make overflow auto overflow:auto;

查看更多
登录 后发表回答