Using Bootstrap affix while maintaining responsive column layout - html

Please see this fiddle. I have a main content div and a sidebar, which I want affixed to the top of the page as the user scrolls. Everything works fine, except for when viewed in mobile:
Without the affix stuff, the columns behave as Bootstrap columns should and the sidebar falls into place directly below the main div. But with affix, the div simply disappears.
I have sort of fixed this using a media query:
//Override affix on small screens:
#media (max-width: 750px) {
.affix {
position: static;
}
}
This puts the div where it should be on small screens and reverts to the affix layout on Desktops. However, there is a void in the middle where it just disapears. As you drag the window in, around halfway it disapears, then repeareas in the correct position as the window is dragged smaller still. I've tried adjusting the 750px value, but haven't been able to come up with a figure which actually works.
How can I reconcile the grid layout and the affix switch on/off? How do I know where the breakpoint will be - should I avoid using a specific number of PX and take another approach to this issue?
My current Bootstrap layout is (I've added the height:500px so you can see the scroll behaviour in JS Fiddle - it is not present in my actual code):
<div class="container-fluid">
<div class="row" id="content">
<div class="col-md-8" style="height:500px">
Main content
</div>
<div class="col-md-4">
<div class="affix" data-spy="affix" data-offset-top="0">
Side content
</div>
</div>
</div>
</div>
Many thanks

I'm not clear on where you would like the Affix to be on mobile, either to the right of the content or beneath it, but I'll try to help:
In your Fiddle I am not seeing a point where the Affix momentarily disappears, but I do see it react as expected with the grid system classes. Ie: the col-md-* divs expand to 100% width at 992px.
The Media Query breakpoint for col-md-* is 992px. (Unless you have reset it in your copy of Bootstrap.)
If you would like to maintain the same width ratio that you have on desktop, I would suggest swapping out your classes from .col-md-* to .col-xs-*
So .col-md-8 becomes .col-xs-8 and .col-md-4 becomes .col-xs-4 -- but then your main content would be quite narrow on mobile.
Not sure if that's what you are going for?

Related

How to bring left sidebar below the content for mobile view in bootstrap?

In my bootstrap web page i have a left sidebar and besides it i have the page content. The HTML code is:
<div class="col-sm-3">Sidebar</div>
<div class="col-sm-9">Content</div>
I like the view for laptops and bigger screens but on screens <768 px wide (tablets and smartphones). The divs slack and the sidebar comes on top of content div.
I know this is a bootstrap feature but i want it to slack another way- i want the content to be at top of sidebar on screens <768 px wide.
You can view this thing on the jQuery page. Opening the page on smaller browser view will show what i mean.
Can this be done in bootstrap? I definitely want to the design to remain same for laptop and bigger screen.
And i don't want to apply any custom media query for this. Can bootstrap provides a solution for things like this? Please help. thanks
Push and Pull solution
If you can reorder the divs in your html you can utilize the push and pull from bootstrap.
<div class="col-sm-9 col-sm-push-3">Content</div>
<div class="col-sm-3 col-sm-pull-9">Sidebar</div>
Update Bootstrap V4 Alpha
Change the order of your grid columns using the push-md-* and the pull-md-* modifier classes.
Example
<div class="row">
<div class="col-md-9 push-md-3">Right Content</div>
<div class="col-md-3 pull-md-9">Left Sidebar</div>
</div>
You can use direction: rtl; on you container, and direction: ltr; on your columns, with the appropriate media queries.
HTML:
<div class="row-rtl">
<div class="col-ltr">Main</div>
<div class="col-ltr">Sidebar</div>
</div>
CSS:
.row-rtl {
direction: rtl;
}
.col-ltr {
direction: ltr;
}
I solved it using the col-md-push-*, i also changed the order of my columns first then applied the push. This is the final code.
<div class="col-sm-9 col-sm-push-3">Content</div>
<div class="col-sm-3 col-sm-pull-9">Sidebar</div>
What is is doing with push and pull is that when the screen size is greater than sm meaning in md-* and lg-* then is is pushing the content div and pulling the sidebar - meaning for screen size ≥992px sidebar div comes first then comes the content div.
For in sm screen size (<768px) it behaves normally based on what the order is specified in the html.

Dsplaying content in a carousel only at a certain width not working

I'm trying to display content in a carousel only when the viewport width is less than 961px. As the display window gets smaller I see my content display horizontally (desired), then stack vertically (undesired) then disappear all together (also undersired). I don't want it to stack vertically. Just horizontally and then show in a carousel. But as stated before it disappears when it's suppose to be in a carousel and I can only see the navigation arrows. I would also like the content to be centered when in a carousel. I believe there is something wrong with my media queries, but I also think there's more to it than that. Can I use jQuery to accomplish this? Here's a link to a codepen i created. (FYI: the navigation arrows do not show in the codepen but i can see them in my browser window)
http://codepen.io/anon/pen/KVwGeB
Check this pen. I hope this is what you are looking for.
use col-md for medium screen and col-sm for small screens such as ipad and tabs and col-xs for mobile devices.
div#why-cs div:nth-child(1){
display: none;
}
the above code causing the disappearing of carousal
http://codepen.io/jinukurian7/pen/RrNzoL

