2017-02-21 56 views
0

錯誤特別在於跨度元素的寬度爲900像素,並且由於它在較小的屏幕尺寸範圍內延伸,因此它迫使頁面水平滾動。我嘗試使用overflow:hidden屬性,但不會停止滾動。CSS跨度強制頁面應該更寬應該是

我需要900像素的原因是我的文字和邊框居中,我的邊框不分爲兩部分。另外,該文本位於圖像的旋轉木馬滑塊上方。錯誤看起來這樣:

http://i.imgur.com/iAd16ml.png

我的目標是在元素overextends在裁剪頁面的寬度。這是我的代碼:

`

#title-display{ 
    vertical-align: middle; 
    text-align: center; 
    justify-content: center; 
    position: absolute; 
    top: 50%; 
    left: 50%; 
    margin: -40px 0 0 -450px; 
} 
#title-display span{ 
    width: 900px; 
    float: left; 
    position: absolute; 
} 

#title-display h1 { 
    display: inline; 
    text-transform: uppercase; 
    border-width: 8px; 
    border-style: solid; 
    border-color: white; 
    padding: 10px; 
    color: white; 
    font-size: 4vw; 
} 

`

我使用保證金:-40px 0 0 -450px;以文本爲中心。

下面是一些HTML的情況下:

<div id="title-display"> 
       <span> 
        <h1><strong>Adrian's Workflow<strong></h1> 
        <p class="kicker">Designer // Programmer // Youtuber</p> 
       </span> 
      </div> 
+0

嗯..爲什麼不只是'文本對齊:中心;'標題,而不是裕地獄出來的嗎? – Option

+0

這迫使它離開了視線,所以我添加了邊距。 –

+0

你能提供一些html嗎? – Armin

回答

2

你可以在50%的#title-display元素位置,50%則使用transform: translate(-50%, -50%)一半的寬度和高度,以抵消它,無論它的實際大小。像這樣。

body {background:#666;} 
 
#title-display{ 
 
    position: fixed; 
 
    top: 50%; 
 
    left: 50%; 
 
    -webkit-transform: translate(-50%, -50%); 
 
    -ms-transform: translate(-50%, -50%); 
 
    transform: translate(-50%, -50%); 
 
    text-align:center; 
 
} 
 

 
#title-display h1 { 
 
    text-transform: uppercase; 
 
    border-width: 8px; 
 
    border-style: solid; 
 
    border-color: white; 
 
    padding: 10px; 
 
    color: white; 
 
    font-size: 4vw; 
 
    white-space: nowrap; 
 
}
<header id="title-display"> 
 
    <h1><strong>Adrian's Workflow</strong></h1> 
 
    <p class="kicker">Designer // Programmer // Youtuber</p> 
 
</header>

+0

我更喜歡你的回答,因此刪除了我的和+1了你:) – Option

+0

我並不需要翻譯。白色空間:h1上的nowrap固定了一切。謝謝! –