Restrict height of CSS table - ignore content height - html

I am having trouble with a CSS table I am using for layout. Not a traditional table but a set of div's using display:table etc.
The problem is that it works great when one of the cell div's is empty, however as soon as I add content to it, the table stretches to accommodate the content.
#dispcontainer {
display: table;
width:100%;
height:100%;
overflow-y: scroll;
max-height:100%;
table-layout:fixed;
border-collapse:collapse;
}
.disprow {
display: table-row;
width:100%;
}
.dispcell {
display: table-cell;
width:100%;
height:100%;
}
The HTMl:
<body>
<div class="box">
<div class="content">
<div id="dispcontainer">
<div class="disprow">
<div class="dispcell">
<img class="heading_img" src="img/heading.png" /><br />
<div class="nav_buttons">
<?php include("menu.html"); ?>
</div>
</div>
</div>
<div class="disprow">
<div class="dispcell">
<div style="height:100%;overflow:hidden;">
<?php include("tumblr/tumblrFeed.php"); ?>
</div>
</div>
</div>
</div>
</div>
<?php include("social_buttons.html"); ?>
</div>
<div id="contactBar"><?php include("contactDetails.html")?></div>
</body>
And the website proper is here: http://fadeinfuture.net/users/tbw/test2.php
I just don't understand how to get the table to never become taller than it's containing div.
I got it working with regular <table>'s, however Internet Explorer didn't like it basically with the same problem.
The reason for this layout is that I want the heading to be fluid depending on the screen width and the area below to take up the rest of the screen.

Try moving your overflow-y: scroll; to the box div.

You can use JavaScript and jQuery. (with pure css it MAY BE more difficult)
<script>
$(function() {
$("#parent").height($("#child").height());
});
</script>
I use something like that on my website.

Related

How to keep divs from breaking while keeping them centered

I've got a red box and a green one, side-by-side, and centered. When the browser width is smaller than the width of the squares, they break into separate lines. How do I keep them together?
(I tried using a container div with their combined widths, which does the job in keeping them together, but they no longer are centered.)
Any suggestions?
The code:
<body>
<div style='text-align:center;font-size:0'>
<div style='display:inline-block;background-color:red;width:200px;height:50px'></div>
<div style='display:inline-block;background-color:green;width:200px;height:50px'></div>
</div>
</body>
You can run it here: https://plnkr.co/edit/2De21ziNmaeleFmkPuPF?p=preview
This can be done in many ways, here is 3:
Use min-width
<div style='text-align:center;font-size:0; min-width: 400px'>
<div style='display:inline-block;background-color:red;width:200px;height:50px'></div>
<div style='display:inline-block;background-color:green;width:200px;height:50px'></div>
</div>
Use white-space: nowrap
<div style='text-align:center;font-size:0; white-space: nowrap'>
<div style='display:inline-block;background-color:red;width:200px;height:50px'></div>
<div style='display:inline-block;background-color:green;width:200px;height:50px'></div>
</div>
Use display: flex;
<div style='text-align:center;font-size:0;display: flex;justify-content: center'>
<div style='display:inline-block;background-color:red;width:200px;height:50px'></div>
<div style='display:inline-block;background-color:green;width:200px;height:50px'></div>
</div>
Try using Flex-box
.parent{
display:flex;
border:1px solid green;
width:500px;
}
.parent div{
background:green;
width:100px;
height:100px;
margin:20px;
}
<div class="parent">
<div>cell1</div>
<div>cell2</div>
</div>
Hope this helps
If you give them a fixed width (ex 200+200px), when that div width is passed (ex mobile width of 375px < 400px of divs sum), the last element slide on the next row.
With width of 35% for each other, will look exactly as you want it for that 200px.
<body>
<div style='text-align:center;font-size:0; width: 100%;'>
<div style='display:inline-block;background-color:red; width:35%;height:50px'></div>
<div style='display:inline-block;background-color:green; width:35%;height:50px'></div>
</div>
</body>
Here is the link to your code
EDIT:
Here is a usefull link for understanding better the width options depends of the width of device, and I encourage you to take a deeply look inside of w3schools, or other platforms where you can learn better how to manipulate elements of html, with css and js.
screen-width
Try using width: 50% on the boxes instead of width: 200px.

Make a div stretch across the page overflowing its containing div

