Matching column height in 2column layout - html

My website uses 2 columns, but the only way I've been able to get the columns height to match is to use a fixed height, but this presents a "scrollbar in a scrollbar" issue where the content column has to have overflow: auto; for all the content to be seen, but if the user's browser doesn't make the entire page visible at once, both the page and the content column have scrollbars.
What I would like to do is match the sidebar columns height to that of the content column.
I was thinking of setting some javascript on page load to do it, but I can't help thinking theres a better way.
The site in question is http://www.pcbuddies.co.za (for reference).
Any suggestions would be greatly appreciated.
Thanks in advance!
EDIT 1
After applying the JQuery solution below, I'm happy with the result (mostly).
Where I do have a problem is when the first section (sidebar) of every page (navbar) is smaller than another section see http://www.pcbuddies.co.za/Services/Default.aspx.
In this situation, the content is overflowing past the site's footer.

I wrote out a solution but I was paraphrasing a better example at this site here, which I find works very well. It uses a trick to create the equal height columns but works very well - without any javascript.
Here's an example of it in action: example

The other solutions look a bit too complicated to me. How about this:
Set both of your columns to transparent background and make a container for both of them with the desired background as alpha-transparent png.
Maybe not the "cleanest" solution, but definitely a simple one. Looking at the website you linked, that's what I'd go with.

I always catch grief for suggesting this, but I've found the best, most dependable way of doing this is to utilize Javascript (in this case, jQuery) to make all of the columns the same height as the tallest column. See my live example.
Live Demo http://jsfiddle.net/T9VUc/1/
If you want to do this on the page load, try this. Keep in mind, this procedure uses jQuery, so you will need to include that in your page
var tallest=0;
$(document).ready(function() {
$('.col').each(function(){
if($(this).height() > tallest)
tallest = $(this).height();
});
$('.col').css('height', tallest + 'px');
});
Live Demo on Page Load http://jsfiddle.net/T9VUc/2/
UPDATE
Based on the URL you gave me, I suggest adding <div style='clear:both'></div> to the end of your 2nd div like this ...
<div id="Side" class="col">
...
</div>
<div class="content col">
...
<div id="network" style="display: none;">
...
</div>
<div style='clear:both'></div>
</div>

Related

Image Table in HTML

