Scroll bar in a div in zurb foundation 3 - css

My question is very simple. But I have googled and googled and googled but not found an answer.
I have a simple layout in zurb foundation 3
<div class="row" id="wcont1">
<div class="three columns" id="wcont1a">
</div>
<div class="six columns" id="wcont1b">
</div>
<div class="three columns" id="wcont1c">
</div>
</div>
I want that when the wcontb column is populated, it should not expand beyond a particular point (defined by me) but instead it should be scrollable vertically using up and down arrow icons.
I am a novice. I will highly appreciate a detailed answer and a working example using zurb foundation 3.

You have two concerns here:
That you want to limit the height of the middle div (wcont1b) so the content is scrollable when it reaches a particular point.
That you want a pretty way of doing it
Please take note that the two concerns are separated issues. So let's tackle the first one and using Zurb Foundation 3.2.2 you can layout your three divs like so:
<div class="row" id="wcont1">
<div class="three columns" id="wcont1a">
<div class="panel">
Content goes here...
</div>
</div>
<div class="six columns" id="wcont1b">
<div class="panel">
<h4>Content goes here...</h4>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
<li>10</li>
</ul>
</div>
</div>
<div class="three columns" id="wcont1c">
<div class="panel">
Content goes here...
</div>
</div>
</div>
I populated wcont1b so we can see the scroll bar in action. I also put the sample contents inside a zurb panel (using the panel class) so you can better see how the divs are separated and how the scroll bar behaves (I'll show you two approaches).
Ok so now you have that tall div ('wcont1b`) at the center and we want it to be of a certain height so it will not consume much space, especially when viewed on a mobile (although personally I prefer having a tall div than a short one with a scroll bar especially if there are contents outside the div and below it). To control the height of the div you need this in your css:
Approach #1
#wcont1b .panel {
max-height: 150px;
overflow-y: scroll;
}
The max-height value is the height limit of wcont1b and definitely you should change it per your requirement. The overflow-y is the one that takes care of the scrollbar. This approach will not be desirable if you have a title in wcont1b and you do NOT want it to scroll along with the content. So to make more pretty you should do this:
Approach #2
#wcont1b .panel ul {
max-height: 150px;
overflow-y: scroll;
}
Notice now that only the list scrolls and the header stay on top. The difference is that your css now targets the ul, the list, and not the entire content or not the entire wcont1b.
With that you now have a height-controlled div. But I think you want the scroll bar to look nice and that's where jquery plugins comes in. You told us you have tried millions but you have not shown us any code and it's important that you do. But let me give an example anyway using jscrollpane that you can get here. Once you downloaded the necessary files and referenced them on your page you need to do the following:
The code you need for approach #1:
<script>
$(window).load(function(){
$('#wcont1b .panel').jScrollPane();
});
</script>
The code you need for approach #2:
<script>
$(window).load(function(){
$('#wcont1b .panel ul').jScrollPane();
});
</script>
That's it, it should solve your problem. If you encounter more issues you need to give as much info as you can so people here can help you better.

Related

Does this Flexbox-based layout require extra markup?

I'm getting into Flexbox now, trying to see how I can transition from using the traditional CSS grids.
I have two layouts: One made with a CSS grid. The other one made using Flexbox. The basic layout for both examples is quite basic: A header, a nav, a content section and the footer.
Design-wise they both look the same and behave exactly the same for RWD. However, in order for me to accomplish the same behavior using Flexbox I had to create a wrapper div around the Nav and the Content sections.
This is the HTML used with the CSS grid layout:
<div class="container-12 clear">
<header class="grid-12">Header</header>
<nav class="grid-4">Nav</nav>
<section class="grid-8">Content</section>
<footer class="grid-12">Footer</footer>
</div>
This is the HTML used with the Flexbox layout:
<div class="main-container">
<header>Header</header>
<div class="site-content">
<nav>Nav</nav>
<section>Content</section>
</div>
<footer>Footer</footer>
</div>
Notice the <div class="site-content"> around the nav and section elements.
So my question is: Is the <div class="site-content"> around the nav and section elements necessary in order to accomplish that layout using Flexbox?
I'm trying to achieve the same layout with the same HTML but different CSS techniques.
Here are the demos:
Basic Layout Using a CSS Grid
Basic Layout Using Flexbox
Thanks for any guidance on this.
The answer is simple: Yes, that extra wrapper is required.
I was able to find this article in Smashing Magazine from 2011 By Richard Shepherd where confirms that sometimes an extra wrapping container is needed in order to treat the child elements with Flexbox. Granted, his article uses the old 2009 syntax, but still, the case applies:
Using flexbox often requires an extra div or two, because the parent of any flexbox element needs to have display set to box. Before, you could get away with the following:
<div style="float: left; width: 250px;"> Content here </div>
<div style="float: right; width: 250px;"> Content here </div>
Now with flexbox, you’ll need:
<div style="display: box">
<div style="width: 250px"> Content here </div>
<div style="width: 250px"> Content here </div>
</div>
Many of you have already turned away, insulted by this extra mark-up that is purely for presentation. That’s understandable. But here’s the thing: once you master the CSS, this extra containing div becomes a small price to pay. Indeed, you’ll often already have a containing element (not necessarily a div) to add display: box to, so there won’t be a trade-off at all.
Extract taken from CSS3 Flexible Box Layout Explained
Thanks.

Tumblr CSS positioning

