2017-08-24 72 views
1

我想讓此分區響應並將文本保持在整個時間的中心位置。截至目前,在手機上看起來很好,因爲我向它添加了媒體查詢,但在桌面上,我的.info-p-div中的p元素進入了下面的div,看起來很糟糕。這些div在頁面上並排顯示。我將發佈我的HTML和CSS代碼,以便查看我的意思。保持分區內的P元素

HTML

<div class="info"> 
<div class="info-img-div"> 
<img src="images/owner.jpg" /> 
<p><font color="#F5F5F5">Text here</font></p> 
</div> 
<div class="info-p-div"> 
<p><font color="#F5F5F5">Text here</font></p> 
</div> 
</div> 
<div class="parallax-3"></div> 

CSS

.info { 
    text-align: center; 
    min-height: 250px; 
    width: 100%; 
    background-color: #000; 
} 

.info-img-div { 
    position: left; 
    width: 35%; 
    border-right-style: solid; 
    border-color: #F5F5F5; 
} 

.info-img-div img { 
    border-radius: 50%; 
    height: 25%; 
    width: 25%; 
    min-height: 100px; 
    min-width: 100px; 
    margin-top: 20px; 
} 

.info-p-div { 
    height: 25%; 
    width: 50%; 
    max-width: 65%; 
    text-align: center; 
    position: relative; 
    float: right; 
    font-size: 12px; 
    word-wrap: break-word; 
    vertical-align: middle; 
} 

.parallax-3 { 
    background-image: url("images/background3.jpg"); 
    height: 400px; 
    background-attachment: fixed; 
    background-position: center; 
    background-repeat: no-repeat; 
    background-size: cover; 
} 

@media only screen and (max-width: 600px) { 
    .info { 
     text-align: center; 
     float: none; 
     height: 50%; 
    } 
    .info-img-div { 
     float: none; 
     border-right-style: none; 
     position: relative; 
     width: 100%; 
    } 
    .info-p-div { 
     float: none; 
     text-align: center; 
     width: 100%; 
     max-width: 100%; 
    } 
} 
+0

你可以得到它'flex' – LKG

+0

我之前試過,但在p仍然從DIV伸出。 :( –

+0

@詹姆斯哈蒙德請提供[完整,最小和可驗證](https://stackoverflow.com/help/mcve)示例。您尚未提供任何關於您在OP中提及的「div」的代碼。如果沒有代碼來重現問題,很難協助。 – McHat

回答

0

我認爲你正在尋找下面的解決方案。

我發佈了一個工作示例。

.box { 
 
    display: flex; 
 
    justify-content: center; 
 
    flex-direction: row; 
 
    align-items: center; 
 
    width: 100%; 
 
    height: 300px; 
 
    background: tomato; 
 
} 
 

 
.box p { 
 
    flex: 1 0 0; 
 
    text-align: center; 
 
} 
 

 
@media screen and (max-width:600px) { 
 
    .box { 
 
    flex-direction: column; 
 
    } 
 
    .box p { 
 
    display: flex; 
 
    justify-content: center; 
 
    align-items: center; 
 
    } 
 
}
<div class="box"> 
 
    <p>One</p> 
 
    <p>Two</p> 
 
</div>

+0

我之前嘗試過,它確實使文本中心很好。但是,它仍然會進入.parallax-3 div。我只是在網站上再次嘗試。它在你的例子中工作。我猜我的問題涉及這樣的事實,即這個div需要佔用75%的寬度,而旁邊的寬度需要佔用25%,直到他們通過媒體查詢移動爲止。看到我的代碼以供參考。再次感謝! @LKG –