2017-03-03 200 views
0

我試圖在幾個元素之間創建一個垂直的左邊框,我嘗試了一些來自this thread的最受好評的建議,但沒有成功。CSS:邊框顯示不正確

目前,邊框看起來是這樣的:

(是的,它是可憐的黑線)

當然,我真正想要的是行至佔據整個左側頁面的一面。所有的建議是非常感謝!

我的ERB文件:

<h1 class="p1_vs_p2"><%= @game.player.name %> vs <%[email protected] %></h2> 
<h2 class="player_chose"> You chose <%= @game.player.weapon.capitalize %></h2> 
<h2 class="computer_chose"><%= @game.computer.name %> chose <%[email protected] %></h2> 
<div style="clear: both;"></div> 

<% if @game.outcome == Game::POSSIBLE_OUTCOMES[0] %> 
    <h2 class="victory_message"> Congratulations, you win!</h2> 
<% elsif @game.outcome == Game::POSSIBLE_OUTCOMES[1] %> 
    <h2 class="tie_message"> It's a tie!</h2> 
<% else %> 
    <h2 class="defeat_message">You lost this time.</h2> 
<% end %> 

<h4> <a href="/" class="play_again">Play Again</a> </h4> 
<div class="vertical_line"> 

我的CSS文件:

html { 
    height: 100% 
} 

body { 
    background-color: #f4f1ec; 
} 

input[type="radio"]{ 
    margin: 0 5px 0 10px; 
} 

table.center { 
    margin-left:auto; 
    margin-right:auto; 
    } 

.title { 
    padding-top: 40px; 
    text-align: center; 
    font-family: 'Raleway', sans-serif; 
    color: #6495ED; 
    padding-bottom: 100px; 
} 

.input_name_button { 
    position: fixed; 
    text-align: center; 
    top: 50%; 
    left: 50%; 
    margin-top: -50px; 
    margin-left: -100px; 
} 

.play_button { 
    text-align: center; 
    padding-top: 30px; 
} 

.p1_vs_p2 { 
    padding-top: 40px; 
    text-align: center; 
    font-family: 'Raleway', sans-serif; 
    color: #B0C4DE; 
    padding-bottom: 100px; 
} 

.player_chose { 
    color: #6495ED; 
    float: left; 
    padding-left: 200px; 
} 


.computer_chose { 
    color: #FFA07A; 
    float: right; 
    padding-right: 50px; 
} 

.victory_message { 
    color: #8FBC8F; 
    text-align: center; 
    bottom: 0px; 
    width: 100%; 
    padding-bottom: 300px; 
    position: fixed; 
} 

.tie_message { 
    color: #FFDEAD; 
    text-align: center; 
    bottom: 0px; 
    width: 100%; 
    padding-bottom: 300px; 
    position: fixed; 
} 

.defeat_message { 
    color: #F08080; 
    text-align: center; 
    bottom: 0px; 
    width: 100%; 
    padding-bottom: 300px; 
    position: fixed; 
} 

a.play_again { 
    color: #A9A9A9; 
    text-align: center; 
    bottom: 0px; 
    width: 100%; 
    padding-bottom: 100px; 
    position: fixed; 
    font-family: 'Raleway', sans-serif; 
    text-decoration: none; 
} 

.vertical_line { 
    width: 4px; 
    background-color: black; 
    height: 100%; 
    float: left; 
} 

讓我知道,如果你有什麼事,我會很樂意提供。謝謝。 :)

回答

0

你有沒有嘗試把所有的內容在一個股利,並使其邊界屬性是這樣的?

border-top-style: none; 
border-right-style: none; 
border-bottom-style: none; 
border-left-style: solid; 
+0

我只是想包裝一個div內的所有內容的網頁和應用你所提供的造型,但它只是做了輕微更大的黑色k行出現在頁面的頂部?談到CSS哈哈,我有點小氣,所以原諒我吧!哦,謝謝你的回覆! – IainK

+0

我只是需要幫助你..我在w3shools上試過它,它運行良好:P – 2017-03-03 23:49:20

0

您可以在下面的CSS添加到您的樣式表:

body { 
    margin-left: 0; 
    border-left: 5px solid black; 
} 

您可能還刪除了一堆,你的標題創造利潤的。

+0

嘿!謝謝回覆。這在很大程度上是有效的,但是它在頁面的頂部和底部都留下了一個小小的差距。有任何想法嗎? – IainK

+0

