Bootstrap3 row span - css

I would like to make a layout where my logo is at the left, and my title and menu are on the right of the logo. When the screen is too small then it should be logo, title and then menu. (On either side there is a col-lg-2)
My attempt was:
<header class="row">
<div id="logo"class="col-xs-12 col-sm-2
col-md-2 col-md-offset-2 col-lg-2 col-lg-offset-2">
</div>
<div id="title_menu" class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
<div id="title">
Title
</div>
<nav id="navigation_bar" >
Menu
</nav>
</div>
</header>
<div class="row">
<div id="something" class="col-xs-12 col-sm-12
col-md-8 col-md-offset-2 col-lg-8 col-lg-offset-2">
something
</div>
header {
background: #0090e5 !important;
}
#logo {
height:250px;
}
#title_menu {
height:50px;
}
But on an IPhone the title and menu disappear and seem to be behind the element in the row underneath. I am using the height, because I want everything to be align with the bottom of the row.

I'm not sure exactly what you're going for, but there appears to be quite a bit of redundancy in your classes. One thing you should know about Bootstrap is that you only need to specify the number of columns on each size if the number of columns is changing. For instance, if you want a div to take up 2 columns on small, medium and large, you only need to define small, every size above small will automatically use the same number of columns. Similarly, you don't need to specify col-xs-12 because that is already assumed. So you could simplify it to this(notice how I'm only defining the number of columns for sm and everything else is taken care of automatically):
<div class="container">
<header class="row">
<div id="logo" class="col-sm-2">
<img src="http://placehold.it/50x50">
</div>
<div id="title_menu" class="col-sm-5">
<div id="title">
Title
</div>
</div>
<div class="col-sm-5">
<nav id="navigation_bar">
<ul>
<li>Menu Item 1</li>
<li>Menu Item 2</li>
<li>Menu Item 3</li>
<li>Menu Item 4</li>
</ul>
</nav>
</div>
</header>
</div>
This will display the logo, title and menu all on the same line from small up and it will show the logo, title and menu stacked on mobile(xs).
Bootply example

Related

Change order of cols with push and pull Bootstrap

I just discovered the "push" and "pull" classes in Bootstrap, but am having a lot of trouble implementing them the way I'd like. On XS screens, my content appears as follows, which is correct:
|A||B||C|
But on SM screens, I need it to be:
|B|
|C|
|A|
My HTML is below. I tried adding "col-sm-push-10" to the div that contains my button, but that just pushed it to the right within it's own div. I need to actually MOVE this div down. Any help would be much appreciated!!
<div class="container-fluid">
<div class="col-sm-4">
<ul class="prod-group">
<div class="col-xs-2 col-sm-10">
<li><button type="button" class="btn">A</button></li>
</div>
<div class="col-xs-6 col-sm-10">
<li>B</li>
</div>
<div class="col-xs-4 col-sm-10">
<li>Cr</li>
</div>
</ul>
</div>
Usually you'd want elements to stack vertically on xs screens, and remain horizontally on larger (sm) screens, so this is an unusual case where you actually want the opposite. Create the stacking sm layout first, then adjust for xs using push-pull.. A-B-C on large. B-C-A on mobile.
<div class="container-fluid">
<div class="row">
<div class="col-sm-4">
<ul class="row prod-group">
<li class="col-xs-6 col-sm-10 col-xs-push-2 col-sm-push-0">
B
</li>
<li class="col-xs-2 col-sm-10 col-xs-pull-0 col-sm-pull-0">
C
</li>
<li class="col-xs-4 col-sm-10 col-xs-pull-8 col-sm-pull-0">
A
</li>
</ul>
</div>
</div>
</div>
Demo http://www.codeply.com/go/yMxh8sGwMZ
Also, don't forget to keep your columns inside a row for proper padding.
You should write your elements in order that you want to see on -sm-.
Then adjust their position at -xs-:
<div class="row">
<div class="col-sm-12 col-xs-4 col-xs-push-4">
B
</div>
<div class="col-sm-12 col-xs-4 col-xs-push-4">
C
</div>
<div class="col-sm-12 col-xs-4 col-xs-pull-8">
A
</div>
</div>
By the way, you should use li only as direct child of ul as well as not using other elements such as div directly inside ul, because it is not valid.

Bootstrap show div in same row

