フォローボタンと広告をサイドバーに固定する方法
フォローボタンと広告をサイドバーに固定してみました。
コピペだけでサイドバーに固定する方法
一番下のモジュールを固定できます。リンク先のように複数固定したい場合は、一つのモジュールの中にHTMLで
複数記述しましょう。
レスポンシブデザインのときに表示をなくす方法
http://www.turetiru.com/entry/2016/02/17/%E3%81%AF%E3%81%A6%E3%81%AA%E3%83%96%E3%83%AD%E3%82%B0%E3%81%A7%E3%82%B5%E3%82%A4%E3%83%89%E3%83%90%E3%83%BC%E5%9B%BA%E5%AE%9A%E3%82%92%E3%82%B9%E3%83%9E%E3%83%9B%E6%99%82%E3%81%ABwww.turetiru.com
この設定をしないで、表示幅を狭くしてカラムを1つにすると表示がおかしくなります。
この設定をすると、カラムが1つになったときに表示が消えてくれます。
スマホの表示も消えてくれましたが最後までスクロールすると画面が少しだけガチャガチャしてしまう謎は残ってしまった。。
サンプルコード
HTML
サイドバーの最後のモジュールに追加したHTMLをそのままのせておきます。
後半の広告のコードは伏せています。
<div class="follow"> <link rel="stylesheet" href="https://rawgit.com/aloerina01/follow-buttons/master/icomoon/style.css"> <div class="follow-buttons"> <div class="follow-button follow-button-blog"> <div class="follow-button-inner follow-button-inner-blog" onClick="blog();"> <i class="icon blogicon-hatenablog"></i> <span class="tooltip tooltip-feedly">読者になる</span> </div> </div> <div class="follow-button follow-button-twitter"> <div class="follow-button-inner follow-button-inner-twitter" onClick="twitter();"> <i class="icon fa fa-twitter"></i> <span class="tooltip tooltip-twitter">Twitterをフォロー</span> </div> </div> <div class="follow-button follow-button-github"> <div class="follow-button-inner follow-button-inner-github" onClick="github();"> <i class="icon fa fa-github"></i> <span class="tooltip tooltip-github">GitHubをフォロー</span> </div> </div> </div> <script> function blog() { window.open('http://blog.hatena.ne.jp/yamano3201/yamano3201.hatenablog.jp/subscribe'); }; function twitter() { window.open('https://twitter.com/intent/follow?screen_name=yamano3201'); }; function github() { window.open('https://github.com/yamano'); }; </script> <!-- ここから広告コード --> <script async src="//xxxxxxxxxxxxxxxxxxxxx/adsbygoogle.js"></script> <!-- blog-side --> <ins class="adsbygoogle" style="display:block" data-ad-client="xxxxxxxxxxxxxx" data-ad-slot="xxxxxxxxxxxx" data-ad-format="auto"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div>
css
フォローボタンのcssです。
フォローボタンと広告がくっついてしまったので、元のcssにpadding : 0px 0px 40px 0px を追加しています。
.display-none { display: none !important; } .follow-buttons { display: flex; justify-content: space-around; align-items: center; position: relative; width: 100%; padding : 0px 0px 40px 0px; } .follow-buttons .follow-button { position: relative; width: 25%; max-width: 65px; min-width: 54px; } .follow-buttons .follow-button:before { padding-top: 100%; display: block; content: ""; } .follow-buttons .follow-button-inner { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; text-align: center; border: 2px solid #7f7f7f; border-radius: 50%; transition: all 0.4s ease; cursor: pointer; } .follow-buttons .follow-button-inner .icon { font-size: 32px; } .follow-buttons .follow-button-inner-blog { border-color: #78909c; color: #78909c; background-color: #ffffff; } .follow-buttons .follow-button-inner-blog:hover { background-color: #78909c; color: #ffffff; } .follow-buttons .follow-button-inner-twitter { border-color: #29b6f6; color: #29b6f6; background-color: #ffffff; } .follow-buttons .follow-button-inner-twitter:hover { background-color: #29b6f6; color: #ffffff; } .follow-buttons .follow-button-inner-github { border-color: #B083DF; color: #B083DF; background-color: #ffffff; } .follow-buttons .follow-button-inner-github:hover { background-color: #B083DF; color: #ffffff; } .follow-buttons .follow-button-inner-feedly { border-color: #66bb6a; color: #66bb6a; background-color: #ffffff; } .follow-buttons .follow-button-inner-feedly:hover { background-color: #66bb6a; color: #ffffff; } .follow-buttons .follow-button-inner .tooltip { display: none; position: absolute; width: 100px; left: 50%; top: 110%; opacity: 0; background-color: #263238; color: #ffffff; font-size: 0.6rem; text-align: center; border-radius: 4px; padding: 6px; -webkit-transform: translate(-50%, 0); -moz-transform: translate(-50%, 0); -ms-transform: translate(-50%, 0); -o-transform: translate(-50%, 0); transform: translate(-50%, 0); } .follow-buttons .follow-button-inner:hover .tooltip { display: block; animation-name: fade-in; -moz-animation-name: fade-in; -webkit-animation-name: fade-in; animation-duration: 0.4s; animation-delay: 0.4s; -moz-animation-duration: 0.4s; -moz-animation-delay: 0.4s; -webkit-animation-duration: 0.4s; -webkit-animation-delay: 0.4s; animation-fill-mode: forwards; -moz-animation-fill-mode: forwards; -webkit-animation-fill-mode: forwards; } @keyframes fade-in { 0% { display: none; opacity: 0; } 1% { display: block; opacity: 0; } 100% { display: block; opacity: 1; } } @-moz-keyframes fade-in { 0% { display: none; opacity: 0; } 1% { display: block; opacity: 0; } 100% { display: block; opacity: 1; } } @-webkit-keyframes fade-in { 0% { display: none; opacity: 0; } 1% { display: block; opacity: 0; } }
レスポンシブデザインのときに表示をなくすcssです。
@media screen and (max-width:968px){ .follow{ display: none; } }
最後に
これでフォローボタンと広告がサイドバーに固定して表示されるようになりました。
気が向いたら、また書きます。