I'm having issue getting my grid to align correctly. Here is the HTML
<div class="span6" id="content">
<!-- Category 2 is Programming category. -->
<?php $programming_posts = get_posts('2'); ?>
<div class="row-fluid">
<?php foreach($programming_posts as $key => $post){ ?>
<div class="span6 well well-small" id="post-preview">
<?php echo $post->post_excerpt;?>
</div>
<?php }?>
</div>
</div>
Here is the CSS
#post-preview{
border: 1px solid rgba(140,140,140,1);
border-radius: 2px;
max-height: 135px;
min-height: 135px;
margin-bottom: 5px;
}
As you can see the first row is not aligned with the rows that comes after it. The first row is the row with the right alignment. I'm not sure how to fix this?
You html structure is bad as a row-fluid can have only maximum of 12 columns, ie in this case two <div class="span6 well well-small" id="post-preview"> elements. But in your case you are adding all post-preview divs to a single row-fluid
Your html must be structure should be like
<div class="row-fluid">
<div class="span6 well well-small" id="post-preview1">
</div>
<div class="span6 well well-small" id="post-preview2">
</div>
</div>
<div class="row-fluid">
<div class="span6 well well-small" id="post-preview1">
</div>
<div class="span6 well well-small" id="post-preview2">
</div>
</div>
Also the id should be unique in a document, you have many divs with id post-preview because of the loop
Approach A:
Since you have 4 blocks, you can use span3 class:
<div class="span3 well well-small" id="post-preview">
<?php echo $post->post_excerpt;?>
</div>
Approach B:
If you want to keep the width and only display a pair of blocks in one line, then you can split pairs of divs into separate row-fluid (PHP code is just for reference):
<div class="row-fluid">
<div class="span6 well well-small" id="post-preview1">
<?php echo $post->post_excerpt;?>
</div>
<div class="span6 well well-small" id="post-preview2">
<?php echo $post->post_excerpt;?>
</div>
</div>
<div class="row-fluid">
<div class="span6 well well-small" id="post-preview1">
<?php echo $post->post_excerpt;?>
</div>
<div class="span6 well well-small" id="post-preview2">
<?php echo $post->post_excerpt;?>
</div>
</div>
Related
I am having an issue with a dynamic form I am creating on my page.
I have a Row that contains 1 or more Divs that are 4 col in length. I would expect that after ever 3, it moves the next one down as it hits the 12 col limit.
Looking at the picture below, after we hit the first three fields I would think it would move the others down to their own row.
Here id the HMLT that my data is in. As you can see, each one is its own col within the row.
Is there something I am doing incorrectly with the way I have this formatted? Just not sure what else to try.
I believe it is proper to create a .row for every row on the page:
<div class="row">
<div class="col-md-4">.col-md-4</div>
<div class="col-md-4">.col-md-4</div>
<div class="col-md-4">.col-md-4</div>
</div>
<div class="row">
<div class="col-md-4">.col-md-4</div>
<div class="col-md-4">.col-md-4</div>
<div class="col-md-4">.col-md-4</div>
</div>
I had the same problem yesterday, what I found is that the container should have the col length specified in order to fix the problem.
Also I found useful to add additional divs in order to fix better the length of the fields.
My example:
<div class="form-group col-md-12">
<div class="row">
<div class="form-group col-md-3">
your label data
</div>
<div class="form-group col-md-4">
your input data
</div>
</div>
<div class="row">
<div class="form-group col-md-2">
your label data
</div>
<div class="form-group col-md-3">
your input data
</div>
</div>
</div>
I hope it helps.
It's hard to tell from your screenshot, but it looks like you have the whole thing (rows, columns, and some form groups) inside of a span element. Try using a div instead.
The problem: http://jsfiddle.net/24doudo0/
This seems to be an issue with how bootstrap handles grid wrapping. It doesn't handle as nicely as we would like. I can think of two solutions to this problem. The first is to insert rows after every third column when you loop over them in the backend. For that you can use the modulus operator. I don't know what backend language you are using, but I'll illustrate this approach using PHP because I'm lazy.
Lets assume you have an array of input names that you want to loop over and create columns for each.
<div class="row">
<? foreach ($inputs as $count => $name) : ?>
<div class="col-md-4">
<input type="text" name="<?=$name?>">
</div>
<? if (($count + 1) % 3 == 0) : // $count is 0 based. We need an index that starts at 1 so that we don't trigger a new row on the first loop (0 / 3 = 0 which is a remainder of 0) ?>
</div>
<div class="row">
<? endif; ?>
<? endforeach; ?>
</div>
The other solutions is a CSS based one. Pretty simple but is CSS3 only, so it won't work in IE 8 or less. This approach just clears the float after every third column. Demo here: http://jsfiddle.net/j0dtng4t/
[class*="col-"] {
background: #C55;
border: 1px solid white;
color: white;
}
[class*="col-"]:nth-of-type(3n + 1) {
clear:left;
}
Actually there are at least other 2 alternative solutions you can consider without adding row divs.
The first is adding heights to all the .col* elements , in this way they'll get ordered progressively and stack when they don't fit next to each other.(checkout the pen).
The second is using display flex on the div containing the .col* elements; it's not a bootstrap feature but it seems to suite your situation quite well.
In the pens I made I modified the col-* selectors but I suggest you use a new selector so not to mess with Bootstrap's grid style.
There seems to be some confusion on how floats work especially in a bootstrap grid.
Here is a simple bit of code that demonstrates how floats work
.container-fluid {min-width:638px;}
.container-fluid p{margin:0;font-size:1.2rem}
[class*="col-"] {
background: #C55;
border: 1px solid white;
color: white;
}
<link href="http://getbootstrap.com/dist/css/bootstrap.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row">
<div class="col-xs-4">
column 1 <p>we work because we are the same height</p>
</div>
<div class="col-xs-4">
column 2 <p>we work because we are the same height</p>
</div>
<div class="col-xs-4">
column 3 <p>we work because we are the same height</p>
</div>
<div class="col-xs-4">
column 1
</div>
<div class="col-xs-4">
column 2 <p>I'm tall, but my buddies aren't</p>
</div>
<div class="col-xs-4">
column 3
</div>
<div class="col-xs-4">
column 3
</div>
<div class="col-xs-4">
column 1
</div>
<div class="col-xs-6">
column 2 <p>I'm tall but because Fred is too wide he goes to the far left to fit</p>
</div>
<div class="col-xs-2">
column 3
</div>
<div class="col-xs-4">
Fred column 1
</div>
</div>
<div class="row">
<div class="col-xs-4">
inputs are taller than select
</div>
<div class="col-xs-4">
inputs are taller than select
</div>
<div class="col-xs-4">
selects are smaller
</div>
<div class="col-xs-4">
<input type="text" placeholder="i'm too tall" />
</div>
<div class="col-xs-4">
<input type="text" placeholder="i'm too tall" />
</div>
<div class="col-xs-4">
<select><option>i'm shorter</option></select>
</div>
<div class="col-xs-4">that's why i'm column 3</div>
</div>
</div>
one:
<div class="row">
<div class="col-md-12">
<div class="row">
.
.
</div>
</div>
</div>
two:
<div class="row">
<div class="col-md-12 row">
.
.
</div>
</div>
Is both the implementations are same?can i use the 2 method so that i can reduced the mark-up.
According to Bootstrap's own API documentation, when nesting columns any columns .col should be nested within a .row. The two should not be combined on a single element.
Aside from the fact this makes more sense semantically- the underlying CSS properties both classes affect are reliant on this structure.
Also note, when using col-md-12 in isolation, you are effectively creating a full width element (which a row is anyway). In which case using the grid layout may not be relevant unless you have other elements showing/coming into play at different screen sizes.
Right (if using other columns as well as col-md-12):
<div class="row">
<div class="col-md-12">
<div class="row">
.
.
</div>
</div>
</div>
Wrong:
<div class="row">
<div class="col-md-12 row">
.
.
</div>
</div>
If you just want a full width element, you dont need to use the grid layout and/or can remove one level of nesting.
1.If you need multiple .col- in a row then you may write as following..
<div class="row">
<div class="col-md-6">
.
.
.
</div>
<div class="col-md-6">
.
.
.
</div>
</div>
2. if you need to divide `.col-` in more `.col` then
<div class="row">
<div class="col-md-6">
<div class="row">
<div class="col-md-6">
.
.
.
</div>
<div class="col-md-6">
.
.
.
</div>
</div>
</div>
<div class="col-md-6">
.
.
</div>
</div>
I am new to programming and having difficulty in adjusting the bootstrap grids to fit my framework; I am trying to do a 3 columns side bar on the left, and followed by a 9 column main side bar on the right - but they appeared as 12 columns each after I input my code.
<div class="content row">
<?php include "_/components/php/snippet-carousel.php"; ?>
<section class="col-md-3 col-md-pull-9 sidebar">
<?php include "_/components/php/aside-social.php"; ?>
</section><!-- sidebar -->
<section class="col-md-9 col-md-push-3 cont-grid">
<?php include "_/components/php/weekend-intro.php"; ?>
<?php include "_/components/php/popular-categories.php"; ?>
</section><!-- main -->
</div><!-- content -->
<?php include "_/components/php/footer.php"; ?>
</section><!-- container -->
Take a look at this code. Maybe it will help you:
<div class="content">
<div class="row">
<div class="col-md-12"><?php include "_/components/php/snippet-carousel.php"; ?></div>
</div>
<div class="row">
<section class="col-md-3 sidebar"><?php include "_/components/php/aside-social.php"; ?></section>
<section class="col-md-9 cont-grid">
<?php include "_/components/php/weekend-intro.php"; ?>
<?php include "_/components/php/popular-categories.php"; ?>
</section>
</div>
<div class="row">
<div class="col-md-12"><?php include "_/components/php/footer.php"; ?></div>
</div>
</div>
You have one closing section with no opening one. And I suppose you wrap the whole thing into a container?
I'm using a container.
And two spans.
The first span in the markup is div.span8 and the second one is div.span4
Now, When I view the site using mobile-sized browser, things are neat but the span4 slips to the bottom of the span8 which is natural since span4 comes after span8 in the markup. Now, I want to make it in a way that when the size of the browser is mobile, the span4 comes before the span8, which means on top of it. How should I do this?
Here is my MarkUp:
<div id="maincontent" style="margin:0px; padding: 0px;" class="row-fluid <?php echo $main; ?> category" role="main">
<div class="span8">
<div id="content" class="span8 mainborder"></div>
</div>
<div class="span4">
<?php
echo $column_right;
?>
</div>
And the CSS is TB 2.0.
Thanks in advance
You can do that like:
<div id="maincontent" style="margin:0px; padding: 0px;" class="row-fluid <?php echo $main; ?> category" role="main">
<div class="span4 pull-right">
<?php
echo $column_right;
?>
</div>
<div class="span8 pull-left" >
<div id="content" class="span8 mainborder"></div>
</div>
for reference you can visit http://getbootstrap.com/css/#helper-classes-floats
You can add the span4 first in your html Document and give the span8 an float right when the screen size is > 768 pixels.
#media (min-width:768px) {
.span8 {
float:right;
}
}
I want to make a Bootstrap Theme with the Menu on the left sidebar. The problem is that I can't fix the content after the sidebar menu. Here's a screenshot:
.
The content is placed into a row, in 4 span3 divs. How can I make this content to move right next to the sidebar nav?
<?php
if ( !defined('ABSPATH')) exit;
get_header();
?>
<?php if(is_front_page()): ?>
<div class="row wpeden-bs-services">
<?php for($i=1;$i<=4;$i++){ ?>
<div class="span3">
<?php $tpid = (int)bleed_get_theme_opts('home_featured_page_'.$i); $intropage=get_page($tpid); $introcontent = strip_tags(strip_shortcodes($intropage->post_content),"p,br"); if (preg_match('/^.{1,80}\b/s', $introcontent, $match)) $introcontent = $match[0]; else $introcontent = substr($introcontent,0,80); ?>
<div class="about well">
<?php bleed_thumb($intropage,array(500,300), array('class'=>'img')); ?>
<div class="entry-content">
<h2><?php echo $intropage->post_title; ?></h2>
<p><?php echo $introcontent; ?></p>
</div>
View details
</div>
</div>
<?php } ?>
<!-- /.span4 -->
<?php get_template_part('homepage','category'); ?>
<div class="clear"></div>
<div>
</div>
</div><!-- /.span4 -->
<?php endif; ?>
<?php get_footer(); ?>
if i understood you correctly it looks like you need to nest your rows.
<div class="row">
<div class="span4">
side bar here
</div>
<div class="span8">
nested content goes here
<div class="row">
<div class="span3"></div>
<div class="span3"></div>
<div class="span3"></div>
<div class="span3"></div>
</div>
</div>
</div>
This template has a responsive menu toggling system. The menu will appear collapsed on smaller screens, and will appear non-collapsed on larger screens. When toggled using the button below, the menu will appear/disappear. On small screens, the page content will be pushed off canvas.
Make sure to keep all page content within the #page-content-wrapper.
http://blackrockdigital.github.io/startbootstrap-simple-sidebar/