How to make an empty div take space

前端 未结 12 1671
广开言路
广开言路 2020-12-12 13:03

This is my 960 grid system case:

ID
相关标签:
12条回答
  • 2020-12-12 13:30

    With using the inline-block it will behave as an inline object. so no floats needed to get them next to eachother on one line. And indeed as Rito said, floats need a "body", like they need dimensions.

    I totally agree with Pekka about using tables. Everybody that build layouts using div's avoid tables like it's a desease. But use them for tablular data! That's what they're ment for. And in your case i think you need them :)

    BUT if you really really want what you want. There is a css hack way. Same as the float hack.

    .kundregister_grid_1:after {  content: ".";  }
    

    Add that one and you're also set :D (Note: does not work in IE, but that is fixable)

    0 讨论(0)
  • 2020-12-12 13:31

    it works if you remove floating. http://jsbin.com/izoca/2/edit

    with floats it only works if theres some content e.g.  

    0 讨论(0)
  • 2020-12-12 13:33

    Slight update to @no1cobla answer. This hides the period. This solution works in IE8+.

    .class:after
    {
        content: '.';
        visibility: hidden;
    }
    
    0 讨论(0)
  • 2020-12-12 13:36

    A simple solution for empty floated divs is to add:

    • width (or min-width)
    • min-height

    this way you can keep the float functionality and force it to fill space when empty.

    I use this technique in page layout columns, to keep every column in its position even if the other columns are empty.

    Example:

    .left-column
    {
       width: 200px;
       min-height: 1px;
       float: left;
    }
    
    .right-column
    {
        width: 500px;
        min-height: 1px;
        float: left;
    }
    
    0 讨论(0)
  • 2020-12-12 13:38

    If they need to be floated, you could always just set the min-height to 1px so they don't collapse.

    0 讨论(0)
  • 2020-12-12 13:41

    Try adding   to the empty items.

    I don't understand why you're not using a <table> here, though? They will do this kind of stuff automatically.

    0 讨论(0)
提交回复
热议问题