0

私は 2 列の HTML/CSS レイアウトを使用して<div>sidebar</div>おり、div がコンテンツの横に完全に展開されないという問題があります (つまり、「サイドバー」の下部の間に大きなギャップがあります)。 div と「フッター」の div を削除すると、醜い空白ができてしまいます。

サンドボックス.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>My Title</title>
<link href="twoColLiqLtHdr.css" rel="stylesheet" type="text/css" />
<!--[if lte IE 7]>
    <style>
        .content { margin-right: -1px; } /* this 1px negative margin can be placed on any of the columns in this layout with the same corrective effect. */
        ul.nav a { zoom: 1; }  /* the zoom property gives IE the hasLayout trigger it needs to correct extra whiltespace between the links */
    </style>
<![endif]-->
</head>

<body>

<div class="container">
  <div class="header">
  My Header
  </div>
  <div class="sidebar1">
    <ul class="nav">
      <li><a href="#">Link 1</a></li>
      <li><a href="#">Link 2</a></li>
      <li><a href="#">Link 3</a></li>
      <li><a href="#">Link 4</a></li>
    </ul>
    <p>&nbsp;</p>
    </div>
  <div class="content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent luctus dolor nec ante imperdiet malesuada. Phasellus nec ipsum ipsum. Pellentesque lacus elit, tempor vitae laoreet nec, condimentum vel magna. Mauris imperdiet consectetur egestas. Praesent pellentesque, turpis ultricies elementum pellentesque, felis arcu consequat diam, quis viverra libero nibh a massa. Proin nec lectus at lorem semper hendrerit. Curabitur sed diam ut nisi ultrices vestibulum vel eget leo. Donec dapibus sem vel ipsum vestibulum suscipit. Donec faucibus ipsum eu neque facilisis blandit. Vivamus rhoncus odio in nibh pretium elementum.

Morbi adipiscing odio eu nibh gravida eu cursus risus luctus. Cras malesuada fermentum fermentum. Aliquam neque magna, pellentesque nec lobortis eget, scelerisque eu elit. Curabitur commodo leo porttitor eros commodo a venenatis odio vehicula. Aenean sodales diam ac orci interdum aliquam. Nulla sodales enim ut leo porttitor in mollis est consequat. Morbi lobortis nunc nec mi varius varius. Mauris ac velit eget augue cursus viverra. Mauris ut felis vehicula urna aliquet sodales ut vel purus. Pellentesque sed mi felis. In leo urna, dignissim et vestibulum tristique, lobortis quis est. Nulla tincidunt consequat mi a volutpat. Aenean ut arcu nibh, ut placerat augue. Etiam sollicitudin orci id neque ornare a euismod metus imperdiet.
  </div>
  <div class="footer">
    My Footer
    </div>
</body>
</html>

twoColLiqLtHdr.css:

@charset "UTF-8";
body {
    font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif;
    background: #699643;
    margin: 0;
    padding: 0;
    color: #000;
}

/* ~~ Element/tag selectors ~~ */
ul, ol, dl { /* Due to variations between browsers, it's best practices to zero padding and margin on lists. For consistency, you can either specify the amounts you want here, or on the list items (LI, DT, DD) they contain. Remember that what you do here will cascade to the .nav list unless you write a more specific selector. */
    padding: 0;
    margin: 0;
}
h1, h2, h3, h4, h5, h6, p {
    margin-top: 0;   /* removing the top margin gets around an issue where margins can escape from their containing div. The remaining bottom margin will hold it away from any elements that follow. */
    padding-right: 15px;
    padding-left: 15px; /* adding the padding to the sides of the elements within the divs, instead of the divs themselves, gets rid of any box model math. A nested div with side padding can also be used as an alternate method. */
}
a img { /* this selector removes the default blue border displayed in some browsers around an image when it is surrounded by a link */
    border: none;
}

/* ~~ Styling for your site's links must remain in this order - including the group of selectors that create the hover effect. ~~ */
a:link {
    color:#414958;
    text-decoration: none; /* unless you style your links to look extremely unique, it's best to provide underlines for quick visual identification */
}
a:hover {
    color:#414958;
    text-decoration: underline;
}

a:visited {
    color: #4E5869;
    text-decoration: underline;
}
a:hover, a:active, a:focus { /* this group of selectors will give a keyboard navigator the same hover experience as the person using a mouse. */
}

/* ~~ this container surrounds all other divs giving them their percentage-based width ~~ */
.container {
    width: 80%;
    max-width: 1260px;/* a max-width may be desirable to keep this layout from getting too wide on a large monitor. This keeps line length more readable. IE6 does not respect this declaration. */
    min-width: 1260px;/* a min-width may be desirable to keep this layout from getting too narrow. This keeps line length more readable in the side columns. IE6 does not respect this declaration. */
    background: #FFF;
    margin: 0 auto; /* the auto value on the sides, coupled with the width, centers the layout. It is not needed if you set the .container's width to 100%. */
    overflow: hidden;
}

/* ~~ the header is not given a width. It will extend the full width of your layout. It contains an image placeholder that should be replaced with your own linked logo ~~ */
.header {
    background: #A9B92E;
}

.sidebar1 {
    float: left;
    width: 20%;
    background: #94c493;
    padding-bottom: 10px;
}
.content {
    padding: 10px 0;
    width: 80%;
    float: left;
}

/* ~~ This grouped selector gives the lists in the .content area space ~~ */
.content ul, .content ol { 
    padding: 0 15px 15px 40px; /* this padding mirrors the right padding in the headings and paragraph rule above. Padding was placed on the bottom for space between other elements on the lists and on the left to create the indention. These may be adjusted as you wish. */
}

