如何根据内容拉伸DIV

时间:2014-03-18 17:52:52

标签: html css css-position

我有一个包含一些内容的div,HTML如下:

<div id="subpageFooter">
    <div id="subpageFooterLeft">
        <div style="z-index: 15; position: relative; left: 0; padding-left: 20px; padding-top: 30px; font-weight: bold; color: #00A0BE; font-size: 13px;">
            State-Of-The-Art-Technology
        </div>
        <div style="z-index: 14; position: relative; left: 0; padding-left: 40px; padding-top: 10px; padding-right: 8px; font-weight: normal; color: #000000; font-size: 12px;">
            Our state-of-the-art technology ensures that we provide the finest healthcare. Our practice continuously invests in systems and equipment so that physicians can diagnose problems in the most accurate and efficient manner possible.
        </div>
        <div style="position: relative; width: 90%; padding-left: 5%; padding-top: 10px; padding-right: 5%;"><hr /></div>
        <div style="z-index: 13; position: relative; left: 0; padding-left: 20px; padding-top: 10px; font-weight: bold; color: #00A0BE; font-size: 13px;">
            Advanced Electronic Medical Records
        </div>
        <div style="z-index: 12; position: relative; left: 0; padding-left: 40px; padding-top: 10px; padding-right: 8px; font-weight: normal; color: #000000; font-size: 12px;">
            Our advanced electronic medical record improves patient care and gives physicians all of the important patient information they need in one place.
        </div>
        <div style="position: relative; width: 90%; padding-left: 5%; padding-top: 10px; padding-right: 5%;"><hr /></div>
        <div style="z-index: 11; position: relative; left: 0; padding-left: 20px; padding-top: 10px; font-weight: bold; color: #00A0BE; font-size: 13px;">
            Premier Radiology Services
        </div>
        <div style="z-index: 10; position: relative; left: 0; padding-left: 40px; padding-top: 10px; padding-right: 8px; font-weight: normal; color: #000000;font-size: 12px;">
            Filmless radiology capabilities provide rapid results and allow physicians to view images on an office computer screen within minutes. Our premier radiology services include MRI, CT scan, ultrasonography, nuclear medicine, bone densitometry and mammography. We offer computer-aided diagnosis (CAD), which is a tool to assist the radiologist in more accurately diagnosing breast disease.
        </div>
        <div style="position: relative; width: 90%; padding-left: 5%; padding-top: 10px; padding-right: 5%;"><hr /></div>
        <div style="z-index: 9; position: relative; left: 0; padding-left: 20px; padding-top: 10px; font-weight: bold; color: #00A0BE; font-size: 13px;">
            Our Employees Make MED a Special Place
        </div>
        <div style="z-index: 8; position: relative; left: 0; padding-left: 40px; padding-top: 10px; padding-right: 8px; font-weight: normal; color: #000000; font-size: 12px;">
            MED values each of our employees’ experience, diversity and dedication. Ideas and backgrounds that our employees bring to our company enable us to be more effective in anticipating and exceeding our patients’ needs and expectations. <a class="blueLinks" href="http://www.MEDgroup.com/talented_people.aspx">Click here</a> for the opportunity to meet some of the employees who greatly contribute to our success.
        </div>
        <div style="position: relative; width: 90%; padding-left: 5%; padding-top: 10px; padding-right: 5%;"><hr /></div>
        <div style="z-index: 7; position: relative; left: 0; padding-left: 20px; padding-top: 10px; font-weight: bold; color: #00A0BE; font-size: 13px;">
            Wide Range Of Insurances
        </div>
        <div style="z-index: 6; position: relative; left: 0; padding-left: 40px; padding-top: 10px; padding-right: 8px; font-weight: normal; color: #000000; font-size: 12px;">
            A big advantage to using MED Medical Group is the <a class="blueLinks" href="http://www.MEDgroup.com/participating_insurance.aspx?id=473">wide range of insurance coverage</a> accepted. This means you should be able to keep your doctors even if you find you have to change insurance plans. We care equally about every patient regardless of the insurance provider.
        </div>
    </div>
    <div id="subpageFooterRight">
        <!-- #include virtual ="includeNav/hospAff.inc" -->
    </div>
</div>

CSS就是这样:

#subpageFooter {
    position: relative;
    width: 100%;
    height: 715px;
    background: url('../theImages/bg_90_w.png');
    /*box-shadow: 0 0 10px #FFFFFF;*/
}
#subpageFooterRight {
    position: absolute;
    right: 0;
    width: 40%;
    height: 100%;
    float: right;
    background-color: #CCCCCC;
    background: url('../theImages/vshadow.png') 0 0 repeat-y;
    text-align: center;
}
#subpageFooterLeft {
    position: absolute;
    left: 0;
    float: left;
    width: 60%;
    height: 100%;
}

当我放大时,内容会超出subpageFooterLeft div

enter image description here

如何修改它以使div伸展以匹配内容?

3 个答案:

答案 0 :(得分:0)

问题是您要将height: 100%设置为#subpageFooterLeft。删除此规则可修复缩放问题:

http://jsfiddle.net/qtDm3/

#subpageFooterLeft {
    position: absolute;
    left: 0;
    float: left;
    width: 60%;
    /* height: 100%; */
}

答案 1 :(得分:0)

您也可以尝试将其放入css中:

overflow:auto;

答案 2 :(得分:0)

试试这个:

overflow:hidden;
height:1%;