2017-03-03 111 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