Possible to convert container/row to container-fluid/row-fluid at viewport breakpoint?

For the purpose of learning Bootstrap, I'm copying http://www.newsweek.com/ (using as vanilla Bootstrap as possible) and the top bar (sign in, register, etc.) has me stymied. With a large viewport, it appears to be a simple container/row, but as it resizes and gets to a medium viewport, instead of breaking it seems to transition to a container-fluid/row-fluid.
I set up a tester in Codepen with every possible combination of containers and rows fluid and responsive independent and codependent (that I'm aware of) to figure out what was going on and to experiment a bit:
http://codepen.io/spectre6000/full/vOzeBB/
At a 1200px viewport width (as indicated below the rulers),
<div class="container">
<div class="row">
...
</div>
</div>
and
<div class="container-fluid">
<div class="row-fluid">
...
</div>
</div>
...are identical. It seems this is what the Newsweek site is doing, but I can't find a way to do it myself without coding the bar twice with different visibility.
How do you switch from one container/row setup to the other at the breakpoint?
Add a media query! Use the container class, then do something like this (assuming your container has the id #myContainer):
#media (max-width: 1200px) {
#myContainer {
width: 97.5%; /*this gives it the precise width to match the Bootstrap defaults*/
}
}
The width attribute is pretty much the only real difference between container and container-fluid, so this just makes your container emulate a container-fluid.
In the latest Bootstrap 4.4 you can use:
<div class="container-xl">
<div class="row">
...
</div>
</div>
This will start off width: 100% ('container-fluid') and then switch to 'container' when you reach your 'xl' breakpoint (normally 1200px).

Converting non responsive three column lay-out to bootstrap three column lay-out

So i have an website using a three column lay-out with a fixed width of 1000px. I want to convert this to an bootstrap responsive lay-out. What i did was the following:
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-push-2">Main</div>
<div class="col-lg-2 col-lg-pull-8">Left</div>
<div class="col-lg-2">Right</div>
</div>
</div>
I've set the container width for #media (min-width: 1200px) to width : 1000px. The problem i have now is that my sidebars are to small and the middle column is too wide. Changing the left and right col to col-lg-3 makes the colum to wide and the center column to small. I know bootstrap works with percentage so my question is, is this just how bootstrap works and i have to deal with it? Or is it somehow possible to set an fixed width to the sidebars? or is there an other way to make this happen?
thanks
This is how Bootstrap works. If you want to adapt it to your own liking, you should give your Main, Left and Right divs a class of their own and just adapt the % in your CSS.
Just be aware that creating your own %-width DOES NOT make it responsive! What I mean to say is that your divs will resize according to the browser-width, resulting in a very skinny website on mobile phones. Best is to combine this solution with Bootstrap, so Bootstrap takes over whenever your browser gets under X pixels wide, or to write your own #media and change the look of your website according to the width of the page.
Edit: Of course you could also try and override the bootstrap width in your own CSS, but this might result in some weird things when you use the same col-width again on another page.

Links stop working at the tablet viewport ( 768px to 991px ) in Wordpress

I really can't explain why this is happening but I am building a WP theme in BS3, for some reason, on the tablet viewport (768 to 991px) my links stop working. They are not clickable, tappable, tab-able, etc.
What causes this strange phenomena? How do I even diagnose when my site is W3C Compliant?
Ugh... the horror!
I really don't have code to support this, but I could paste my entire page on here. I will do that on request, or my CSS file, etc.
When using bootstrap .col-* DIVs should reside in .row DIVs and in turn .container DIVs. I can see in your html that you have 2 top level DIVs with a class of .col-*, and they have different screen sizes associated with them. Your footer DIV has a class of 'col-lg-12 footer area' which means when it gets below 991px it will stop floating, while the rest of your content floats, which is whats causing the issue.
If you change the footer class to: 'col-sm-12 footer area' - this will solve the issue.
But what you ideally need to do is remove the col-sm-12 from your footer and page-wrap altogether and replace it with 'container' so they look like: <div class="container footer area">