0

2 つのテキスト div が互いに整列しているページのセクションを作成しようとしていますが、一方が他方の右側に浮いています。私が何をしようとしても、フローティング div は、開始する前に約 1 行の空白のテキストを残すようです。

http://jsfiddle.net/7MpYj/のフィドル

Chrome (および Safari) では次のように表示されます。

ここに画像の説明を入力

マージン、パディング、垂直方向の位置合わせを試しましたが、2 つの間の空白行を取り除くものは何もないようです。

CSS は次のとおりです。

body {
  font-family: sans-serif;
  font-size: 13px;
}
div.sidebar {
  width: 300px;
  float: right;
  background: pink;
}
div.maincolumn {
  background: #aaffaa;
}
div.clear {
  clear: right;
}

HTML は次のとおりです。

<div class="maincolumn">
  <div class="sidebar">
    <h3>Constitution</h3>
    We the People of the United States, in Order to form a more perfect
    Union, establish Justice, insure domestic Tranquility, provide for
    the common defence, promote the general Welfare, and secure the
    Blessings of Liberty to ourselves and our Posterity, do ordain and
    establish this Constitution for the United States of America.
  </div>
  <h3>Declaration</h3>
  When in the Course of human events, it becomes necessary for one
  people to dissolve the political bands which have connected them with
  another, and to assume among the powers of the earth, the separate and
  equal station to which the Laws of Nature and of Nature's God entitle
  them, a decent respect to the opinions of mankind requires that they
  should declare the causes which impel them to the separation.
  <p/>
  We hold these truths to be self-evident, that all men are created
  equal, that they are endowed by their Creator with certain unalienable
  Rights, that among these are Life, Liberty and the pursuit of
  Happiness.--That to secure these rights, Governments are instituted
  among Men, deriving their just powers from the consent of the
  governed, --That whenever any Form of Government becomes destructive
  of these ends, it is the Right of the People to alter or to abolish
  it, and to institute new Government, laying its foundation on such
  principles and organizing its powers in such form, as to them shall
  seem most likely to effect their Safety and Happiness.
</div>
<div class="clear">
  Edward by the grace of God King of England, lord of Ireland and
  duke of Aquitaine sends greetings to all to whom the present
  letters come. We have inspected the great charter of the lord
  Henry, late King of England, our father, concerning the liberties
  of England in these words:
</div>

フローティング div のテキストをプルアップする CSS マジックはありますか?

4

3 に答える 3

0

はい。overflow:autoに追加div.maincolumn

div.maincolumn {
    background: #aaffaa;
    overflow:auto;
}

jsFiddle の例

特定のレイアウトは、ブロックの書式設定コンテキストoverflow:autoの例であり、求める動作を復元する方法です。

于 2013-06-19T02:50:23.920 に答える
0

これを css に追加します。

div.sidebar h3 {
    margin-top:0;
}

ここにフィドルがあります:http://jsfiddle.net/7MpYj/3/

于 2013-06-19T03:12:45.313 に答える