简体   繁体   English

显示三个块的内联CSS

[英]Display three blocks inline CSS

I have three div 's, #left_sidebar , #records_list and #right_sidebar , I want to display them inline, but when I using display:inline-block , all seems to be fine but sidebars placing on the bootom of page, then I try to use float , but still getting some creppy behavior, then I do this: 我有三个div#left_sidebar#records_list#right_sidebar ,我想#right_sidebar联方式显示它们,但是当我使用display:inline-block ,一切似乎都很好,但是侧边栏放置在页面的尾部,然后尝试使用float ,但仍然出现一些爬行行为,那么我这样做:

#left_sidebar {
    top: 0px;
    width: 142px;
    float: left;
}

#records_list {
    width: 530px;
    display: inline-block;
}

#right_sidebar {
    background-image: url('../images/enstein_banner.png');
    width: 174px;
   height: 231px;   
   float: right;
}

(you see mix from float 's and display ), and all works fine, so can somebody explain me, if it right? (您会从floatdisplaydisplay看到混合),并且一切正常,所以有人可以解释一下吗? Or I need do this somehow else? 还是我需要以其他方式执行此操作? Thanks! 谢谢!

PS If you need more info, or it a little bit unclearly what I am asking just say, and I will try to improve question. PS:如果您需要更多信息,或者不清楚,我只是想说些什么,我将尝试改善问题。

 #left_sidebar { width: 10%; padding: 20px; background: red; float: left; margin-right: 1%; color: #fff; } #records_list { width: 50%; padding: 20px; background: red; float: left; margin-right: 1%; color: #fff; } #right_sidebar { background-image: url('../images/enstein_banner.png'); width: 15%; padding: 20px; background: red; height: 231px; float: left; color: #fff; } 
 <div class="wrapper"> <div id="left_sidebar">left bar</div> <div id="records_list">center part</div> <div id="right_sidebar">right bar</div> </div> 

Please now check this 现在请检查一下

Since all the three div have fixed width, you need a wrapping div width fixed width. 由于所有三个div均具有固定宽度,因此您需要一个包装div宽度为固定宽度。

And gave float:left instead of inline-block 并给了float:left而不是inline-block

Check the fiddle - https://jsfiddle.net/afelixj/racnob3f/ 检查小提琴-https: //jsfiddle.net/afelixj/racnob3f/

I know you know about the concepts of float, i think you need more clarification, There is a good discussion about the float, inline, inline-block here please refer float:left; 我知道您了解float的概念,我想您需要进一步澄清,有关float,内联,内联块的讨论很好,请参见float:left;。 vs display:inline; vs display:inline; vs display:inline-block; vs display:inline-block; vs display:table-cell; vs display:table-cell;

give float left to all blokes, float means that they will become inline and they will displayed one after another if you want to add space between them with margin 将浮点数留给所有bloks,float表示它们将变为内联,并且如果您要在它们之间添加边距,它们将一个接一个地显示

make changes like this: 进行如下更改:

#left_sidebar {
width: 142px;
float: left;
}

#records_list {
width: 530px;
float: left;
}

#right_sidebar {
background-image: url('../images/enstein_banner.png');
width: 174px;
height: 231px;   
float: left;
}

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

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