0

私は3つのdivを取得しました:

  • 並んでいる必要があります(一列に)
  • すべてに背景画像があります
  • 中央の div は自動的に幅を調整する必要があり、中央の div の幅は div に挿入されたコンテンツに依存します ( 長いテキスト = 長い幅
  • center div もページの中心にある必要があります。
  • 側面の div には異なる背景 img があります。

HTML コード:

<div class="spanl"></div>
<div class="center">Headline</div>
<div class="spanr"></div>

両側の div は空であることに注意してください。

このようなもの: http://jsfiddle.net/fsnuh/134/

これはcssまたはcss3で行うことができますか? そうでない場合、どうすればjqueryまたは生のjavascriptでそれを行うことができますか?

4

3 に答える 3

4

勝利のためのテーブル!フィドル

<!DOCTYPE html>
<html>
    <head>
        <style type="text/css">
            #container {  display: table; width: 100% }
            #left, #right { display: table-cell; width: 50%; background: #ffd }
            #content { display: table-cell }
        </style>
    </head>
    <body>
        <div id="container">
            <div id="left"></div>
            <div id="content">
                <div style="white-space: nowrap" onclick="this.firstChild.nodeValue += ' blah'">blah</div>
            </div>
            <div id="right"></div>
        </div>
    </body>
</html>
于 2012-06-08T08:16:33.360 に答える
1

この CSS のみのソリューションを試してください。

jsFiddle の例

HTML:

<div id="headlines">
    <h3 class="headline2">
        <span>Kontakt</span>
    </h3>
</div>

CSS:

#headlines {
    background-image: url('../img/headline2.png'), url('../img/headline2.png');
    background-repeat: no-repeat;
    background-position: left center, right center
}
.headline2, .headline2 > span {
    height: 33px;
    text-align: center;
    text-transform: uppercase;
    line-height: 33px
}
.headline2 > span {
    background-color: #E6B043;
    display: inline-block;
    padding: 0 10px
}
于 2012-06-08T08:20:13.040 に答える
1

可能であれば、ヘッダーの幅を固定してください。次に、jQuery を使用して幅を計算し、それに応じて設定します。

これが実際のデモです: http://jsfiddle.net/rniestroj/fsnuh/135/

html:

<div>
     <h3 class="headline2">
     <div class="spanl"></div>
     <div class="center">Kontakt 11111111111 22222</div>
     <div class="spanr"></div>
     </h3>
</div>

CSS:

*{
    padding: 0;
    margin: 0;    
}

h3{
    width: 600px;
    overflow: auto;
}

.spanr, .spanl {
    background: url("../img/headline2.png") no-repeat scroll right center gold;
    float: left;
    height: 33px;
    position: relative;
    width: 33%;
}
.center {
    background: none repeat scroll 0 0 #E6B043;
    float: left;
    height: 33px;
    line-height: 33px;
    padding: 0 10px;
    position: relative;
    text-transform: uppercase;
    width: auto;
}

js:

var h3Width = $("h3").width();
var centerWidth = $(".center").width();
var asideWidth = 0;
asideWidth = ((h3Width - centerWidth) / 2) - 12;

$(".spanl").width(asideWidth );
$(".spanr").width(asideWidth );
于 2012-06-08T07:56:28.123 に答える