I am having difficulty making a div stretch across the page overflowing its containing div.
I am using WordPress child theme of twenty thirteen theme importing bootstrap CSS file only, no JavaScript files (yet anyway!).
I am using this div called section to add styling just to add a background image or colour like this websites orange section please see link below:
Flat Web Design
I have tried
position: absolute;
left: 0;
right: 0;
but position: absolute seems to play havoc with the grid.The section div appears in the correct place, however the following divs sit on top of the "section" div.
I am aware of HTML5 section tag. But as I understand it, it is not best practice to use section for styling only, but to use a div instead? However I have experimented with the section tag and I have the same problem.
I hope someone can advise how I can make a div stretch across the page overflowing its containing div? Can this be done without position absolute?
Thanks in advance
My MarkUp
<div id="content" class="site-content" role="main">
<div class="entry-content">
<div class="container">
<div class="section">
<div class="row">
<div class="col-md-4">
<?php the_field('title'); ?>
</div>
<div class="col-md-4">
<?php the_field('content'); ?>
</div>
<div class="col-md-4">
<?php the_field('image-item'); ?>
</div>
</div>
</div>
</div>
</div>
</div>
My CSS
.entry-header,
.entry-content,
.entry-summary,
.entry-meta{
margin: 0 auto;
max-width: 1150px;
width: 95%;
}
.section{
background:#e8e5ce;
position:absolute;
left:0;
right:0;
}
To achieve this kind of layout you can't use a single container, each section should have its own .container element, this way the section covers the width of the window but the content is centered:
HTML
<div class="section">
<div class="container">
<div class="row">
<div class="col-md-4">
<?php the_field( 'title'); ?>
</div>
<div class="col-md-4">
<?php the_field( 'content'); ?>
</div>
<div class="col-md-4">
<?php the_field( 'image-item'); ?>
</div>
</div>
</div>
</div>
CSS
.section{
background-color:#e8e5ce;
}

map and fixed side bar with bootstrap

I'm using bootstrap to do a simple version of something like this: http://techlist.in/
Basically, I want to have a map and a right side bar with a fixed size and fixed position.
I've started with something like:
HTML:
...
<div class="container">
<div class="span10">
<div id="map_canvas">
</div>
</div>
<div class="span2" style="position:fixed; right:0">
Some stuff
</div>
</div>
...
CSS:
#map_canvas {
display:block;
position:absolute;
height:auto;
bottom:0;
top:0;
left:0;
right:0;
margin-top:40px; /* used for the top navigation bar */
}
But this is not working as expected, as the map remains 100% width and the "some stuff" label appears on top of the map. Any hints?
UPDATE
In fact, I already have the nav-bar, but I did not detailed it in the code, my bad. So basically the whole structure of the html page is (with the missing row div added):
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
...
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="span10">
<div id="map_canvas">
</div>
</div>
<div class="span2" style="position:fixed; right:0">
Some stuff
</div>
</div>
</div>
<!-- include javascript stuff -->
...
</body>
The css file is:
#map_canvas {
display:block;
position:absolute;
height:auto;
bottom:0;
top:0;
height: 90%
width: 80%;
left:0;
right:0;
margin-top:40px;
margin-right:200px;/* used for the top navigation bar */
background: #ccc;
}
If a leave 200px of right margin for the map, how can I fill the margin with the sidebar ?
Basically, I need a side bar of 200px width and the map adapting accordingly on screen resizing.
UPDATE 3
I'm wondering if I really need to use container / row to achieve this layout in fact (I still do not manage to have this working as expected). As I only need to have a map and a sidebar (that should always remain on the right of the map even if the window is resized), would it make some sense to use basic div / css and not bootstrap classes ?
This is basically what I needed: http://jsfiddle.net/kuXYq/4/
have a look at this fiddle I made it might help.
http://jsfiddle.net/eKQGD/
I used percentages to keep things the same
#map_canvas {
display:block;
position:absolute;
height:auto;
bottom:0;
top:0;
height: 90%
width: 80%;
left:0;
right:0;
margin-top:40px;
margin-right:150px;/* used for the top navigation bar */
background: #ccc;
}
There are a few parts to the answer to this question.
The first thing to point out is that it's a little hazy as to why there is the requirement of a "fixed size and position", and by that I mean that the terminology being used may be throwing off your thinking a bit. Typically, you only need to use the "fixed" css position property if you plan on the page having scroll bars and you want the element to stay in the same position on the page no matter what. In this case, it doesn't seem like you want page scrolling at all since the map will appear to be the same size as the entire page. It seems like what you really want on the sidebar is for it to be a fixed height (aka the height of the browser window) with overflow set to scroll.
Secondly, it appears that you're missing a <div class="row"></div> tag around your elements - a tag with a "row" class is necessary to make the bootstrap "span" classes work.
Lastly, here is something that I would go with if I was trying to duplicate the link you posted, using a bit of JS love as well: http://jsfiddle.net/kzBkA/5/ (background colors added just to show what it looks like )
HTML:
<div class="container">
<div class="row">
<div class="span10">
<div id="nav_bar">
Nav bar goes here
</div>
<div id="map_canvas">
test
</div>
</div>
<div class="span2">
<div id="sidebar">
Some stuff
</div>
</div>
</div>
</div>
css:
#nav_bar {
height:40px;
background-color:blue;
}
#map_canvas {
background-color:green;
}
#sidebar{
background-color:red;
overflow-y:auto;
}
js:
$(function(){
$("#map_canvas").height($(window).height() - 40);
$("#sidebar").height($(window).height());
});
UPDATE:
So - again, first off, I encourage you to reconsider your use of fixed elements. You seem to be trying to build a page that won't scroll, but then using a "positioning" feature that's specifically for scrolling (position:fixed), which basically tells all your nice bootstrap code to be ignored and just put it where you tell it. A much nicer way to do this would be to use Bootstrap to your advantage. I changed the row class to row-fluid, I moved your nav bar into the span10 with the map (since that's how wide you actually want the nav, or at least that's how it was in the example), I removed the "navbar-fixed-top" class since you don't actually need things to be fixed, and removed the fixed positioning from the sidebar (since again that's basically making it ignore what you're trying to do). Check out the updated jsfiddle: http://jsfiddle.net/kzBkA/7/ - you may have to tinker with the JS to get the map_canvas div set with the correct height, but otherwise this should take care of making your page fluid when the browser is resized without having to add a ton of unnecessary CSS rules. In general, if you use a scaffolding framework, you should use it to your advantage to avoid creating cluttered, messy css with lots of "width:80%; height:20%; margin: ..." - the whole point of using the framework and scaffolding was to avoid that kind of code :)
HTML:
<div class="container">
<div class="row-fluid">
<div class="span10">
<div class="navbar navbar-inverse">
<div class="navbar-inner">
navbar
</div>
</div>
<div id="map_canvas">
map goes here
</div>
</div>
<div class="span2" id="sidebar">
Some stuff
</div>
</div>
</div>
CSS:
.container{
max-width:100%;
}
#map_canvas {
background-color:green;
}
#sidebar{
background-color:red;
overflow-y:auto;
}
JS:
$(function(){
$("#map_canvas").height($(window).height() - 40);
$("#sidebar").height($(window).height());
});
UPDATE 2
Just realized I missed the part about the sidebar always being 200px but the map width being fluid. I've updated the fiddle to reflect that as well as updating so that sizes get reset when window is resized - http://jsfiddle.net/kzBkA/9/
HTML:
<div class="container">
<div class="row-fluid">
<div class="span10 left-col">
<div class="navbar navbar-inverse">
<div class="navbar-inner">
navbar
</div>
</div>
<div id="map_canvas">
map goes here
</div>
</div>
<div class="span2 right-col" id="sidebar">
Some stuff
</div>
</div>
</div>
CSS:
.container{
max-width:100%;
}
#map_canvas {
background-color:green;
}
#sidebar{
background-color:red;
overflow-y:auto;
}
.right-col{
width:200px;
}
JS:
$(function(){
resizeElements();
window.onresize = function(event) {
resizeElements();
}
});
function resizeElements(){
//set height
$("#map_canvas").height($(document).height() - $(".navbar").outerHeight() - 20 /*not sure where this is coming from, possibly the scrollbar?*/);
$("#sidebar").height($(document).height());
//set width of left col
$(".left-col").width($(document).width() - $(".right-col").outerWidth() - 20 /*not sure where this is coming from, possibly the scrollbar?*/)
}