I want to do exactly like this for my self-hosted wordpress site - http://www.dota2.com/heroes/
I assume they put separate pictures in a table (could be completely wrong)
Any suggestions on where should I start ?
Actually if you check the source code you can see that they are using DIV to place the element like they want. You can do it with a table too if you want (it could be easier!).
If you want to do it "exactly like them" you can make a container with a fixed width, and they insine you could add your images with a fixed width.
I would also advise you to check "Source Code" ! It will be very helpful (I think)!
(If you are using chrome as main navigator : https://support.google.com/adsense/answer/181951?hl=en)
Hope it helped you
I would avoid table. From my experience, tables are hard to work with.
I would rather go with <ul><li></li></ul> or <div class="container"><div class="pic"></div></div>
The <li></li> or <div class="pic"> will have float:left so that they get rendered one after another.
If you feel that the data you are rendering are actually a table, then only table makes sense.
Your data is not a table with multiple columns.

how to arrange divs with css as a grid?

I want to present dynamically generated (PHP, XML) questionnaires to the user in the browser like this:
requirements:
1. The left column will will always be a number, the middle and the right column may swap position in some questionnaires.
2. There will be questionnaires with 200 items or so over multiple pages.
3. The width of the container (rounded corners) is fixed at 800px at this time, BUT
4. it has to be flexible / fluid in the near future for being displayed on mobile devices like iPad and iPhone
what I've tried
I experimented both with a <table> based and a <div> based layout:
The <table> was clean and simple, but with lots of overhead and not very flexible, e.g. if I swapped middle and right column for item #2 only...
The <div> based layout was sleeker, I let the containers float, but have to set the divs to a fixed width in order to get them align in columns. In a fluid design, I do not know the widths in advance, which will be a mess then...
questions to the pros:
1. <table> or <div>, regarding my requirements above, what would you prefer?
2. is there some magic tool to make this nice and easy?
3. would you rather serve the raw data and let a client-side script (jQuery) do the positioning instead?
Here's a code example: http://codepen.io/anon/pen/inmwD
Either use a wrapping div or a list element
<div class="parent">
<div class="row">
<div class="col1">1</div>
<div class="col2">Content</div>
<div class="col3"><input type="radio"/></div>
</div>
</div>
In my opinion <table> is for tables <div> is for layout.
Yes there are some style templates usually named grid system or css grid take a look at this stack : https://stackoverflow.com/questions/76996/what-is-the-best-css-grid-framework
I wont arrange elements around with JavaScript unless it can't be done with css or is a special requirement from the marketing guys. The con about this is that you increase the page render time.
Take a look at this fiddle made with a custom 960 grid system that have 6 columns with the width 150px
Fixed width: http://jsfiddle.net/UjXPR/
Fluid width: http://jsfiddle.net/UjXPR/1/
960 gs customizer: http://grids.heroku.com/
Checkout bootstrap grid system
1. <table> or <div>, regarding my requirements above, what would you prefer?
div is specially used for layout of the page and table is specially used for placing tabular data. so in your condition I would choose the table layout for the questionnaire.
2. is there some magic tool to make this nice and easy?
First dream to design how should this row data look then only accomplish for the site.
3. would you rather serve the raw data and let a client-side script (jQuery) do the positioning instead?
This is not good idea but if the clients need so you could do that.
And one more thing, you are not asking for your problem with SO but asking what we like, this is not good practice for SO users.

Setting "scrollTop" for overflowing element via HTML/CSS (without javascript)

Suppose I have the following html:
<div style="width:200px;height:200px;overflow:scroll">
...
</div>
If the stuff in this div ends up overflowing, the most popular way to change the scrolling position of this item is to use jQuery.scrollTop(). However, I have a situation where I would like to set the initial scroll position of the div using the source HTML. Is there a way of doing this? All examples I see online for doing this end up using javascript.
One way I tried is to write a scrollTop property on the element, like so:
<div scrollTop=20 style="width:200px;height:200px;overflow:scroll">
...
</div>
However, this does not work. Surely, there must be a way to set the initial scrolling position of an overflowing item via HTML/CSS...
Here is a full version of this code that illustrates that it doesn't work- The vertical scrollbar remains at "0": http://jsfiddle.net/gueBZ/1/
Can anyone help me to make it work? Thanks so much for any pointers!
<div style="width:200px;height:200px;overflow:scroll">
<br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<div id="hello">autoscroll here</div>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br>
</div>
then open the page as
page.html#hello
this is the only thing you can do, with HTML only

How do I push a header alongside part of a container?

I've got some HTML:
<div id="thing">
<div id="contentheader">
<h3>Header</h3>
</div>
<div id="contentcontainer">
<div id="image">
<img alt="balt" src="imagesrc">
</div>
<div id="body">
<p>hegl gegl</p>
</div>
</div>
</div>
I need to push the h3 in 'contentheader' down alongside the image in 'contentcontainer' while having the body text sit alongside it. Everything is of variable width save the image.
Perhaps an image will demonstrate better:
As you can see, grey corresponds with 'thing', green with 'contentcontainer' and blue with 'contentheader'.
Editing the HTML would be a major hassle. I also can't make anything other than the image fixed-width. Is it possible to do it with just CSS? (It'd be awesome to be able to do it with floats and stuff but I don't know if it's doable)
I don't think you're going to find a perfect solution with CSS. You could use positioning but you would probably run into issues if you had a long title that ran more than one line.
If you're open to using javascript the following non-framework snippet would work.
// Add the header inside the container div just before the body
containerDiv = document.getElementById('contentcontainer');
headerDiv = document.getElementById('contentheader');
bodyDiv = document.getElementById('body');
containerDiv.insertBefore(headerDiv, bodyDiv);
You could recreate this code as a neater, one-liner using jQuery or another javascript framework.
Sure, heres the Css for a rudimentary setup:
http://jsfiddle.net/Nkapr/
Ask if you have any questions.
The problem here is the HTML structure, it's not been written really with your goal in mind (which is a bummer!)
If all you're after is pushing the H3 container 'contentheader' down in line with the rest of the stuff inside 'contentcontainer' you could set a negative top margin on 'contentcontainer' to pull it upwards, and then add a positive top margin to the elements in 'contentcontainer' which need to go down (in this case 'image') giving the impression that the h3 section actually sits in with the rest of the content. It's a bit of a hack but it might do the trick if you can't alter the HTML.
Thirtydot's answewr in the comments section solved my issue.

