0

HTML と CSS の学習を始めたばかりで、単純な静的 Web サイトを作成しようとしています。私の問題は、 div container( option2) を css でスクロールさせようとしていることですoverflow:auto

問題は、が有効になっているときに、間違った場所に配置されたり、重複したりする内部 div があることoverflow:autoです。#box2の内部 div です#option2#box2textdivの内部divです#box2

HTML

<div id="option2">
    <div id="box2">
        <img class="pic1" src="img/button top/user1.png"></img>
        <div id="box2text">Text for updates, news, events, ect.</div>
    </div>
    <div id="box2">
        <img class="pic1" src="img/button top/user1.png"></img>
        <div id="box2text">Text for updates, news, events, ect.</div>
    </div>
    <div id="box2">
        <img class="pic1" src="img/button top/user1.png"></img>
        <div id="box2text">Text for updates, news, events, ect.</div>
    </div>
    <div id="box2">
        <img class="pic1" src="img/button top/user1.png"></img>
        <div id="box2text">Text for updates, news, events, ect.</div>
    </div>
</div>

CSS

#option2 {
    height:90%;
    width:35%;
    margin-left:0;
    margin-right:5%;
    margin-top:2%;
    min-height:90%;
    position:apsolute;
    float:left;
    text-align:center;
    overflow:auto;
    display:block;
    -moz-border-radius: 15px;
    border-radius: 15px;
    border:solid white;
}
#box2 {
    height:25%;
    width:90%;
    float:center;
    text-align:center;
    margin:0 auto;
    margin-top:15px;
    margin-bottom:5px;
    bottom:0px;
    -moz-border-radius: 15px;
    border-radius: 15px;
    border:solid white;
}
img.pic1 {
    float:left;
    height:80px;
    width: 80px;
    margin-left:20px;
    margin-top:20px;
    -moz-border-radius: 15px;
    border-radius: 15px;
    border:solid white;
}
#box2text {
    float:right;
    height:80%;
    width:65%;
    margin-right:1%;
    margin-top:20px;
    background-color:grey;
    -moz-border-radius: 15px;
    border-radius: 15px;
    border:solid white;
}
4

1 に答える 1

0

私が見ることができる唯一の問題は、#option2 の css でabsoluteスペルが間違っていて、float 値を使用しようとしていることですcenter。要素を水平方向に中央に配置するには、次を使用します

margin-left: auto; 
margin-right: auto

また、ID は 1 回だけ使用する必要があります。通常、ブラウザが HTML をレンダリングする方法には影響しませんが、HTML 標準によれば正しくありません。同じ ID を持つ複数の要素があると、特に JavaScript を使用してそれらの要素を操作する場合に、ブラウザーで混乱が生じる可能性があります。

この jsfiddle をabsolute修正して参照してください: http://jsfiddle.net/qpkJV/1/

于 2013-03-10T12:21:17.647 に答える