I'm making a two column Tumblr theme and I need to fix this weird CSS positioning issue I'm having. If you look at the picture provided you can see that there's a gap in between two pictures in the first column. This happens when a picture is smaller than the max-width I guess the rest of the width it just filled with blank space. How can I fix it?
Code:
http://pastebin.com/eY4EsQKH
Picture:
http://i.imgur.com/z8k22cQ.png
jsFiddle:
http://jsfiddle.net/kQVNd
Try this:
1. Divide the content in two columns like this:
<div class="column">
<!-- articles -->
</div>
<div class="column">
<!-- articles -->
</div>
2. Add this CSS:
.column {
display:inline-block;
vertical-align:top;
}
jsFiddle demo.

Links in bootstrap grid stop working in small screen mode

What is required to make links in bootstrap grids work throughout all the media breakpoints ?
In my case, the links work only as long as the grid is not stacked.
This is what the grid looks like:
<div class="row">
<div class="col-md-6">
<a href="#" class="room" style="height: 155.60px; width: calc(25.0% - 4px);"> <span>Item 1</span>
</div>
<div class="col-md-6">
<div class="row">
<div class="col-sm-12">
<p>This is another row</p>
</div>
</div>
</div>
</div>
The working fiddle is here:
http://jsfiddle.net/pTw2j/8/
Edit Thanks for the fast answer. I chose overflow:hidden; at the end to avoid scrollbars while still fixing the issue.
The problem is that the links are floated, resulting in a height of 0 for the parent .storey container.
Setting overflow: auto on the container will fix the problem.
http://jsfiddle.net/pTw2j/13/
.storey {
overflow: auto;
}
This is referred to as "clearfixing." If you're interested in learning more, here are two good articles:
CSS Tricks: Force Element to Self-Clear its Children
David Walsh: CSS Clear Fix
I had the same problem. In my case a better solution was to add the class of "clearfix" to the containing div. Bootstrap has this class built in so you don't have to do anything with your CSS.
Adding overflow:auto will result in a horizontal scroll bar. Best to use clearfix class which resolves the issue.

Vertically Aligning Text with CSS Tables Not Working

I was trying to vertically align some text inside a div using a CSS table, but it doesn't work for some reason:
<div class="navlink" style="width:150px; display:table;">
<div style="text-align:center; display:table-cell; vertical-align:middle;">Some Text</div>
</div>
Any suggestions on how I can get this code to work?
Works for me, you just put table width instead of height.
<div class="navlink" style="width:150px; display:table;">
---> <div class="navlink" style="height:150px; display:table;">
It works, it's simply that you are not using any height for your cell div, so do it like this
Demo
<div class="navlink" style="width:150px; display:table;">
<div style="text-align:center; display:table-cell; height: 200px; vertical-align:middle;">Some Text</div>
</div>
This is the best answer I've found: http://phrogz.net/css/vertical-align/index.html
This comes up a lot. There's no easy answer.
A quote from the page:
A FAQ on various IRC channels I help out on is "How do I vertically
center my stuff inside this area?" This question is often followed by
"I'm using vertical-align:middle but it's not working!"
The problem here is three-fold:
A HTML layout traditionally was not designed to specify vertical
behavior. By its very nature, it scales width-wise, and the content
flows to an appropriate height based on the available width.
Traditionally, horizontal sizing and layout is easy; vertical sizing
and layout was derived from that.
B The reason vertical-align:middle isn't doing what is desired want
is because the author doesn't understand what it's supposed to do, but
…
C … this is because the CSS specification really screwed this one
up (in my opinion)—vertical-align is used to specify two completely
different behaviors depending on where it is used.
The article goes on to explain that there are two basic methods: absolute positioning, and the line-height method in the other answers.

Centered fixed-width layout with fullscreen-width backgrounds

I'm trying to code a layout somewhat similar to SO.
It has a centered container with typical blocks: header, navigation, content area and footer. This blocks have different background-color. The problem is, I want the background to be 100% of the screen width.
You can see this in SO's userbar at the top of the screen.
Also I made an example picture. Note, that there shouldn't be any vertical borders, they're just to show the content area.
I've checked SO's html source but it didn't tell me anything
So, what are my options?
My first idea was to make a wrapper div for each section which handles the background, and another content div inside of it with width:950px and margin:0 auto
But it seems to me very inefficient.
Is there a nicer way to make it?
I've ended up with this structure:
<body>
<div id="header">
<div id="logo-container" class="wrap">
<div>...</div>
</div>
<div id="navigation" class="wrap">
<div>...</div>
</div>
</div>
...
<body>
and the style looks like
#... {
background:#...
}
.wrap div {
width:950px;
margin:0 auto;
}
Thanks everyone.
What I do in cases like that is style the html or body with the main background color (the one for your content), then keep the header and footer out of the main wrapper and size down their contents as needed, so I'd end up with something like so (which I think is similar to what you're saying you did, but with a couple minor differences):
<body style="background: #000;">
<div id="header" style="width: 100%; background: #666;">
<div id="nav" style="width: 100%; background: #999;">
<ul class="navigation" style="width: 950px; margin: 0 auto;">
</ul>
</div>
</div>
<div id="contentWrap" style="width: 950px; margin: 0 auto;">
Whatever content stuff, other divs, etc.
</div>
<div id="footer" style="width: 100%; background: #999;">
</div>
</body>
You don't really need extra wrappers if you have only a couple block level elements in your header and footer, so you end up with about the same number of divs as if you had them all in one wrapper. You can also keep their sizes in sync if you put them in one CSS call with the size. It might sacrifice a little bit in the way of CSS efficiency, but in my experience, it's a small enough trade off that it's not worth losing sleep over, since either the site is small enough that it doesn't matter, or large enough that there are better efficiency increases in places like the images, javascript, and server-side code.

Resources