你可能有一些有邊距的元素,比如h1s等等。您必須通過給它們賦值'0'來重置這些邊距。 –

+0

嗯,當我引用位於不同頁面上的類時,我只在CSS文件中使用了「邊距」。這仍然是問題嗎? – IainK

0

包裹CSS的相關部分的股利和左邊框應用到DIV

這裏是與你的代碼(不考慮你有沒有張貼的腳本,這是導致原因爲所有「%」的東西的內容):

html { 
 
    height: 100% 
 
} 
 

 
body { 
 
    background-color: #f4f1ec; 
 
} 
 

 
input[type="radio"]{ 
 
    margin: 0 5px 0 10px; 
 
} 
 

 
table.center { 
 
    margin-left:auto; 
 
    margin-right:auto; 
 
    } 
 

 
.title { 
 
    padding-top: 40px; 
 
    text-align: center; 
 
    font-family: 'Raleway', sans-serif; 
 
    color: #6495ED; 
 
    padding-bottom: 100px; 
 
} 
 

 
.input_name_button { 
 
    position: fixed; 
 
    text-align: center; 
 
    top: 50%; 
 
    left: 50%; 
 
    margin-top: -50px; 
 
    margin-left: -100px; 
 
} 
 

 
.play_button { 
 
    text-align: center; 
 
    padding-top: 30px; 
 
} 
 

 
.p1_vs_p2 { 
 
    padding-top: 40px; 
 
    text-align: center; 
 
    font-family: 'Raleway', sans-serif; 
 
    color: #B0C4DE; 
 
    padding-bottom: 100px; 
 
} 
 

 
.player_chose { 
 
    color: #6495ED; 
 
    float: left; 
 
    padding-left: 200px; 
 
} 
 

 

 
.computer_chose { 
 
    color: #FFA07A; 
 
    float: right; 
 
    padding-right: 50px; 
 
} 
 

 
.victory_message { 
 
    color: #8FBC8F; 
 
    text-align: center; 
 
    bottom: 0px; 
 
    width: 100%; 
 
    padding-bottom: 300px; 
 
    position: fixed; 
 
} 
 

 
.tie_message { 
 
    color: #FFDEAD; 
 
    text-align: center; 
 
    bottom: 0px; 
 
    width: 100%; 
 
    padding-bottom: 300px; 
 
    position: fixed; 
 
} 
 

 
.defeat_message { 
 
    color: #F08080; 
 
    text-align: center; 
 
    bottom: 0px; 
 
    width: 100%; 
 
    padding-bottom: 300px; 
 
    position: fixed; 
 
} 
 

 
a.play_again { 
 
    color: #A9A9A9; 
 
    text-align: center; 
 
    bottom: 0px; 
 
    width: 100%; 
 
    padding-bottom: 100px; 
 
    position: fixed; 
 
    font-family: 'Raleway', sans-serif; 
 
    text-decoration: none; 
 
} 
 

 
.wrapper_for_left_border { 
 
    border-left: 2px solid black; 
 
}
<div class="wrapper_for_left_border"> 
 
<h1 class="p1_vs_p2"><%= @game.player.name %> vs <%[email protected] %></h2> 
 
<h2 class="player_chose"> You chose <%= @game.player.weapon.capitalize %></h2> 
 
<h2 class="computer_chose"><%= @game.computer.name %> chose <%[email protected] %></h2> 
 
<div style="clear: both;"></div> 
 

 
<% if @game.outcome == Game::POSSIBLE_OUTCOMES[0] %> 
 
    <h2 class="victory_message"> Congratulations, you win!</h2> 
 
<% elsif @game.outcome == Game::POSSIBLE_OUTCOMES[1] %> 
 
    <h2 class="tie_message"> It's a tie!</h2> 
 
<% else %> 
 
    <h2 class="defeat_message">You lost this time.</h2> 
 
<% end %> 
 

 
<h4> <a href="/" class="play_again">Play Again</a> </h4> 
 
</div>

+0

嘿,我試過這樣做,但取決於我在哪裏開始div,垂直線只佔用頁面的一小部分。除非我完全誤解了你,否則道歉! – IainK

+0

看看我添加的片段 – Johannes

+0

嘿約翰內斯 - 感謝您花時間包含一段代碼。不幸的是,我已經嘗試過了(並且我剛剛嘗試過使用您使用的確切CSS),所有這些都將黑色線從頁面中間移到頁面頂部。任何想法爲什麼這可能發生?再次感謝! – IainK