管理画面のビジュアルエディタと、フロントの見た目の違い、また、reset.cssなどにより影響がでて、装飾しにくいことが多いため、投稿用のCSSを準備しておくと、修正しやすい。
投稿ページは、クライアントが入力するため、見た目などは装飾する技術がなく、ビジュアルエディタを使用することがあるため、なるべくビジュアルエディタと同じ見た目で表示してあげることを努力する。
ネット上では、ビジュアルエディタ側の見た目をフロント側の見た目に寄せる方法が多いが、ビジュアルエディタで追加させるクラス群を別途準備しなければならないので、ここではeditor-style.cssをカスタムして、フロント側の見た目をビジュアルエディタ側に寄せる方法を推奨とする。
editor-style.cssを.post-contentクラスのdiv内のみで適応されるように調整したものが以下のCSS。
いらない部分は独自で削除して、post.cssなどの名前のcssファイルを作成して読み込む。
/** * 1.0 Body * ---------------------------------------------------------------------------- */ .post-content html .mceContentBody { font-size: 100%; max-width: 474px; } .post-content body { color: #2b2b2b; font-family: Lato, sans-serif; font-weight: 400; line-height: 1.5; vertical-align: baseline; } /** * 2.0 Headings * ---------------------------------------------------------------------------- */ .post-content h1, .post-content h2, .post-content h3, .post-content h4, .post-content h5, .post-content h6 { clear: both; font-weight: 700; margin: 36px 0 12px; } .post-content h1 { font-size: 26px; line-height: 1.3846153846; } .post-content h2 { font-size: 24px; line-height: 1; } .post-content h3 { font-size: 22px; line-height: 1.0909090909; } .post-content h4 { font-size: 20px; line-height: 1.2; } .post-content h5 { font-size: 18px; line-height: 1.3333333333; } .post-content h6 { font-size: 16px; line-height: 1.5; } .post-content h1:first-child, .post-content h2:first-child, .post-content h3:first-child, .post-content h4:first-child, .post-content h5:first-child, .post-content h6:first-child { margin-top: 0; } /** * 3.0 Text Elements * ---------------------------------------------------------------------------- */ .post-content address { font-style: italic; margin-bottom: 24px; } .post-content abbr[title] { border-bottom: 1px dotted #2b2b2b; cursor: help; } .post-content b, .post-content strong { font-weight: 700; } .post-content cite { border: 0; } .post-content cite, .post-content dfn, .post-content em, .post-content i { font-style: italic; } .post-content mark, .post-content ins { background: #fff9c0; border: 0; color: inherit; text-decoration: none; } .post-content p { margin: 0 0 24px; } .post-content code, .post-content kbd, .post-content tt, .post-content var, .post-content samp, .post-content pre { font-family: monospace, serif; font-size: 15px; line-height: 1.6; } .post-content pre { border: 1px solid rgba(0, 0, 0, 0.1); margin-bottom: 24px; max-width: 100%; overflow: auto; padding: 12px; white-space: pre; white-space: pre-wrap; word-wrap: break-word; } .post-content blockquote, .post-content q { quotes: none; } .post-content blockquote:before, .post-content blockquote:after, .post-content q:before, .post-content q:after { content: ""; content: none; } .post-content blockquote { color: #767676; font-size: 19px; font-style: italic; font-weight: 300; line-height: 1.2631578947; margin: 0 0 24px; } .post-content blockquote cite, .post-content blockquote small { color: #2b2b2b; font-size: 16px; font-weight: 400; line-height: 1.5; } .post-content blockquote em, .post-content blockquote i, .post-content blockquote cite { font-style: normal; } .post-content blockquote strong, .post-content blockquote b { font-weight: 400; } .post-content small { font-size: smaller; } .post-content big { font-size: 125%; } .post-content sup, .post-content sub { font-size: 75%; height: 0; line-height: 0; position: relative; vertical-align: baseline; } .post-content sup { bottom: 1ex; } .post-content sub { top: .5ex; } .post-content dl { margin: 0 0 24px; } .post-content dt { font-weight: bold; } .post-content dd { margin: 0 0 24px; } .post-content ul, .post-content ol { list-style: none; margin: 0 0 24px 20px; padding-left: 0; } .post-content ul { list-style: disc; } .post-content ol { list-style: decimal; } .post-content li > ul, .post-content li > ol { margin: 0 0 0 20px; } .post-content del { color: #767676; } .post-content hr { background-color: rgba(0, 0, 0, 0.1); border: 0; height: 1px; margin-bottom: 23px; } /** * 4.0 Links * ---------------------------------------------------------------------------- */ .post-content a { color: #24890d; text-decoration: none; } .post-content a:visited { color: #24890d; } .post-content a:focus { outline: thin dotted; } .post-content a:active, .post-content a:hover { color: #41a62a; outline: 0; } /** * 5.0 Alignment * ---------------------------------------------------------------------------- */ .post-content .alignleft { float: left; margin: 7px 24px 7px 0; } .post-content .alignright { float: right; margin: 7px 0 7px 24px; } .post-content .aligncenter { clear: both; display: block; margin: 7px auto; } .post-content blockquote.alignleft, .post-content blockquote.alignright { border-top: 1px solid rgba(0, 0, 0, 0.1); border-bottom: 1px solid rgba(0, 0, 0, 0.1); padding-top: 17px; width: 50%; } .post-content blockquote.alignleft p, .post-content blockquote.alignright p { margin-bottom: 17px; } /** * 6.0 Tables * ---------------------------------------------------------------------------- */ .post-content .mceItemTable { border: 1px solid rgba(0, 0, 0, 0.1); border-width: 1px 0 0 1px; border-collapse: separate; border-spacing: 0; font-size: 14px; line-height: 1.2857142857; margin-bottom: 24px; width: 100%; } .post-content .mceItemTable th, .post-content .mceItemTable caption { border: 1px solid rgba(0, 0, 0, 0.1); border-width: 0 1px 1px 0; font-weight: 700; padding: 8px; text-align: left; text-transform: uppercase; vertical-align: baseline; } .post-content .mceItemTable td { border: 1px solid rgba(0, 0, 0, 0.1); border-width: 0 1px 1px 0; font-family: Lato, sans-serif; font-size: 14px; padding: 8px; vertical-align: baseline; } /** * 7.0 Images * ---------------------------------------------------------------------------- */ .post-content img { height: auto; width: auto; max-width: 100%; /*max-width: 474px;*/ vertical-align: middle; } .post-content .wp-caption { background: transparent; border: none; color: #767676; margin: 0 0 24px 0; max-width: 474px; padding: 0; text-align: left; } .post-content .html5-captions .wp-caption { padding: 0; } .post-content .wp-caption.alignleft { margin: 7px 14px 7px 0; } .post-content .html5-captions .wp-caption.alignleft { margin-right: 24px; } .post-content .wp-caption.alignright { margin: 7px 0 7px 14px; } .post-content .wp-caption.alignright img, .post-content .wp-caption.alignright .wp-caption-dd { padding-left: 10px; } .post-content .html5-captions .wp-caption.alignright { margin-left: 24px; } .post-content .html5-captions .wp-caption.alignright img, .post-content .html5-captions .wp-caption.alignright .wp-caption-dd { padding: 0; } .post-content .wp-caption.aligncenter { margin: 7px auto; } .post-content .wp-caption-dt { margin: 0; } .post-content .wp-caption .wp-caption-text, .post-content .wp-caption-dd { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; font-size: 12px; font-style: italic; line-height: 1.5; margin: 9px 0; padding: 0 10px 0 0; /* Avoid the caption to overflow the width of the image because wp-caption has 10px wider width */ text-align: left; } .post-content .mceTemp + ul, .post-content .mceTemp + ol { list-style-position: inside; } /** * 8.0 Gallery * ----------------------------------------------------------------------------- */ .post-content .gallery .gallery-item { float: left; margin: 0 4px 4px 0; overflow: hidden; padding: 0; position: relative; } .post-content .gallery-columns-1 .gallery-item { max-width: 100%; width: auto; } .post-content .gallery-columns-2 .gallery-item { max-width: 48%; max-width: -webkit-calc(50% - 14px); max-width: calc(50% - 14px); width: auto; } .post-content .gallery-columns-3 .gallery-item { max-width: 32%; max-width: -webkit-calc(33.3% - 11px); max-width: calc(33.3% - 11px); width: auto; } .post-content .gallery-columns-4 .gallery-item { max-width: 23%; max-width: -webkit-calc(25% - 9px); max-width: calc(25% - 9px); width: auto; } .post-content .gallery-columns-5 .gallery-item { max-width: 19%; max-width: -webkit-calc(20% - 8px); max-width: calc(20% - 8px); width: auto; } .post-content .gallery-columns-6 .gallery-item { max-width: 15%; max-width: -webkit-calc(16.7% - 7px); max-width: calc(16.7% - 7px); width: auto; } .post-content .gallery-columns-7 .gallery-item { max-width: 13%; max-width: -webkit-calc(14.28% - 7px); max-width: calc(14.28% - 7px); width: auto; } .post-content .gallery-columns-8 .gallery-item { max-width: 11%; max-width: -webkit-calc(12.5% - 6px); max-width: calc(12.5% - 6px); width: auto; } .post-content .gallery-columns-9 .gallery-item { max-width: 9%; max-width: -webkit-calc(11.1% - 6px); max-width: calc(11.1% - 6px); width: auto; } .post-content .gallery-columns-1 .gallery-item:nth-of-type(1n), .post-content .gallery-columns-2 .gallery-item:nth-of-type(2n), .post-content .gallery-columns-3 .gallery-item:nth-of-type(3n), .post-content .gallery-columns-4 .gallery-item:nth-of-type(4n), .post-content .gallery-columns-5 .gallery-item:nth-of-type(5n), .post-content .gallery-columns-6 .gallery-item:nth-of-type(6n), .post-content .gallery-columns-7 .gallery-item:nth-of-type(7n), .post-content .gallery-columns-8 .gallery-item:nth-of-type(8n), .post-content .gallery-columns-9 .gallery-item:nth-of-type(9n) { margin-right: 0; } .post-content .gallery-columns-1 .gallery-item:nth-of-type(1n), .post-content .gallery-columns-2 .gallery-item:nth-of-type(2n - 1), .post-content .gallery-columns-3 .gallery-item:nth-of-type(3n - 2), .post-content .gallery-columns-4 .gallery-item:nth-of-type(4n - 3), .post-content .gallery-columns-5 .gallery-item:nth-of-type(5n - 4), .post-content .gallery-columns-6 .gallery-item:nth-of-type(6n - 5), .post-content .gallery-columns-7 .gallery-item:nth-of-type(7n - 6), .post-content .gallery-columns-8 .gallery-item:nth-of-type(8n - 7), .post-content .gallery-columns-9 .gallery-item:nth-of-type(9n - 8) { margin-left: 12px; /* Compensate for the default negative margin on .gallery, which can't be changed. */ } .post-content .gallery .gallery-caption { background-color: rgba(0, 0, 0, 0.7); -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; color: #fff; font-size: 12px; line-height: 1.5; margin: 0; max-height: 50%; opacity: 0; padding: 6px 8px; position: absolute; bottom: 0; left: 0; text-align: left; width: 100%; } .post-content .gallery .gallery-caption:before { content: ""; height: 100%; min-height: 49px; position: absolute; top: 0; left: 0; width: 100%; } .post-content .gallery-item:hover .gallery-caption { opacity: 1; } .post-content .gallery-columns-7 .gallery-caption, .post-content .gallery-columns-8 .gallery-caption, .post-content .gallery-columns-9 .gallery-caption { display: none; } /** * 9.0 Audio/Video * ---------------------------------------------------------------------------- */ .post-content .mejs-mediaelement, .post-content .mejs-container .mejs-controls { background: #000; } .post-content .mejs-controls .mejs-time-rail .mejs-time-loaded, .post-content .mejs-controls .mejs-horizontal-volume-slider .mejs-horizontal-volume-current { background: #fff; } .post-content .mejs-controls .mejs-time-rail .mejs-time-current { background: #24890d; } .post-content .mejs-controls .mejs-time-rail .mejs-time-total, .post-content .mejs-controls .mejs-horizontal-volume-slider .mejs-horizontal-volume-total { background: rgba(255, 255, 255, .33); } .post-content .mejs-controls .mejs-time-rail span, .post-content .mejs-controls .mejs-horizontal-volume-slider .mejs-horizontal-volume-total, .post-content .mejs-controls .mejs-horizontal-volume-slider .mejs-horizontal-volume-current { border-radius: 0; } .post-content .mejs-overlay-loading { background: transparent; } .post-content .mejs-overlay-button { background-color: #fff; background-image: none; border-radius: 2px; box-shadow: 1px 1px 1px rgba(0,0,0,.8); color: #000; height: 36px; margin-left: -24px; width: 48px; } .post-content .mejs-overlay-button:before { -webkit-font-smoothing: antialiased; content: '\f452'; display: inline-block; font: normal 32px/1.125 Genericons; position: absolute; top: 1px; left: 10px; } .post-content .mejs-controls .mejs-button button:focus { outline: none; } .post-content .mejs-controls .mejs-button button { -webkit-font-smoothing: antialiased; background: none; color: #fff; display: inline-block; font: normal 16px/1 Genericons; } .post-content .mejs-playpause-button.mejs-play button:before { content: '\f452'; } .post-content .mejs-playpause-button.mejs-pause button:before { content: '\f448'; } .post-content .mejs-volume-button.mejs-mute button:before { content: '\f109'; font-size: 20px; position: absolute; top: -2px; left: 0; } .post-content .mejs-volume-button.mejs-unmute button:before { content: '\f109'; left: 0; position: absolute; top: 0; } .post-content .mejs-fullscreen-button button:before { content: '\f474'; } .post-content .mejs-fullscreen-button.mejs-unfullscreen button:before { content: '\f406'; } .post-content .mejs-overlay:hover .mejs-overlay-button { background-color: #24890d; color: #fff; } .post-content .mejs-controls .mejs-button button:hover { color: #41a62a; } /** * 10.0 RTL * ---------------------------------------------------------------------------- */ .post-content html .mceContentBody.rtl { direction: rtl; unicode-bidi: embed; } .post-content .rtl ol, .post-content .rtl ul { margin-left: 0; margin-right: 24px; } .post-content .rtl .wp-caption, .post-content .rtl tr th { text-align: right; } .post-content .rtl td { text-align: right; }