CSS: Force text to wrap (OR defining element width by only one of its children)

Okay, this is a weird one to me. Here's the HTML element I'm working with:
LOLZ http://www.ubuntu-pics.de/bild/14571/screenshot_030_0O2o3D.png
A photo with a caption. Ideally, I'd like it to look like this, through pure CSS:
alt text http://www.ubuntu-pics.de/bild/14572/screenshot_031_mp84u7.png
The width of the image's parent element needs to be dependent on the image's size.
I can change the markup all I need to. (The text isn't currently in its own div, but it can be if necessary.) Is there any way in CSS to accomplish this? I get the impression that I need to "force" the text to wrap as much as possible (which doesn't seem achievable), or make the whole element's width dependent on just one element and ignore the other (which I've never heard of before).
Is there a real way? Or do I need to use magical Javascript instead? (The JS solution is fairly simple, but fairly lame...)
Check out this great article on the best ways of handling the image-with-a-caption scenario.
Personally this is one of those cases where you gotta suck it up and go with that works.
Make the container a table with table-layout:fixed and put the image in the top row. You can also do this with pure CSS using the display:table-* properties (and the IE7-js library for IE6 compatibility).
What table-layout:fixed does is make the table drawing algorithm lock the width of each table column once the width of the first cell in that column is known. The caption will have nowhere to expand to so it will wrap to the width of the image (the first cell).
Alright, it looks like there's no simple solution that I can pull off. Thanks for helping me work that out :)
I think that, given how I'll be storing those images, accessing width won't involve constant recalculation. I may just use that server-side magic instead.
Thanks!
Here's a solution that probably does not work for you even though it does produce the layout you requested:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style>
div.a {float: left;
position:relative;}
div.b {
position: absolute;
top: 100%;
left: 0;
right: 0;
text-align: center;
background-color:gray;}
</style>
</head>
<body>
<div class="a">
<img src="http://stackoverflow.com/content/img/so/logo.png" alt="">
<div class="b">Caption text Caption text Caption text Caption text Caption text </div>
</div>
</body>
</html>
You see the reason why it is unsatisfactory if you place some content below the div a. It will overlap with the caption, because the absolutely positioned caption did not extend the parent div vertically. It still may work for you if you have enough white space below anyway or you are willing to reserve it.
I came up with a working and fairly clean solution.
The solution uses a table (or div with display:table if you prefer) and adds a second column to "push" the first cell into the minimum space it really needs. The table can be set to 1px width to stop it growing across the page. I've put together a demo to show this in action:
http://test.dev.arc.net.au/caption-layout.html
Tested and working in IE8, Firefox and Safari/Win
The table answer would work. Easily. I can't encourage its use but ease-of-use does have merit. I was going to suggest using the clip: CSS property, but I can't get it to work on my local machine (for some reason, though it renders the example at cssplay.co.uk perfectly).
The downside of this is that it probably only works if you define fixed-widths for the containers. I'm sure there must be a way, though. I'll keep looking.