0

I have 2 different partial views that I am calling in my main view like this:

<div class="col-md-6">
 @Html.Action("Chart", "Teams")
</div>
<div class="col-md-6">
 @Html.Action("SeriesWinsChart", "Teams")
</div>
<div class="next-game">
 <h3 class="text-center">The Next Game Is:</h3>
</div>
<br />
<div class="text-center">
 <h3 style="color:red;">@ViewBag.NextGame</h3>
</div>

Now my problem is this:

background issue

All I have done is put background-color: green in my CSS for the class .next-game (honestly just to see what it looked like.. green is not what I am going to use)... I have gone into Inspect Element on IE and I cannot find the problem as to why the background is so big. I just want the background to be around The Next Game Is:

CSS:

.next-game{
 background-color: green;
}

How do I shrink the background? I have tried width: 50%; height: 10px; //etc just to see the different changes but can't figure this out

UPDATE:

I have changed the HTML to:

<div class="next-game">
 <h3 class="text-center">The Next Game Is:</h3>
 <div class="text-center">
 <h3 style="color:red;">@ViewBag.NextGame</h3>
 </div>
</div>
<div class="col-md-6">
 @Html.Action("Chart", "Teams")
</div>
<div class="col-md-6">
 @Html.Action("SeriesWinsChart", "Teams")
</div>

This at least made the background render properly. So this has something to do with the partial views?

asked Mar 30, 2016 at 14:27
5
  • Looking at all the elements you have provided does not explain that result. Make sure there is nothing else that may impact the end result. We could help you more if you included all parts of code that reproduce this behavior. Commented Mar 30, 2016 at 14:30
  • col-md-6. Are you using twitter bootstrap by any chance? You should be using rows to wrap those columns if that's the case. Commented Mar 30, 2016 at 14:30
  • @JosephMarikle I am using twitter bootstrap. what do you mean by using rows? Commented Mar 30, 2016 at 14:32
  • Standard syntax for columns in twbs is <div class="container"><div class="row"><div class="col-sm-12">Your stuff</div></div></div>. You generally need all three (container, row, column) for it to render properly. What you're running into here is probably a clearfix issue. The columns are floated, which makes the next available non-floating element appear to "wrap" them. An alternative solution would be to implement a clearfix. In bootstrap I think there's the .clearfix class. Commented Mar 30, 2016 at 14:35
  • @JosephMarikle that worked. post answer and I will mark it! thank you! Commented Mar 30, 2016 at 14:37

2 Answers 2

2

The most likely cause for this issue is that your twitter bootstrap columns have no wrapping row. You generally need all three (container, row, column) for it to render properly. What you're running into here is probably a clearfix issue. The columns are floated, which makes the next available non-floating element appear to "wrap" them. Below is a possible solution to the problem.

<div class="container">
 <div class="row">
 <div class="col-md-6">
 @Html.Action("Chart", "Teams")
 </div>
 <div class="col-md-6">
 @Html.Action("SeriesWinsChart", "Teams")
 </div>
 </div>
</div>
<div class="next-game">
 <h3 class="text-center">The Next Game Is:</h3>
</div>
<br />
<div class="text-center">
 <h3 style="color:red;">@ViewBag.NextGame</h3>
</div>

Other solutions include adding a .clearfix class to a wrapper for the columns or adding clear:both to .next-game.

answered Mar 30, 2016 at 14:41
Sign up to request clarification or add additional context in comments.

3 Comments

In other words, the old float problem. I don't know why bootstrap still use floats to layouts in XXI century...
@MarcosPérezGude Well, to be fair, they are moving to flex in the next release. They just need to actually release it finally. :P
really!? Good news are them!
0

You need

.next-game h3{
 background-color: green;
}

(it's just for the header h3 inside the element with that class .next-game)

answered Mar 30, 2016 at 14:29

1 Comment

I have tried this and I still render the same result

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.