/* ~~ The navigation list styles (can be removed if you choose to use a premade flyout menu like Spry) ~~ */
ul.nav {
    list-style: none; /* this removes the list marker */
    border-top: 1px solid #666; /* this creates the top border for the links - all others are placed using a bottom border on the LI */
    margin-bottom: 15px; /* this creates the space between the navigation on the content below */
}
ul.nav li {
    border-bottom: 1px solid #666; /* this creates the button separation */
}
ul.nav a, ul.nav a:visited { /* grouping these selectors makes sure that your links retain their button look even after being visited */
    padding: 5px 5px 5px 15px;
    display: block; /* this gives the link block properties causing it to fill the whole LI containing it. This causes the entire area to react to a mouse click. */
    text-decoration: none;
    background: #E8EEC7;
    color: #000;
}
ul.nav a:hover, ul.nav a:active, ul.nav a:focus { /* this changes the background and text color for both mouse and keyboard navigators */
    background: #FDEAA6;
    color: #000;
}

/* ~~ The footer ~~ */
.footer {
    padding: 10px 0;
    background: #A9B92E;
    position: relative;/* this gives IE6 hasLayout to properly clear */
    clear: both; /* this clear property forces the .container to understand where the columns end and contain them */
}

/* ~~ miscellaneous float/clear classes ~~ */
.fltrt {  /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */
    float: right;
    margin-left: 8px;
}
.fltlft { /* this class can be used to float an element left in your page. The floated element must precede the element it should be next to on the page. */
    float: left;
    margin-right: 8px;
}
.clearfloat { /* this class can be placed on a <br /> or empty div as the final element following the last floated div (within the #container) if the #footer is removed or taken out of the #container */
    clear:both;
    height:0;
    font-size: 1px;
    line-height: 0px;
}




/* style the results tables */
#stylized p {
    font-size:11px;
    color:#666666;
    margin-bottom:20px;
    border-bottom:solid 1px #b7ddf2;
    padding-bottom:10px;
}
table.decorated {
  margin: 1em 1em 1em 2em;
  background: whitesmoke;
  border-collapse: collapse;
}
table.decorated th, table.decorated td {
  border: 1px silver solid;
  padding: 0.2em;
}
table.decorated th {
  background: gainsboro;
  text-align: left;
}
table.decorated caption {
  margin-left: inherit;
  margin-right: inherit;
}
table.decorated tr:hover {
   background: lightsteelblue !important;
}


/* Create the scrollable "boxes" */
.scrollArea {
width: 200px; 
height: 300px;
padding-left: 5px;
padding-right: 5px; 
border-color: #6699CC;
border-width: 1px; 
border-style: solid;
float: left; 
overflow: auto;
}
</style>
4

4 に答える 4

2

ああ、列を垂直に並べる。CSSのダークサイド。2つのオプションがあります。

  1. 少し複雑ですが、十分に文書化されたCSSを使用してください。この仲間は、私が以前に使用したことができる優れたテンプレートを持っており、それは素晴らしい働きをします。
  2. JavaScript。jQueryを使用すると、すべてのコンテンツがレンダリングされた後、小さい方のdivの高さを大きい方のdivの高さに設定できます。
于 2012-06-19T22:05:57.417 に答える
0

場合によっては、bg 画像を親コンテナーに追加するか、列をヘッダー、コンテンツ、フッターのセクションに分割し、それぞれのフッターを別のコンテナーに配置することで、同じ高さの列を偽装できます (同じことをヘッダー セクションが必要な場合)。列の幅が固定されている場合は、より多くのオプションを利用できます。

<div class="container-with-bg-image-for-all-columns">
    <div class="col1"></div>
    <div class="col2"></div>
    <div class="col3"></div>
</div>

また...

<div class="content-container">
    <div class="col1-content"></div>
    <div class="col2-content"></div>
    <div class="col3-content"></div>
</div>
<div class="footer-container">
    <div class="col1-footer"></div>
    <div class="col2-footer"></div>
    <div class="col3-footer"></div>
</div>

必要性が十分に高い場合は、列に HTML テーブルを使用するオプションを忘れないでください。これが、列のサイズと配置を完全に制御する唯一の簡単な方法です。私は display:table やその他のテーブル関連の表示値をテストしていませんが、HTML テーブルが提供する垂直方向の利点を得る別の方法かもしれません。

于 2012-06-19T22:15:56.743 に答える
0

IE7 以下をサポートする必要がない限り、レイアウトに float を使用しないでください。

.sidebar1 {
    display:table-cell;
    width: 20%;
    background: #94c493;
    padding-bottom: 10px;
}
.content {
    padding: 10px 0;
    width: 80%;
    display: table-cell;
}

この のように、 の内部で.contentは余白が機能しないため、要素に余分なパディングを追加することをお勧めします。display: table-cell;

于 2012-06-19T22:11:24.980 に答える
0

IE7 を気にしない場合は、次のように簡単に実行できます。

<style>
    div.sidebar_ {
        display:        table-cell;
        width:          20%;
        background:     red;
    }

    div.content_ {
        display:        table-cell;
        width:          80%;
        background:     blue;
    }
</style>

<div class="sidebar_">
    Sidebar
</div>
<div class="content_">
    Content<br>
    Content<br>
    Content<br>
    Content<br>
</div>

IE8 以上、およびその他のブラウザーで動作します。

于 2012-06-19T22:13:06.733 に答える