ようこそここは俺のチラシの裏だ。

専門学校卒のぽんこつえんじにあが個人事業主になって書いているただの日記。

ブログ改造計画(カスタムCSS修正)[スマホ向け修正追記]

(*'▽') 見栄え、大事!!

f:id:sugaryo1224:20170902100056j:plain

カスタムCSS(全文掲載)

/* <system section="theme" selected="reach"> */
@import "/css/theme/reach/reach.css";
/* </system> */

/* <system section="background" selected="383838"> */
body{background:#383838;}
/* </system> */

/* ------------------------- */
/* テーマ補正:ページトップの見切れ */
#container {
    padding-top: 32px;
}
/* テーマ補正:記事のフォント指定 */
div.entry-content {
  font-family: "メイリオ",sans-serif;
}


/* ------------------------- */
/* ヘッダの補正 */
#top-editarea {
  padding: 10px;
}
#top-editarea > p {
  margin: 0px;
  padding: 1px 16px;
}


/* 記事見出しの設定 */
.entry-content h2,
.entry-content h3,
.entry-content h4,
.entry-content h5 {
  padding: 5px;
}
.entry-content h3 {
  color: white;
  background-color: #646464;
  padding: 8px 16px;
  border-radius: 5px;
}
.entry-content h4 {
  border-left:   8px solid #338dff;
  border-bottom: 1px solid #338dff;
}

.entry-content h5 {
  position: relative;
  border-bottom: 3px solid #ccc;
  padding: 8px 10px;
}
.entry-content h5::before {
  position: absolute;
  top: 100%;
  left: 0;
  width: 25%;
  height: 3px;
  background-color: #338dff;
  z-index: 2;
  content: '';
}


/* ------------------------- */
/* 表 */
div.entry-content > table {
  width: 100%;
}

/* ------------------------- */
/* 画像 */
.entry-content img {
  border: thin solid gray;
  max-width: 80%;
  display: block;
  margin: 10px auto;
}


/* ------------------------- */
/*share-botton*/
.share-buttons{
    margin-bottom: 10px;
    text-align: center;
}
.share-buttons .inner a {
    position: relative;
    display: inline-block;
    width: 12%;
    height: 45px;
    line-height: 25px;
    font-size: 16px;
    text-align: center;
    text-decoration: none;
    padding: 5px;
    margin: 5px 2px;
}
.share-buttons .inner .share-text{
    font-size: 15px;
}
.share-buttons .inner .hatena-bookmark-button{
    color:#008fde;
    border:1px solid #008fde;
    background: #fff;
}
.share-buttons .inner .hatena-bookmark-button:hover{
    color:#fff;
    background: #008fde;
}
.share-buttons .inner .hatena-bookmark-button:active{
    background: #5478A5;
}
.share-buttons .inner .facebook-button{
    color:#305097;
    border:1px solid #305097;
    background: #fff;
}
.share-buttons .inner .facebook-button:hover{
    color:#fff;
    background: #305097;
}
.share-buttons .inner .facebook-button:active{
    background: #213254;
}
.share-buttons .inner .twitter-button{
    color:#55acee;
    border:1px solid #55acee;
    background: #fff;
}
.share-buttons .inner .twitter-button:hover{
    color:#fff;
    background: #55acee;
}
.share-buttons .inner .twitter-button:active{
    background: #0285b7;
}
.share-buttons .inner .googleplus-button{
    color:#db4a39;
    border:1px solid #db4a39;
    background: #fff;
}
.share-buttons .inner .googleplus-button:hover{
    color:#fff;
    background: #db4a39;
}
.share-buttons .inner .googleplus-button:active{
    background: #a23629;
}
.share-buttons .inner .pocket-button{
    color:#d3505a;
    border:1px solid #d3505a;
    background: #fff;
}
.share-buttons .inner .pocket-button:hover{
    color:#fff;
    background: #d3505a;
}
.share-buttons .inner .pocket-button:active{
    background: #b5392c;
}

今回の改善ポイント

改善したかった点

  • 画像imageを中央揃えにするのにイチイチcenterタグを打ってたのがダルい。
  • 画像imageが横幅いっぱいに広がって、スクショのような縦長画像だとデカすぎる。
  • tableも間に合わせで横幅いっぱいに広げてたので、画像とあわせて修正したい。

基本的にはこんな感じ。

画像に対する変更点

※後述「追記」の通り、スマホでレイアウト崩れを起こしてたのでこの方法は修正しました。

変更前:

/* ------------------------- */
/* 画像 */
.entry-content img {
  border: thin solid gray;
}

変更後:

/* ------------------------- */
/* 画像 */
.entry-content img {
  border: thin solid gray;
  max-width: 80%;
  margin: 10px 10%;
}

もともと枠線付けるだけだったけど、max-widthとmarginの指定を追加。

最大幅を80%に指定し、マージンを左右10%ずつに指定して、大きな画像を最大八割で表示しつつ疑似的に中央揃えに。

表に対する変更点

変更前:

/* ------------------------- */
/* 表 */
div.entry-content > table {
  width: 100%;
}

変更後:

/* ------------------------- */
/* 表 */
div.entry-content > table {
  width: 80%;
  margin: 10px 10%;
}

元々は幅100%指定だけだったのを、画像と同じように変更。

ついでにソーシャルシェアボタンも変更

/* ------------------------- */
/*share-botton*/
.share-buttons{
    margin-bottom: 10px;
    text-align: center;
}
.share-buttons .inner a {
    position: relative;
    display: inline-block;
    width: 12%;
    height: 45px;
    line-height: 25px;
    font-size: 16px;
    text-align: center;
    text-decoration: none;
    padding: 5px;
    margin: 5px 2px;
}

幅を12%に減らし、上下5px,左右2pxのマージン指定を追加。

追記

これでいいやと思ってたけど、どうやらスマホで見た時に画像が思いっきりズレるようになったみたい。

修正しなきゃ><

という事で修正しました。(上の「全文掲載」の方もあわせて修正済み)

/* ------------------------- */
/* 表 */
div.entry-content > table {
  width: 100%;
}

/* ------------------------- */
/* 画像 */
.entry-content img {
  border: thin solid gray;
  max-width: 80%;
  display: block;
  margin: 10px auto;
}

画像に関しては、ブロック要素にしつつmargin autoを指定するパターンに変更。

表はスマホだともう仕方ない(どう足掻いても大きな表は見辛いし、CSSだけでは調整するのに限界がある)ので、横幅100%指定に戻しました。

しかし、単一CSSでPCとスマホの両対応って難しいなぁ、、、。

ブログ改造計画のばっくなんばー。

第一回

sugaryo1224.hatenablog.com

第二回

sugaryo1224.hatenablog.com

第三回

sugaryo1224.hatenablog.com

おまけ

sugaryo1224.hatenablog.com