2017-03-15 69 views
1

我想將一些文本居中居中。我覺得這不應該是這麼困難,我很困惑它爲什麼不工作。不能在引導行中居中放置一些文本

照片(例)

enter image description here

#title_img { 
 
    background-image: url(http://cdn.playbuzz.com/cdn/UserImages/4343091c-c906-457b-b885-77675c22c92f.jpg); 
 
    height: 180px; 
 
    width: 180px; 
 
    margin: 0 auto; 
 
} 
 
#title_img_holder { 
 
    padding-top: 5%; 
 
    float: none; 
 
    margin: 0 auto; 
 
} 
 
#title_holder { 
 
    text-align: center; 
 
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" /> 
 
<div class="container-fluid" id="header_con"> 
 
    <div class="container"> 
 
    <div class="row" id="title_img_holder"> <img src="http://cdn.playbuzz.com/cdn/UserImages/4343091c-c906-457b-b885-77675c22c92f.jpg" class="mx-auto" alt="Smiley face" height="180" width="180"> </div> 
 
    <div class="row" id="title_holder"> 
 
     <h2 class="text-center">We fix screens. 
 
     <small class="text-muted">Not for free though</small> 
 
     </h2> 
 
    </div> 
 
    </div> 
 
</div>

我使用的自舉4

回答

4

的最新版本添加這個CSS:

#title_holder h2 { 
    margin: 0 auto; 
} 

(你必須居中H2其父容器內)

http://codepen.io/anon/pen/QpqQYq

+0

OMG我才意識到,我一直在編輯一個上面意外BC類似名稱XD – cosmichero2025

+0

還我必須等待3分鐘之前,我可以接受你的答案,但我將做到 – cosmichero2025

1

眼下,在.title_holderdisplay: flex是壓倒一切的<h2>的自動填寫其母公司的整個寬度的能力。一個簡單的解決方法是設置.title_holder h2 { width: 100%; },然後文本內容將居中。

#title_img { 
 
     background-image: url(http://cdn.playbuzz.com/cdn/UserImages/4343091c-c906-457b-b885-77675c22c92f.jpg); 
 
     height: 180px; 
 
     width: 180px; 
 
     margin: 0 auto; 
 
    } 
 
    
 
    #title_img_holder { 
 
     padding-top: 5%; 
 
     float: none; 
 
     margin: 0 auto; 
 
    } 
 
    
 
    #title_holder { 
 
     text-align: center; 
 
    } 
 
    
 
    #title_holder h2 { 
 
     width: 100%; 
 
    }
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/> 
 
<div class="container-fluid" id="header_con"> 
 
      <div class="container"> 
 
       <div class="row" id="title_img_holder"> <img src="http://cdn.playbuzz.com/cdn/UserImages/4343091c-c906-457b-b885-77675c22c92f.jpg" class="mx-auto" alt="Smiley face" height="180" width="180"> </div> 
 
       <div class="row" id="title_holder"> 
 
        <h2 class="text-center">We fix screens. 
 
     <small class="text-muted">Not for free though</small> 
 
    </h2> </div> 
 
      </div> 
 
     </div>

+0

我已經給他檢查的東西,但繼承人upvote,金星,評論,我會帶你的意見,以及動漫女孩反應img http://i.4cdn.org/b/1489612869792 .jpg – cosmichero2025

+0

哈哈,很感激。很高興我們可以提供幫助。 –