Rows not moving upwards in looped content - html

Hi I am new user to Bootstrap (and coding), I have some looped content which takes an image and text for each loop (of different image heights and text lengths) to create 4 columns. But the result does not flow how I would like it too - see image example [image shows how img/text layout in 4 columns] Any help or advice greatly appreciated!
Here's the code example;
<div class="container-fluid bg-3 text-center">
<div class="row">
<div class="col-sm-3">
<some loop code which gets 1 image and 1 set of text>
</loop>
</div>
</div>

You need to start a new row every fourth iteration of your loop..
$i = 0; //Count
//Start your loops
if($i % 4 === 0) {
echo '</div><div class="row">';
}
++$i;

I agree that you should start with a row every 4th turn but you should also close the end tag of the div properly
Here is the sample code
var i = 0;
for(your logic){
if( i%4 === 0 {
Append <div class="row">
}
elseif(i%4 !== 0 && i%4 !==3){
Append the following code
<div class="col-sm-3">
The image should be here
</div>
}
else if( i%4=== 3){
Append </div>
}
}

Related

html merge 2 columns in 1 with 100% width bootstrap 2

I have the following HTML markup in my .NET MVC project:
<div class="row">
<div class="span6">#Model.Data</div>
<div class="span6">#Model.OtherData</div>
</div>
I'm getting data from server. So I want to do the following:
If data is empty then show other data with width = 100%.
Just to clarify I want to do something like that:
<div class="row">
<div class="span12">#Model.OtherData</div>
</div>
Or vice versa.
Is there a way to do that? Maybe with using different HTML tags / CSS classes.
Essentially you just want conditionally display the #Model.Data only if it isn't null. You can also set the col class with a variable, and conditionally change that variable depending if #Model.Data exists or not. Try something like this:
# {
var colClass = 'span6';
if (#Model.Data == null) {
colClass = 'span12';
}
}
<div class="row">
#if (#Model.Data != null) {
<div class="#colClass">#Model.Data</div>
}
<div class="#colClass">#Model.OtherData</div>
</div>

Can't increase variable

I'm working on a navigation and for some reason, I can't increase a variable.
<ul id="menu">
<li>
Home
<div class="dropdown_2columns">
<!-- Begin 2 columns container -->
<div class="col_2">
<h2>Welcome !</h2>
</div>
</div><!-- End 2 columns container -->
</li><!-- End Home Item -->
#foreach (var mainNode in rootNode.Children())
{
int childCount = 1;
int numChildren = mainNode.Children().Count();
int num = 0; #*<-------------- Num variable*#
<li>
#mainNode.Name
<div id=main-#num class="dropdown_5columns"> #*<----------Using the variable here*#
<!-- Begin 2 columns container -->
<div class="col_5">
<h2>#mainNode.Name</h2>
</div>
#* note if you want ALL descendants change .Children to .Descendats*#
#foreach (var childNode in mainNode.Children())
{
// if first node or new set of three open the div and ul #: is used to stop razor trying to
// "balance" the tags
if (childCount == 1 || (double)childCount % 3 == 1)
{
#:<div class="col_1">
#:<ul>
}
#childNode.Name
// close the div and list if this is either a multiple of 3 or the last one
if ((double)childCount % 3 == 0 || numChildren == childCount)
{
#:</ul>
#:</div>
}
childCount++;
num++; #*< -----------Increasing the varable here*#
}
</div>
</li>
}
</ul>
}
The problem is that the varable doesnt increase after looping. The div id is always main-0 even after looping multiple times. Does anyone know the cause of this?
"Num" is placed inside the mainNode loop, so it's always set to 0.
You have to move the num variable outside the mainNode loop and it should work :-)

Bootstrap grid layout issue when populating with items

I'm new to MVC5 and especially to using Bootstrap. I'm trying to create a website in which the first page should feature a grid with student images. Right now it looks like this. I want to have 5 images per row, but I haven't manage to figure out how(it was either 4, or 6).
Also when there is no space between the rows and the images stuck together.
I am populating the grid with items from my Student Model.
<div class="col-md-10">
<div class="row">
#foreach (var item in Model.Students)
{
<div class="col-md-2">
<a href="#Url.Action("Edit", "Students", new {studentId = item.StudentId})">
<img src="../../#item.ProfileImagePath" alt="Profile Image" />
</a>
</div>
}
</div>
</div>
I didn't fully understand how does the bootstrap grid work, especially when I'm populating it with dynamic data. The website looks like this now
http://imgur.com/5fLRZeM
You have
<div class="row">
#foreach (var item in Model.Students)
{
<div class="col-md-2">
...
</div>
}
</div>
Which generates one long <row>. But there is no auto-wrapping, you'll have to break this up into rows yourself.
Assuming that Students is a List<>
// roughly, untested
#for(int r = 0; r < Model.Students.Count; r += 5)
{
<div class="row">
#for (int s = r; s < r+5; s += 1)
{
<div class="col-md-2">
// do stuff with Model.Students[s]
</div>
}
</div>
}

