2017-03-15 56 views
0

我正在嘗試使按鈕在調整窗口大小時隨文本一起移動。我無法弄清楚它爲什麼不起作用,即使它具有與其他ID /類相同的屬性。按鈕不會隨着區塊級別文本移動div

Check here for JSFiddle

.relative{ 
 
    position:relative; 
 
    width:100%; 
 
} 
 
.absolute-text { 
 
    color: white; 
 
    position:absolute; 
 
    bottom:0; 
 
    top: 115px; 
 
    width:100%; 
 
    text-align:center; 
 
    font-family: 'Raleway', sans-serif; 
 
} \t 
 
#fontStyle { 
 
    font-weight: 700; 
 
    font-size: 48px; 
 
} 
 
#fontStyle2 { 
 
    font-size: 25px; 
 
    text-decoration: none; 
 
    font-weight: 500; 
 
    top: 210px; 
 
} 
 
#button { 
 
    width: 200px; 
 
    height: 46px; 
 
    line-height: 46px; 
 
    padding: 0px 24px; 
 
    display: inline-block; 
 
    background-color: #1a75ff; 
 
    color: #fff; 
 
    font-family: 'Raleway', sans-serif; 
 
    font-weight: 600; 
 
    text-transform: uppercase; 
 
    -webkit-box-shadow: inset 0px -2px rgba(0, 0, 0, 0.22); 
 
    box-shadow: inset 0px -2px rgba(0, 0, 0, 0.22); 
 
    -webkit-border-radius: 4px; 
 
    border-radius: 4px; 
 
    cursor: pointer; 
 
    text-decoration: none; 
 
    top: 335px; 
 
    left: 825px; 
 
    text-align: center; 
 
}
<header> 
 
    <div class="relative"> 
 
    <img id="headerimage" src="http://i.imgur.com/iiE3pbP.jpg" /> 
 
    <p class="absolute-text" id="fontStyle">Reliable Web Hosting</p> 
 
    <p class="absolute-text" id="fontStyle2" href="contact.html">We offer quality and reliable web hosting at <br> low prices that you'll not want to miss.</p> 
 
    <a class="absolute-text" id="button" href="">Order Web Hosting</a> 
 
    </div> 
 
</header>

回答

0

您可以使用%的響應

<div class="relative"> 
    <img id="headerimage" src="http://i.imgur.com/iiE3pbP.jpg" width="100%" /> 
    <p class="absolute-text" id="fontStyle">Reliable Web Hosting</p> 
    <p class="absolute-text" id="fontStyle2" href="contact.html">We offer quality and reliable web hosting at <br> low prices that you'll not want to miss.</p> 
    <p class="button_center"><a class="absolute-text" id="button" href="">Order Web Hosting</a></p> 
</div> 

    <style> 
    .relative{ 
    position:relative; 
    width:100%; 
} 

.absolute-text { 
    color: white; 
    position:absolute; 
    bottom:0; 
    top: 4%; 
    width:100%; 
    text-align:center; 
    font-family: 'Raleway', sans-serif; 
} 

#fontStyle { 
    font-weight: 700; 
    font-size: 48px; 
} 

#fontStyle2 { 
    font-size: 25px; 
    text-decoration: none; 
    font-weight: 500; 
    top: 30%; 
} 

.button_center{ 
text-align:center; 
} 

#button { 
    width: 200px; 
    margin-left: -130px; 
    height: 46px; 
    line-height: 46px; 
    padding: 0px 24px; 
    display: inline-block; 
    background-color: #1a75ff; 
    color: #fff; 
    font-family: 'Raleway', sans-serif; 
    font-weight: 600; 
    text-transform: uppercase; 
    -webkit-box-shadow: inset 0px -2px rgba(0, 0, 0, 0.22); 
    box-shadow: inset 0px -2px rgba(0, 0, 0, 0.22); 
    -webkit-border-radius: 4px; 
    border-radius: 4px; 
    cursor: pointer; 
    text-decoration: none; 
    top: 60%; 
    text-align: center; 
    } 

    </style> 

最好的變種 - 你可以把圖像中<div style="background:url() >而不是用 '絕對'

===================嘗試

<p class="button_center"><a class="absolute-text" id="button" href="">Order Web Hosting</a></p> 

.button_center{ 
text-align:center; 
position: absolute; 
left: 50%; 
    top: 60%; 
} 

#button { 
    width: 200px; 
    height: 46px; 
    line-height: 46px; 
    padding: 0px 24px; 
    display: inline-block; 
    background-color: #1a75ff; 
    color: #fff; 
    font-family: 'Raleway', sans-serif; 
    font-weight: 600; 
    text-transform: uppercase; 
    -webkit-box-shadow: inset 0px -2px rgba(0, 0, 0, 0.22); 
    box-shadow: inset 0px -2px rgba(0, 0, 0, 0.22); 
    -webkit-border-radius: 4px; 
    border-radius: 4px; 
    cursor: pointer; 
    text-decoration: none; 
    left:40%; 
    text-align: center; 

    position: relative; 
    left: -50%; 
    } 
+0

好。我得到了按鈕,但現在,當我調整窗口的大小時,它會略微移動,您可以在這裏看到:https://www.youtube.com/watch?v=wScTTf2unqQ&feature=youtu.be感謝您的幫助至此 – killerwild

+0

您不正確的響應測試..讓我們在brouser中使用F12,並找到按鈕 - >(FF)'響應式設計模式'或(鉻)'切換設計工具欄' –

+0

我同意@OlegBorodko圖像應該是背景圖像的一個div,而不是使用'絕對'。如果沒有絕對的話,你的反應速度會更容易。 – Wes