2
我試圖將我的「tweet」按鈕放在我的「生成報價」按鈕旁邊,但由於某些原因,css無法正常工作。我嘗試使用top: 50%
,margin-top: 50%
,將它放置在「引號」div下的另一個div中,使用#作爲目標,但它仍停留在左上角。可能是什麼原因?使用CSS和Bootstrap定位按鈕
https://codepen.io/s4ek1389/pen/zZGNWw?editors=1100
HTML
<head>
<link href="https://fonts.googleapis.com/css?family=Comfortaa" rel="stylesheet">
</head>
<div class="main">
<div id="quote">
<h1>There is nothing either good or bad, but thinking makes it so.</h1>
<h4>William Shakespeare</h4>
</div>
<div class="containter">
<div class="row">
<button type="button", class="btn btn-primary", id="gen"> Generate Quote!
</button>
<a href="https://twitter.com/share" class="twitter-share-button" data-size="large" data-show-count="false" id="tw">Tweet</a>
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
</div>
</div>
</div>
CSS
.main {
background-image:url("http://wallpapercave.com/wp/mVcZwOP.jpg");
background-size:cover;
min-height: 640px;
margin: 0 auto;
position:relative;
width:100%;
max-width:1680px;
}
#quote {
text-align:center;
width:70%;
}
h1 {
position: absolute;
top: 30%;
font-size:5vw;
background-color:rgba(173, 29, 125, 0.5);
color:white;
font-family: "Comfortaa", cursive;
text-align:center;
display:block;
}
h4 {
top:60%;
font-size:3vw;
background-color:rgba(173, 29, 125, 0.5);
color:white;
font-family: "Comfortaa", cursive;
position:absolute;
display:inline-block;
}
#gen {
top:80%;
position: absolute;
left:42%;
display:inline;
}
#tw {
top:50%;
position:absolute;
margin-top:50%;
}
非常感謝。現在一切正常。我也嘗試使用#twitter-widget-0,我也可以定位按鈕。但我不明白你在哪裏找到這個ID的名字。 –
@IgorSchekotihin np。要找到ID,請使用您的開發工具並在元素創建後檢查它。 –