Variable-heigth col-sm-4 divs on bootstrap

In my page I have three columns and many rows to show the following elements
<div class="col-sm-4">
<img src="<?php echo $myURL; ?>" class="img-responsive img-thumbnail">
<p class="lead"><?php echo $mytext; ?></p>
</div>
The display is perfect when all the $mytext are the same size (number of lines). However, if in a row elements A and B have say 2 lines of $mytext and the element C has 3 lines, the element C on the next row won't be displayed.
How can I prevent this? Ideally, the row height should be the highest of the height of the three elements in the row.
EDIT: If you go to http://bit.ly/1HfHiqC and reduce the width of the window, you will see what I am talking about.
If you are generating the content with a loop, lets say like this
foreach ($posts as $post) {
echo '<div class="col-sm-4">';
...
}
then you need to set a counter to add an clearfix class to every col-n * x = 12 DIV, to clear the floats. In you example you have n = 4 and that means you have to clear it on every 3rd iteration. To sum it up, whenerver your row is full, and the next row begins with a new set of cols, you have to add a class to the first div in that row.
$clearfix = 0;
foreach ($posts as $post) {
if ($clearfix % 3 == 0) { $clear_class = "clearfix"; } else { $clearfix = ""; }
echo '<div class="col-sm-4 '.$clear_class.'">';
...
$clearfix++;
}
And in your css you'd add the following
.clearfix { clear: both; }
That should solve your problem.

insert dynamic 6 images into 2 lines via bootstrap

i try without luck to insert 6 images into 2 lines,
the problem is that the line number 2 break the last 2 images and push them down.
i'm using Umbraco and bootstrap 3.
here is my code
#inherits Umbraco.Web.Mvc.UmbracoTemplatePage
#{
Layout = "InnerPage.cshtml";
}
#section slider
{
#{Html.RenderPartial("ImageSlider");}
}
#{
<!-- PROGRAM PAGE -->
<script src="js/script.js"></script>
<div class="caption-button caption-gray left-top" style="font-size:14px;">UPCOMING EVENTS</div>
<div class="padding-top-60">
<div class="row row-lg-height">
<div id="eventCarousel" class="carousel slide vertical" >
<div class="carousel-inner">
#{
var content = Umbraco.Content(1122);
int itemsCount = content.Children.Count();
int sliders = itemsCount / 6;
for (int i = 0; i <= sliders; i++)
{
var items = content.Children;
if (i == 0)
{
#Html.Raw("<div class=\"item active\">")
items = content.Children.Take(6);
}
else
{
items = content.Children.Skip(i * 6).Take(6);
#Html.Raw("<div class=\"item\">")
}
foreach (var childContent in items)
{
var contentService = ApplicationContext.Current.Services.ContentService.GetById(int.Parse(childContent.Id.ToString()));
var title = childContent.Name.ToString();
var image = Umbraco.Media(contentService.Properties["Thumbnail"].Value.ToString());
var description = contentService.Properties["shortDescription"].Value.ToString();
var img = image.Url.ToString();
<div class="col-lg-4">
<img src="#image.Url" class="media-object pull-left img-responsive" />
<h1 class="media-heading" style="color:#606060;">#title</h1>
<div style="padding:0px 5px; ">#MvcHtmlString.Create(#description)</div>
</div>
}
#Html.Raw("</div>")
}
}
</div>
</div>
</div>
</div>
<a class="caption-button caption-red right-bottom" href="#eventCarousel" data-slide="next">MORE</a>
}
i attached 2 images so you can see what firebug showing to me and what happened on the screen.
PLEASE HELP ME ! I am breaking my head 2 days already and it's wasting my time..
What do i do wrong ??
I think your code is a littlebit difficult. If you use another approach you will be able to debug much easier.
Try some approach like this:
#{
var allNodesToLoop = Umbraco.Content(1122).Children;
}
#foreach(var nodegroup in allNodesToLoop.InGroupsOf(2) {
<div class="row">
#foreach(var item in nodegroup) {
<div class="col-md-4">
#item.Name
<!-- and other stuff you want to render in this grid cell -->
</div>
}
</div>
}