搜索

首页  >  问答  >  正文

如何使标题在媒体尺寸中居中?

我想放置一个以常规尺寸居中的媒体尺寸,当我将其最大宽度更改为 480 时,标题位于左侧。

但它粘在左边。如何更改代码,使标题在媒体大小时位于中间?

caption {
   font-family: "Rock Salt", cursive;
   padding: 20px;
   font-style: italic;
   caption-side: Top;
   color: #666;
   text-align: center;
   letter-spacing: 1px;
 }




@media only screen and (max-width: 480px) {
  caption {
    caption-side: Top;
    text-align: center;
    letter-spacing: 1px;
  }
<section id="right"> 
        <table> 
           <caption>Books everyone will enjoy!</caption> 
           <thead> 
              <th colspan="4">Recommended childrens books!</th> 
              <th colspan="2" style="display: none">Recommended childrens books!</th> 
              <tr> 
                 <th colspan="1">Front of the book</th> 
                 <th colspan="1">Title of the book</th> 
                 <th colspan="1">Authors</th> 
                 <th colspan="1">Book Summary</th> 
             </tr> 
           </thead>

P粉316110779P粉316110779312 天前452

全部回复(1)我来回复

  • P粉239089443

    P粉2390894432024-02-27 00:57:01

    您需要将块元素居中:

    @media only screen and (max-width: 480px) {
       caption {
          caption-side: Top;
          text-align: center;
          letter-spacing: 1px;
          margin:0 auto;
    }

    回复
    0
  • 取消回复