I need create a page with show Polls to users can vote. I want to show all in one row but if window go more little I want that the divs go down like this picture.
<div class="container-fluid">
<div class="row">
<div class="col-md-3">
<div class="header-encuesta">
<span class="text-white">#Model.Name</span>
</div>
<div class="well">
#using (Html.BeginForm("Vote", "Poll", routeValues: new { id = Model.Id, option = 0 }))
{
<ul>
#foreach (PollOptions option in Model.PollOptions)
{
<li>#Html.CheckBox(option.OptionName, false, new { onclick = "ActionVote('" + (Model.Id) + "','" + (option.Id) + "')" }) #option.OptionName</li>
}
</ul>
}
</div>
</div>
</div>
Given your code example, this should just naturally work by the way which Bootstrap's grid system functions (assuming the window its rendering in works for the "md" (medium) sized grid since that's what you've used in your code).
Here is a JS Fiddle https://jsfiddle.net/ecztz3fq/ example of the below code.
<div class="container-fluid">
<div class="row">
<div class="col-sm-3">
<div class="header-encuesta">
<span class="text-white">Header</span>
</div>
<div class="well">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</div>
</div>
<div class="col-sm-3">
<div class="header-encuesta">
<span class="text-white">Header</span>
</div>
<div class="well">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</div>
</div>
</div>
</div>
You can pull up the example, run it, and then drag the divider in the JS Fiddle page that separates the "Result" and "CSS" windows from the "HTML" and "JS" windows. As you drag you'll see the wells render horizontally when the window is large, and then render stacked if the window becomes too small.
The size at which a column will stack vs. render horizontally is based on the xs, sm, md, lg designations in the column's class name.
Bootstrap grid system docs: http://getbootstrap.com/css/#grid
you can use grid system
col-xs-12 for smaller screen
col-md-3 for medium
you can use col-sm-3 here in your case

Bootstrap, fixed left offcanvas sidebar with scrollable content in the center

I want to create a template for a project that i am working on using Bootstrap and i have a problem with the behavior of the offcanvas sidebar. I want the sidebar to take all the space below the header and to not be scrollable. I have found two templates, that combined do what i want but i have a problem merging them as i am not very good with css. I have tried a lot to do but i can't figure how to do it. Here is a picture showing the desired functionality/behavior of the template i want to make:
Here are the two templates i have found:
Dashboard
Dashboard (with off-canvas sidebar)
And here is the code (HTML+CSS) of each template (stripped down) so you can easily figure out how they work:
Dashboard - fixed sidebar
HTML
<div class="row">
<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar">
<li class="active">Overview</li>
<li>Reports</li>
<li>Analytics</li>
<li>Export</li>
</ul>
</div>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<h1 class="page-header">Dashboard</h1>
</div>
</div>
CSS: getbootstrap.com/examples/dashboard/dashboard.css
Dashboard (with off-canvas sidebar) - scrollable
HTML
<div class="row row-offcanvas row-offcanvas-left">
<div class="col-sm-3 col-md-2 sidebar-offcanvas" id="sidebar">
<ul class="nav nav-sidebar">
<li class="active">Overview</li>
<li>Reports</li>
<li>Analytics</li>
<li>Export</li>
</ul>
</div>
<div class="col-sm-9 col-md-10 main">
<h1 class="page-header">Dashboard</h1>
</div>
</div>
CSS: http://textuploader.com/k6ae

Bootstrap span's erroneously centered

I'm laying out a navbar and it's coming out all wrong. I want to have a left and right component so I'm using two span6's. But I'm finding that the first span6 is centered on its own line. Chrome's dev tools show the centered div as having the correct dimensions and 20px left-margin -- it's just centered. As if the container is center it?
Here's the HTML for the navigation view:
<div id="group_and_date_controls" class="container">
<div class="row">
<div id="group_control" class="span12">
<ul>
<span id="new_group">New Group</span>
<li class="controlItem">hi</li>
<li class="controlItem">hi</li>
</ul>
</div>
<div id="date_control" class="span6 navbar pull-right">
<ul id="thing" class="nav pull-right">
<li>Jun 12th</li>
<li>Today, Jun 13th</li>
<li>Jun 14th</li>
</ul>
</div>
</div>
</div>
"I want to have a left and right component so I'm using two span6's."
...Except if your code is the same as the code you posted in your question, you are using one span12, and then one span6. Here's a version that uses two span6 classes.
http://jsfiddle.net/FtPZf/
<div id="group_and_date_controls" class="container">
<div class="row">
<div id="group_control" class="span6">
<ul>
<span id="new_group">New Group</span>
<li class="controlItem">hi</li>
<li class="controlItem">hi</li>
</ul>
</div>
<div id="date_control" class="span6 navbar pull-right">
<ul id="thing" class="nav pull-right">
<li>Jun 12th</li>
<li>Today, Jun 13th</li>
<li>Jun 14th</li>
</ul>
</div>
</div>
</div>

Bootstrap: ordered list with divs not aligning

I'm using Bootstrap to create a website. I need to create an ordered list that has text then an image next to it. For some reason, the content of the list is shifted by one line so that it looks like this:
1.
text here [ image here ]
2.
text here [ image here ]
How do I get it to align properly?
here is my code:
<ol>
<li>
<div class="span12">
<div class="span6">Test</div>
<div class="span6"><img src="asdfd.png"></div>
</div>
<div class="clearfix"></div>
</li>
<li>
<div class="span12">
<div class="span6">Test</div>
<div class="span6"><img src="asdfds"></div>
</div>
<div class="clearfix"></div>
</li>
</ol>

Resources