Setting a div's height in HTML with CSS

前端 未结 14 911
无人共我
无人共我 2020-12-05 09:36

I am trying to lay out a table-like page with two columns. I want the rightmost column to dock to the right of the page, and this column should have a distinct background c

相关标签:
14条回答
  • 2020-12-05 10:16

    It's enough to just use the css property width to do so.

    Here is an example:

    <style type="text/css">;
        td {
            width:25%;
            height:100%;
            float:left;
        }
    </style>
    
    0 讨论(0)
  • 2020-12-05 10:17

    A 2 column layout is a little bit tough to get working in CSS (at least until CSS3 is practical.)

    Floating left and right will work to a point, but it won't allow you to extend the background. To make backgrounds stay solid, you'll have to implement a technique known as "faux columns," which basically means your columns themselves won't have a background image. Your 2 columns will be contained inside of a parent tag. This parent tag is given a background image that contains the 2 column colors you want. Make this background only as big as you need it to (if it is a solid color, only make it 1 pixel high) and have it repeat-y. AListApart has a great walkthrough on what is needed to make it work.

    http://www.alistapart.com/articles/fauxcolumns/

    0 讨论(0)
  • 2020-12-05 10:18

    I gave up on strictly CSS and used a little jquery:

    var leftcol = $("#leftcolumn");
    var rightcol = $("#rightcolumn");
    var leftcol_height = leftcol.height();
    var rightcol_height = rightcol.height();
    
    if (leftcol_height > rightcol_height)
        rightcol.height(leftcol_height);
    else
        leftcol.height(rightcol_height);
    
    0 讨论(0)
  • 2020-12-05 10:18

    I had the same problem on my site (shameless plug).

    I had the nav section "float: right" and the main body of the page has a background image about 250px across aligned to the right and "repeat-y". I then added something with "clear: both" to it. Here is the W3Schools and the CSS clear property.

    I placed the clear at the bottom of the "page" classed div. My page source looks something like this.

    body
     -> header (big blue banner)
     -> headerNav (green bar at the top)
     -> breadcrumbs (invisible at the moment)
     -> page
         -> navigation (floats to the right)
         -> content (main content)
             -> clear (the quote at the bottom)
             -> footerNav (the green bar at the bottom)
         -> clear (empty but still does something)
     -> footer (blue thing at the bottom)
    

    I hope that helps :)

    0 讨论(0)
  • 2020-12-05 10:20

    Here's an example of equal-height columns - Equal Height Columns - revisited

    You can also check out the idea of "Faux Columns" as well - Faux Columns

    Don't go the table route. If it's not tabular data, don't treat it as such. It's bad for accessibility and flexibility.

    0 讨论(0)
  • 2020-12-05 10:20

    No need to write own css, there is an library called "Bootstrap css" by calling that in your HTML head section, we can achieve many stylings,Here is an example: If you want to provide two column in a row, you can simply do the following:

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    
    <div class="row">
      <div class="col-md-6">Content</div>
      <div class="col-md-6">Content</div>
    </div>

    Here md stands for medium device,,you can use col-sm-6 for smaller devices and col-xs-6 for extra small devices

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