2017-02-19 73 views
0

嗯,我想集中我的橫幅文本和圖像作爲psd,但是我嘗試了margin: 0 auto, margin: 0 auto 0 auto,和其他東西,但即使使用標籤中心,它也不起作用,我該如何解決?當我想看到我的html到一個更大的頁面時,它看起來不好,而不是集中,我不知道該做什麼可以幫助我。如何將div放在CSS上?

CSS: -

.banner{ 
    width: 100%; 
    height: 500px; 
    background-color: #505a78; 
} 

.banner p{ 
    display: block; 
} 

.banner_text{ 
    color: #fff; 
    padding: 150px; 
} 

.banner_text h1, 
.banner_text h1 span{ 
    font-size: 35px; 
    font-family: 'Montserrat Black'; 
} 

.banner_text .banner_wrap{ 
    margin:0 auto 0 auto; 
    width:auto; 
} 

.banner_text p{ 
    color: #a5abbb; 
    font-family: 'Montserrat Light'; 
} 

.banner_text p > span{ 
    display: block; 
} 

.banner_text a { 
    margin-top: 25px; 
    display: block; 
    color: white; 
    text-align: center; 
    width: 62px; 
    padding: 4px 25px; 
    text-align: center; 
    background-color: #7cdf95; 
    font-weight: bold; 
    font-family: 'Montserrat Black'; 
text-align: center; 
} 

.banner_text img { 
    width: 75%; 
    margin-top: -275px; 
} 

HTML: -

<section class="banner"> 
     <div class="banner_text"> 
      <div class="banner_wrap"> 
       <h1>Lorem ipsum dolor sit amet, <span>consectetur adipiscing elit</span></h1> 
       <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo.<span> Cum sociis natoque penatibus et magnis dis parturient montes, nascetur</span></p> 
       <a href="#">button</a> 
       <img src="img/16251331_10210478393849069_2072529108_o.png" alt=""> 
      </div> 
     </div> 
     </section> 

psd my_html

回答

0

嘗試增加:

.banner_text .banner_wrap{ 
    margin:0 auto 0 auto; 
    width:50%; 
} 

width:50%;將把div放在頁面中間,如果這是你想要的!

0

您可以設置DIV中心這樣

margin: auto; 
width: 50%; 

如果不設置寬度或將寬度設置爲100%,那麼DIV永遠中心。

如果要居中的DIV中的文本,然後使用

text-align: center 

如果要居中的圖像,然後使用

display: block; 
margin: auto;