0

私は次のhtmlとcssコードを持っています:

<!DOCTYPE HTML>
<html>
<head>
</head>

<body>

    <div class="wrapper">
        <header>
            <section class="top">
                <div id="quote"><a href="contact.html"><p>Request a quote</p></a></div>
                <div class="arrow"><img src="icons/top-icon.png" alt=""></div>
            </section>
</body>
</html>​​​​​​​​​​​​​​​​​​

a {
    font-size: 1.6em;
    color: #fff;
    text-decoration: none;
    }
.top {
    height: 3.2em;    
    width: 100%;
    background: rgb(255,214,94); /* Old browsers */
    background: -moz-linear-gradient(top,  rgba(255,214,94,1) 0%, rgba(254,191,4,1) 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(255,214,94,1)), color-stop(100%,rgba(254,191,4,1))); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top,  rgba(255,214,94,1) 0%,rgba(254,191,4,1) 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top,  rgba(255,214,94,1) 0%,rgba(254,191,4,1) 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top,  rgba(255,214,94,1) 0%,rgba(254,191,4,1) 100%); /* IE10+ */
    background: linear-gradient(top,  rgba(255,214,94,1) 0%,rgba(254,191,4,1) 100%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffd65e', endColorstr='#febf04',GradientType=0 ); /* IE6-9 */
    position: fixed;
    top: 0;
    left :0;
    z-index: 10;
    text-align: center;
    border-bottom: 1px solid #f9e555;
    -webkit-box-shadow: 0px 0px 8px #555;
    -moz-box-shadow: 0px 0px 8px #555;
    box-shadow: 0px 0px 8px #555;
    }
.top div#quote {
    width: 20em;
    background: rgb(254,252,234); /* Old browsers */
    background: -moz-linear-gradient(top,  rgba(254,252,234,1) 0%, rgba(241,218,54,1) 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(254,252,234,1)), color-stop(100%,rgba(241,218,54,1))); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top,  rgba(254,252,234,1) 0%,rgba(241,218,54,1) 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top,  rgba(254,252,234,1) 0%,rgba(241,218,54,1) 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top,  rgba(254,252,234,1) 0%,rgba(241,218,54,1) 100%); /* IE10+ */
    background: linear-gradient(top,  rgba(254,252,234,1) 0%,rgba(241,218,54,1) 100%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fefcea', endColorstr='#f1da36',GradientType=0 ); /* IE6-9 */
    margin: 0 auto;
    }
.top div#quote p {
    color: #f2572a;
    height: 3.5em;
    font-size: 1.5em;
    padding: 0;
    margin: 0;        
    }
.top div#quote a {
    font-size: 1.1em;
    }
.top div#quote p:hover {
    color: #ed3419;
    }    
.arrow {
    display: inline-block;
    margin: 0 auto;
    border: 1px solid #000;
    position: relative;
    }

ここには2つの問題があります。1つは「Requestaquotediv」が、cssで定義された3.2emよりも大きいことです。もう1つは、text-alingを削除した場合:下の画像の.topスタイリングの中央にあることです。見積もりdivは中央に留まりません。.arrow divを相対位置に配置し、imgアイコンを絶対位置に配置しようとしましたが、divが完全に消えるため機能しません。他のアイデアはありますか?</ p>

4

2 に答える 2

8

.arrow要素のデフォルトの幅は100%であるため、設定はmargin: 0 auto水平方向には効果がありません。また、imgはインライン要素であるため、それでも機能しません。要素に明示的な幅を設定するか、.arrow要素に設定display: blockして幅を設定する必要があります。margin: 0 autoimg

于 2012-06-15T22:21:53.647 に答える
2

「見積もり依頼」の div は、高さがフォント サイズに比例するため、大きくなっています。em文字の現在の幅に基づいていますM(少なくとも古典的なタイポグラフィでは)。の要素の を変更したためfont-size、 の要素と同じ3.2emではありません。.top3.2em.top div#quote p

値を変更しない場合でもfont-size、値は異なります ( 3.2emin .top3.5emin .top div#quote p)。

代わりにすべてpadding-topの 、 、padding-bottommargin-topおよびを取り除き、単純に を使用する必要があります。margin-bottomheight:100%

HTML

<div class="wrapper">
    <header>
        <section class="top">
            <p class="quote"><a href="contact.html">Request a quote</a></p>
            <img class="arrow" src="icons/top-icon.png" alt="Arrow"></div>
        </section>
    </header>
</div>

CSS

a {
    color: #fff;
    text-decoration: none;
}

.top {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;

    z-index: 10;

    height: 3.2em;

    background: rgb(255,214,94); /* Old browsers */
    background: linear-gradient(top,  rgba(255,214,94,1) 0%,rgba(254,191,4,1) 100%); /* W3C */    

    text-align: center;

    border-bottom: 1px solid #f9e555;
    box-shadow: 0px 0px 8px #555;
}

.top p.quote {
    width: 20em;
    height:100%;  

    padding: 0;
    margin: 0 auto;

    color: #f2572a;    
    font-size: 1.6em;
    line-height:2.1em;

    background: rgb(254,252,234); /* Old browsers */
    background: linear-gradient(top,  rgba(254,252,234,1) 0%,rgba(241,218,54,1) 100%); /* W3C */
}

.top p.quote a{
    color: #f2572a;
}

.top p.quote a:hover{
    color: #ed3419;
}    
.arrow {
    display: inline-block;
    margin: 0 auto;
    border: 1px solid #000;
    position: relative;
}

/* gradient and other vendor specific quirks */
.top{
    /* background rules */
    background: -moz-linear-gradient(top,  rgba(255,214,94,1) 0%, rgba(254,191,4,1) 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(255,214,94,1)), color-stop(100%,rgba(254,191,4,1))); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top,  rgba(255,214,94,1) 0%,rgba(254,191,4,1) 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top,  rgba(255,214,94,1) 0%,rgba(254,191,4,1) 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top,  rgba(255,214,94,1) 0%,rgba(254,191,4,1) 100%); /* IE10+ */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffd65e', endColorstr='#febf04',GradientType=0 ); /* IE6-9 */

    /* vendor specific box shadows */    
    -webkit-box-shadow: 0px 0px 8px #555;
    -moz-box-shadow: 0px 0px 8px #555;
}

.top p.quote{    
    background: -moz-linear-gradient(top,  rgba(254,252,234,1) 0%, rgba(241,218,54,1) 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(254,252,234,1)), color-stop(100%,rgba(241,218,54,1))); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top,  rgba(254,252,234,1) 0%,rgba(241,218,54,1) 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top,  rgba(254,252,234,1) 0%,rgba(241,218,54,1) 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top,  rgba(254,252,234,1) 0%,rgba(241,218,54,1) 100%); /* IE10+ */    
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fefcea', endColorstr='#f1da36',GradientType=0 ); /* IE6-9 */
}

JSFiddleデモ

于 2012-06-15T22:24:58.733 に答える