左右浮动不起作用

时间:2014-05-02 07:34:07

标签: jquery css html

  

http://jsfiddle.net/S2fe9/   容器应该彼此相邻但是在换行后才会出现

    <div data-role="page" id="pageone">


    <div data-role="header" data-theme="b" data-position="fixed">
        <h2>Audi A8</h2>
    </div>

    <div id="paintarea">

        <div id="painttext" class="pt">
            <h3>
                <b>Paint</b>
            </h3>
            <p>We believe that every part of your car should have a personal
                touch. Which is why you can choose from a wide range of paint
                colours and finishes, from standard shades to metallic and pearl
                effects.</p>
        </div>

        <div id="paintcolor" class="pc">
                      <b>Paint</b>
            </h3>
            <p>We believe that every part of your car should have a personal
                touch. Which is why you can choose from a wide range of paint
                colours and finishes, from standard shades to metallic and pearl
                effects.</p>

        </div>
    </div>
</div>

4 个答案:

答案 0 :(得分:0)

尝试在CSS下面更新:

#painttext {
    width: 20%;
    padding-top: 85px;
    padding-right: 50px;
    padding-left: 50px;
    text-align: justify;
    text-justify: interword; }

实际上宽度被错误地应用并且与其他div重叠

检查更新的小提琴here

答案 1 :(得分:0)

padding-right&amp; padding-left为容器添加额外的宽度,尝试在应用之前进行计算。尝试此代码:现在总宽度将达到100%,如果超过100%,则会转到下一行。

<强> CSS

#paintarea
{

    width: 100%;
    height: 100%;

}
#painttext {
    width: 30%;
    padding-right: 10%;
    padding-left: 10%;
    text-align: justify;
    text-justify: interword;
}

#paintcolor
{
    width: 50%;

}

.pt
{
    float: left;
}
.pc
{
    float: left;
}

更新小提琴Here

答案 2 :(得分:0)

试试这个:

HTML:

 <div data-role="page" id="pageone">
    <div data-role="header" data-theme="b" data-position="fixed">
      <h2>Audi A8</h2>
    </div>

    <div id="paintarea">
      <div id="painttext" class="pt">
        <h3> <b>Paint</b></h3>

        <p>We believe that every part of your car should have a personal touch. Which is       
           why you can choose from a wide range of paint colours and finishes, from 
           standard shades to metallic and pearl effects.</p>
       </div>

    <div id="paintcolor" class="pc">
         <h3><b>Paint</b></h3>

        <p>We believe that every part of your car should have a personal touch. Which is 
           why you can choose from a wide range of paint colours and finishes, from 
           standard shades to metallic and pearl effects.</p>
    </div>
    </div>
</div>

CSS:

  #paintarea {
   width: 100%;
   height: 100%;
   }
   #painttext {
   width: 20%;
   padding-top: 85px;
   padding-right: 50px;
   padding-left: 50px;
   text-align: justify;
   text-justify: interword;
   }
   #paintcolor {    
   width: 55%;
   }
  .pt {
   float: left;
   }
  .pc {
   float: right;
   }

答案 3 :(得分:0)

试试这个:

<强> CSS

#paintarea
{
    width: 100%;
    height: 100%;
}

#painttext {
    width: 30%;
    padding-right: 10%;
    padding-left: 10%;
    text-align: justify;
    text-justify: interword;
 }

#paintcolor
{
    width: 50%;
}

.pt
{
    float: left;
}

.pc
{
    float: left;
}