wordpress自作テーマ内で画像にリンクをつけたくimgをaタグで囲んだのですが、指定した幅になってくれません。
以前はimgに親要素の33%の幅指定をしていたのですがaタグにこの幅を指定しても画像ごとにサイズが変わってしまいます。
また、img自体にはwidth:100%を指定して横縦100%にしているのですがaタグで囲むと縦幅が100%から変わってしまいます。
これ自体はheightで100%の指定をする直るのですが、今までwidthの指定のみで縦幅も動いていたのに釈然としません。
添付画像のように親要素の33%の幅をキープしたまま画像にリンクを貼りたいです。
どたなかよろしくお願いします。
PHP
1<?php get_header(); ?> 2 3 4 5 6 7<!--ページ上部にスクロールするボタン 8 <p id="pageTop"><a href="#"><i class="fa fa-chevron-up"></i></a></p> 9--> 10 11 12<div class="sp-newarticle"> 13 <p>新着記事</p> 14</div> 15 16 17<div class="main"> 18 19 <div class="articles"> 20 <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> 21 <article class="article"> 22 <a class="link-img" href="#"><img class="article-img" src="<?php echo catch_that_image(); ?>"></a> 23 24 <div class="article-right"> 25 <header> 26 <h2 class="article-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 27 <section> 28 <div class="section-header"> 29 30 31 <ul class="article-genre"> 32 <li><time><i class="far fa-clock"></i><?php the_time('Y/m/d'); ?></time></li> 33   34 <li><a href="#"><i class="fas fa-tag"></i><?php the_category(' '); ?></a></li> 35 <li class="article-tag"><a href="#"><?php the_tags( '', ' , ' ); ?></a></li> 36 </ul> 37 </div> 38 </section> 39 40 </header> 41 42<section class="article-text"> 43 <p> <?php the_excerpt(); ?> 44</p> 45</section> 46<footer> 47 <a class="read-more-sp" href="<?php the_permalink(); ?>">...記事を読む</a> 48 <a class="read-more" href="<?php the_permalink(); ?>">続きを読む</a> 49</footer> 50 </div> 51 52 </article> 53 <?php 54 endwhile; 55 endif; 56 ?> 57 </div> 58 59<?php get_sidebar(); ?> 60</div> 61 62 63 64 <?php 65 //Pagenation 66 if (function_exists("pagination")) { 67 pagination($additional_loop->max_num_pages); 68 } 69 ?> 70 71<div class="mobile-search"> 72 <p class="mobile-search-title">サイト内検索</p> 73 <?php get_search_form(); ?> 74</div> 75 76<aside id="mobile-rank"><?php dynamic_sidebar( 'side-widget2' ); ?></aside> 77 </div> 78 79<?php get_footer(); ?>
css
1@charset "UTF-8"; 2/* 3html5doctor.com Reset Stylesheet 4v1.6.1 5Last Updated: 2010-09-17 6Author: Richard Clark - http://richclarkdesign.com 7Twitter: @rich_clark 8*/ 9html, body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, abbr, address, cite, code, del, dfn, em, img, ins, kbd, q, samp, small, strong, sub, sup, var, b, i, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, figcaption, figure, footer, header, hgroup, menu, nav, section, summary, time, mark, audio, video { margin: 0; padding: 0; border: 0; outline: 0; font-size: 100%; vertical-align: baseline; background: transparent; } 10 11body { line-height: 1.4; } 12 13article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section { display: block; } 14 15nav ul { list-style: none; } 16 17blockquote, q { quotes: none; } 18 19blockquote:before, blockquote:after, q:before, q:after { content: ''; content: none; } 20 21a { margin: 0; padding: 0; font-size: 100%; vertical-align: baseline; background: transparent; } 22 23/* change colours to suit your needs */ 24ins { background-color: #ff9; color: #000; text-decoration: none; } 25 26/* change colours to suit your needs */ 27mark { background-color: #ff9; color: #000; font-style: italic; font-weight: bold; } 28 29del { text-decoration: line-through; } 30 31abbr[title], dfn[title] { border-bottom: 1px dotted; cursor: help; } 32 33table { border-collapse: collapse; border-spacing: 0; } 34 35/* change border colour to suit your needs */ 36hr { display: block; height: 1px; border: 0; border-top: 1px solid #cccccc; margin: 1em 0; padding: 0; } 37 38input, select { vertical-align: middle; } 39 40* { margin: 0; padding: 0; box-sizing: border-box; } 41 42p { font-family: "ヒラギノ角ゴ Pro W3", "Hiragino Kaku Gothic Pro", "メイリオ", Meiryo, Osaka, "MS Pゴシック", "MS PGothic", sans-serif !important; } 43 44img { height: auto; width: auto; max-height: 100%; max-width: 100%; vertical-align: middle; } 45 46a { text-decoration: none; } 47 48li { list-style: none; } 49 50.container { width: 100%; padding-top: 10px; max-width: 1170px; background-color: #ECF0F3; padding-right: 20px; padding-left: 20px; margin-right: auto; margin-left: auto; } 51 52@media screen and (max-width: 779px) { .container { padding: 5px; } } 53 54.sp-logo { display: none; } 55 56@media screen and (max-width: 568px) { .sp-logo { display: block; } 57 .pc-logo { display: none; } } 58 59.header { background-color: #ECF0F3; text-align: center; line-height: 140px; height: 140px; position: relative; } 60 61.heade-rabel { padding: 0 12%; height: 60px; background-color: #232323; display: flex; align-items: center; } 62 63.heade-rabel a { font-size: 18px; font-weight: 600; color: white; } 64 65.subtitle { font-size: 11px; } 66 67.header-right { margin: 0 0 0 auto; } 68 69.header-link:nth-of-type(2) { padding: 0 85px; } 70 71@media screen and (max-width: 1400px) { .header-link:nth-of-type(2) { padding: 0 25px; } } 72 73.page { background-color: #ECF0F3; } 74 75.top-btn { display: flex; justify-content: space-between; margin-bottom: 20px; } 76 77@media screen and (max-width: 568px) { .top-btn { display: none; } } 78 79.Genre-btn { color: white; font-size: 18px; font-weight: 600; text-decoration: none; border: 1px solid #333; border-radius: 5px; background-color: rgba(0, 0, 0, 0.2); box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5); width: 163px; height: 50px; display: flex; align-items: center; justify-content: center; } 80 81@media screen and (min-width: 569px) and (max-width: 779px) { .heade-rabel { height: 40px; padding: 0 10%; } 82 .heade-rabel a { font-size: 14px; } } 83 84@media screen and (min-width: 780px) and (max-width: 1023px) { .heade-rabel { height: 50px; } 85 .heade-rabel a { font-size: 16px; } 86 .Genre-btn { font-size: 16px; width: 143px; height: 40px; } } 87 88@media screen and (max-width: 568px) { .heade-rabel { display: none; } } 89 90.main { display: flex; } 91 92.articles { max-width: 850px; flex: 1 1 auto; } 93 94.article { max-width: 850px; height: 190px; padding: 15px; display: flex; background-color: #FFFFFF; border-radius: 3px; box-shadow: 0 0 20px rgba(0, 0, 0, 0.2); margin-bottom: 20px; position: relative; } 95 96.link-img { width: 33%; margin-right: 20px; } 97 98.article-img { width: 100%; height: 100%; } 99 100.article-title { border-bottom: #aaaaaa solid 1px; font-size: 20px; font-weight: 600; } 101 102h2 a { color: #666; } 103 104time { font-size: 14px; font-weight: 600; color: #666; } 105 106.section-header { display: flex; font-size: 14px; font-weight: 600; margin-top: 5px; } 107 108.article-genre li { display: inline; list-style: none; } 109 110.article-genre a { color: #666; } 111 112.article-text { margin: 15px 0 5px; font-size: 12px; } 113 114.read-more { background-color: #566170; border: none; border-radius: 10px; padding: 5px 30px 5px; color: #fff; font-weight: 600; font-size: 13px; position: absolute; right: 15px; bottom: 15px; } 115 116.read-more-sp { display: none; color: #666; font-size: 10px; position: absolute; right: 15px; bottom: 5px; } 117 118.sp-newarticle { display: none; font-size: 11px; border-left: 2px solid #1613b4; border-bottom: 2px solid #6476ee; background-color: #f9f9f9; padding: 5px; margin-bottom: 10px; font-weight: 600; } 119 120@media screen and (min-width: 569px) and (max-width: 779px) { .article { height: auto; padding: 5px; } 121 .article-title { font-size: 14px; } 122 time { font-size: 10px; } 123 .article-genre { font-size: 10px; } 124 .article-tag { display: none; } 125 .read-more { display: none; } 126 .article-text { display: none; } } 127 128@media screen and (min-width: 780px) and (max-width: 1023px) { .article-title { font-size: 16px; } 129 time { font-size: 12px; } 130 .article-genre { font-size: 12px; } 131 .article-tag { display: none; } } 132 133@media screen and (max-width: 568px) { .sp-newarticle { display: block; } 134 .article-title { font-size: 10px; } 135 time { font-size: 10px; } 136 .article-genre { font-size: 10px; } 137 .article-tag { display: none; } 138 .article-text { display: none; } 139 .article { height: auto; padding: 5px; } 140 .read-more { display: none; } 141 .read-more-sp { display: block; } 142 .article-img { width: 33%; height: 100px; margin-right: 5px; } } 143
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/11/22 16:53
2020/11/22 17:27
2020/11/22 19:09