How to center align a Div correctly?

I am having trouble correctly centering my website
It seems to be centered when I zoom out. but to a user that doesn't zoom out it looks out of place. any suggestions? the site was created with all AP divs it doesn't center correctly even when trying to use the following:
<div align="center">
Try margin:0 auto; for the container div it will center align your div :)
See the example
See the fullscreen view of the result
your design is not correct in my opinion. you must:
<body>
<div id="wrapper">
<div id="header">
from apdiv1 to 31
</div>
<div id="content">*/instead of blockquote*/
put content
</div>
<div id="footer">
put content</div>
</div>
</body>
with css
body{background-image:concrete bkg.jpg}
#wrapper{margin:0 auto}
more more more...
brgds
In css
add property
body
{
text-align:center;
margin:0 auto;
}

How to align divs horizontally withput letting them fall down when the page border is reached?

I have this problem. I would like to create a page showing/displaying a series of items in horizontal flow. It means that I want them to align horizontally, but they have to stay in a horizontal line even if they reach the border of the page (yes, I want the horizontal scrollbar to eventually display, it does not bother me, on the contrary, it is needed.).
NOTE:
Please, accordingly to recent design models, please I would like to avoid using tables... just divs...
How can I achieve this?
Place them all inside a white-space:nowrap container.
<style type="text/css">
.container {white-space:nowrap; height: 20px; }
.content{float:left;border: 1px solid black; width:100px;}
</style>
<script type="text/javascript">
$().ready(function() {
var containerwidth =0;
$(".content").each(function(){containerwidth = containerwidth +$(this).width()+10;});
$(".container").width(containerwidth );
});
</script>
<div class="container">
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
etc.
</div>
The answer by Senad will still wrap if you reduced the width of the browser window.
What you want is white-space:nowrap; in your css so that text is not wrapped
HTML:
<ul>
<li>Element</li>
<li>Element</li>
.
.
.
</ul>
CSS:
li { display: table-cell; }