【问题标题】:css two div floated left . Right div not covering the remaining spacecss 两个 div 向左浮动。右 div 不覆盖剩余空间
【发布时间】:2012-05-12 00:12:01
【问题描述】:

我有两个 div leftSide 和 rightSide,它们的父级是 innerContainer。我已将两个 div 浮动到左侧。它们并排出现,但右侧 div 没有覆盖父 div 的剩余空间。

我尝试使用 overflow:hidden 并指定了宽度,但仍然是相同的宽度。

我的 CSS:

  #container {
  overflow:auto;
  margin:10px auto;
}

   #innerContainer{
        margin:10px auto;   
        width:1200px;
        background:#FFFFFF;
        border:2px solid #09F;
        overflow:auto;
}

 #leftSide{
overflow:auto;
float:left;
width:700px;
border:3px solid #F00;
 }

 #topheaderProfile{
margin:5px;
border:1px solid #F00;
  }

   #middleCompanyDescription{
margin:5px;
border:1px solid #333;
  }

  #Profile{
text-align:left;
  }

 .ProfileBox{
padding:10px;
cursor:pointer;
overflow:hidden;
text-align:left;
word-break:break-all;
word-wrap:break-word;
 }

 .CompanyLogo{
float:left;
padding:5px;
 }

 .rightCover{
overflow:auto;
padding:1px;
 }

  .companyTitle{
color:#36F;
font-size:24px;
overflow:hidden;
 }

 .companyTitle a{
text-decoration:none;
 }

 .CompanyRating{
float:left;
margin-top:3px;
 }

 .Companylikedicon{
overflow:hidden;
float:right;
margin-left:10px;
 }

.Companycommenticon{
float:right;
margin-right:10px;
}



.CompanySlogan{
color:#999;
word-break:break-all;
word-wrap:break-word;
clear:both;
 }



  #rightSide{
width:100px;
border:1px solid #000;
  }

我的 HTML:

  <div id="container">
     <div id="innerContainer">

           <div id="leftSide"> 

        <div id="topheaderProfile">
            <div id='Profile'>
                <div class='ProfileBox'>
                    <div class='CompanyLogo'><img src='../Images/defaultPic.jpg' width='90' height='90'/></div> 
                    <div class='rightCover'>
                        <div class='companyTitle'>My Company</div>
                        <div class='CompanyRating'>
                                            Rating : <img src='../Images/FilledStar.png' width='20' height='20' id='Star1' />       
                                            <img src='../Images/EmptyStar.png' width='20' height='20' id='Star2' />
                                            <img src='../Images/EmptyStar.png' width='20' height='20' id='Star3' />
                                            <img src='../Images/EmptyStar.png' width='20' height='20' id='Star4' />
                                            <img src='../Images/EmptyStar.png' width='20' height='20' id='Star5' />
                         </div>

                         <div class='Companylikedicon'><img src='../Images/LikedIcon.png'  width='25' height='25' /> 100</div>
                         <div class='Companycommenticon' ><img src='../Images/comment.png'  width='25' height='25' /> 100</div>

                         <div class='CompanySlogan'>This is the best offer you get 2Rs. off in the besaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaat underwear of the worldffer you get 2Rs. off in the besaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaat underwear of the world.</div>
                   </div>

               </div>    <!--ProfileBox-->
            </div>
           </div><!--TopHeeaderProfile-->

    <div id="middleCompanyDescription">
sadasdsad
    </div>




         </div>     <!--LeftSide-->


        <div id="rightSide">
          sadasdasdasd
        </div>


     </div>


 </div>

好的,我找到了问题。还有另一个 css 文件包含与此文件中相同的 id 名称。这导致了问题。该文件的属性正在此处应用。 感谢大家的帮助。

【问题讨论】:

  • 浮动项目需要有一个指定的宽度。
  • 你可以看到我已经为这两个项目指定了宽度。

标签: css


【解决方案1】:

我尝试使用 overflow:hidden 并指定了宽度,但仍然是相同的宽度。

使用overflow: hidden,但如果您希望#rightSide 填充剩余空间,请不要指定任何width

见:http://jsfiddle.net/thirtydot/Yuxzs/

#rightSide {
    overflow: hidden;
    border: 1px solid #000;
}​

【讨论】:

  • 我的意思是我已经一一使用了这两个选项,但它们都不起作用。
  • 你的代码在小提琴中工作,但我做同样的事情。它在那里不起作用。
  • 您在哪个浏览器中测试?你能做一个JS Bin 演示来展示你的代码是如何不工作的吗?
【解决方案2】:

试试这个:

<style type="text/css">
#rightSide {
 width:100px;
 border:1px solid #000;
 float:left;
}
</style>

【讨论】:

  • 如果你想要 leftSide 和 rightSide 在我这边,那么上面的代码对我有用...尝试将宽度放在#rightSide ...
  • 问题是上面的代码也总是对我有用。但现在同样的事情不起作用,我认为这是其他东西不能让它覆盖空间,我不是能够弄清楚。
  • 试试 float:left !important;一次
  • 为什么不试试把
    放在
猜你喜欢
  • 2022-08-13
  • 1970-01-01
  • 1970-01-01
  • 2014-02-04
  • 1970-01-01
  • 1970-01-01
  • 2014-12-08
  • 2022-10-04
  • 1970-01-01
相关资源
最近更新 更多