Nested floating divs not working - html

On the site I'm currently coding I have a centered DIV containing a float left column and a smaller float right column. This works fine.
In the Left floating column, I have a further float left column, containing an bio image, and a float right text column containing the bio text.
However, I am at the point of throwing my computer out of the window because the last two bio divs are sitting on top of each other, with the text underneath the photo instead of floating next to it.
I have put every combination of clear divs and overflow: hidden; I can reasonably think of, but to no avail.
The page in question is here: http://test.phantomlimb.net/about.php and the CSS is here: http://test.phantomlimb.net/phantom.css
I would greatly appreciate anyone pointing me in the right direction to solve this annoying conundrum before I break down and *gasp!* accomplish the same effect using tables in around 3 minutes!!!
PS I'm more of a designer than a coder, so please feel free to explain things as you would to a child.

Did you try this?
Add float: left; to your .bioleft class in phantom.css
Alternatively add float: right; to your .bioright class

You are missing colons in your css file. e.g. you have
.bioleft {
float left; /* HERE */
width: 25%;
background: red;
display: block;
}
.bioright {
float right; /* AND HERE */
width: 70%;
background: cyan;
display: block;
}
You should have float: left; and float: right;

IT is because of improper syntax you have float left; it should be float: left;

Have you considered using floated divs for the container left and right divs, then just use inline blocks for the divs inside the floated divs?
<div id="left">
<div id="img"></div>
<div id="content"></div>
</div>
And
#left {
float: left;
}
#img,#content {
display:inline-block;
}
#img {
width: 100px;
}
#content {
width: calc(100% - 100px);
}
That should put the image and the content side by side, but they will be treated as a block div.
You could actually put both the image and content divs inside their own container div and name that biog as the id, to create its own 'block'

Related

How to align series of HTML links horizontaly?

I have three links. I want to align them like one in the left, one in the middle and one in the right in a single line.
Say my links are prev(which I want place in the left of the line) home(which I want place in the middle of the line) and next(which I want place in the right of the line). So I wrote this code:
prev
lots of
home
lots of
next`
I understood this is wrong because its a fixed size and will cause problem if I resize my window or in a relatively small screen. So I tried this:
prev
home
next
But it didn't work!
So how can I solve this problem with HTML?
`
Wrap links with a div container and use left/right floats and text-align: center on the wrapper:
.wrap {
text-align: center;
background: #EEE;
padding: 10px;
}
.wrap .left {
float: left;
}
.wrap .right {
float: right;
}
<div class="wrap">
prev
home
next
</div>

Wrapping long line of tables with varying heights

I'm wrapping an image caption under an image. There are many pairs of these images and captions.
<div class="book">
<img alt="cover"><br>
<div>
<b>Title of Book</b><br>
Some extra info, maybe.
</div>
</div>
.book {
display: table;
float: left;
}
.book img {
height: 300px;
}
.book div {
display: table-caption;
caption-side: bottom;
text-align: center;
}
JSFiddle. I float the tables left to line each row up against the side of the screen. One of the boxes gets caught because the height of the box to its left is more than the height of the others.
How can I make each row of boxes line up with the left side of the screen?
It should look something like this, just with the ability to adapt to different caption heights without an explicit global height.
I set all of the images to a constant height, but I don't know their widths. There also might be a long caption, so I need that to wrap to the image width. I've tried
setting .book div to a constant height, but that doesn't adapt to a tall caption (JSFiddle)
using a flexbox, which works, but I'm looking for something simpler.
Add clear:both; to you book class
Like so:
.book {
display: table;
float: left;
clear:both;
}
I added a container and a new class, see working FIDDLE
.clear{clear:both;}

Moving a far right float from the right margin

Let's say I have a navbar that has 5 elements nicely floated to the left. I then add an element that I want to be on the far right, but I want a little bit of a margin between the element floated to the far right and the edge of the actual document. If I just do float:right;, the element is smashed to the end of the document. If I try to mess with position-right or margin-right, nothing happens. How do I get the element away from the edge?
A couple options, first use a wrapper to to control the two divs seperation:
HTML:
<div id="wrapper">
<div id="left">Left Div</div>
<div id="right">Right Div</div>
</div>
CSS:
#left {
float: left;
}
#right {
float: right;
}
#wrapper {
width: 500px;
margin: auto;
padding: auto;
overflow: auto;
}
http://jsfiddle.net/wDjFV/
Another option is to do float: left on BOTH <div>s and seperate with margins there:
HTML:
<div id="left">Left Div</div>
<div id="right">Right Div</div>
CSS:
#left {
float: left;
}
#right {
float: left;
margin-left: 200px;
}
http://jsfiddle.net/wDjFV/3/
Update:
Just a thought on the second option that you may not know, you'll want to to do clear:both on a CSS rule for any <div>s that are bellow the ones you are floating to get the normal stacking behavior.
padding-right may be what you are looking for, not position-right. Either way, margin-right should be working to pull the box away from the edge of the page. padding-right will keep the box on the edge of the page, but move the containing content further away from the edge.

Floating Variable Number of DIVs to the Center

I defined two CSS classes that set the background to an image (shown below). One is a yellow block, and another is a grey block.
.block-gray { background: url('grey.gif'); width: 15px; height: 3px; }
.block-yellow { background: url('yellow.gif'); width: 15px; height: 3px; }
What I want to be able to do is to define a variable number of div's using one of the classes above, and have them horizontally stacked, and centered within a larger container.
So if I defined 3 blocks like so:
<div>
<!-- The # of these is variable, and not necessarily fixed at 3 -->
<div class="block-yellow"></div>
<div class="block-yellow"></div>
<div class="block-grey"></div>
<div>
Then I would like them to be centered within the outer div, no matter how many inner divs there are. I can use float:left to stack them horizontally, but I'm not sure how to keep them centered.
| |
Any ideas?
Thanks.
.container { text-align: center; }
.block-yellow { display: inline-block; }
and you might want to reset that text-align:
.block-yellow { text-align: left; }
well, don't use float:left; instead, use display:block and set the outer div as text-align:center

centering a div between one that's floated right and one that's floated left

I have a page in which a header consists of three divs - one that's floated to the left, one that's floated to the right, and one that's in between them. I'd like for that central div to be centered, yet sadly float: center doesn't exist and I can't just float it to the left and add padding as it'd have to change depending on the window size.
Is there something simple I'm overlooking? Or how would I do such a thing?
Update:
In addition, I'd like to find a way of centering that middle div in the space between the divs in case that looks better.
If you have two floated divs, then you know the margins. The problem is that the float:right div should be put before the middle div. So basically you will have:
left-floated | right-floated | centered
Now, about the margins: usually you can just use margin:0 auto, right? The problem is that right now you know the values of the margins: floated divs! So you just need to use:
margin:0 right-floated-width 0 left-floated-width
That should work.
Years later edit
Meanwhile, a new toy is in town: flexbox. The support is fairly good (i.e. if you don't need to support lower than IE 10) and the ease of use is way over floats.
You can see a very good flexbox guide here. The example you need is right here.
Indeed, the important part is that the centered div come after the left and right divs in the markup. Check out this example, it uses margin-left: auto and margin-right: auto on the centered div, which causes it to be centered.
<html>
<head>
<style type="text/css">
#left
{
float: left;
border: solid 1px red;
}
#mid
{
margin-left: auto;
margin-right: auto;
border: solid 1px red;
}
#right
{
float: right;
border: solid 1px red;
}
</style>
</head>
<body>
<div id="left">
left
</div>
<div id="right">
right
</div>
<div id="mid">
mid
</div>
</body>
</html>
Here's a JS Bin to test: http://jsbin.com/agewes/1/edit
Usually you can use flexbox instead of floats:
https://jsfiddle.net/h0zaf4Lp/
HTML:
<div class="container">
<div>left</div>
<div class="center">center</div>
<div>right</div>
</div>
CSS:
.container {
display: flex;
}
.center {
flex-grow: 1;
}
The element with the centered content needs to be specified after both floated elements. After that, simply set the middle element to text-align: center. The text in the centered element will squeeze in between the floats.
See here:
http://jsfiddle.net/calvintennant/wjjeR/
Try this (make sure to use better class names):
.left {
float:left;
width:200px;
}
.right{
float:right;
width:200px;
}
.center {
overflow:hidden;
zoom:1;
}
The center div will fit between the two floats.
If you want to create a gutter between that centered div and the two floats, then use margin on the floats, not on the center div.
Because of "zoom", the CSS will not validate, but that layout will work in IE 5.5 and 6.
Note that source order is important here: the two floats must come first, then your "centered" div.
In some cases, you have a limitation and cannot change the page markup by moving the middle div after the right-floated div. In that case, follow these instructions:
For container: position: relative
For middle div: position: absolute; left: [containerWidth - middle-width / 2]
I hope you got the idea.
A simple solution without having to change the order of the divs (sometimes we can not do this) could be an absolute positioning for the center div as follows:
.container {
position: relative;
}
.container div {
width: 200px;
background: red;
}
.left {
float: left;
}
.right {
float: right;
}
.center {
position: absolute;
top: 0;
left: 0;
right: 0;
margin: auto;
}
<div class="container">
<div class="left">left</div>
<div class="center">center</div>
<div class="right">right</div>
</div>
https://jsfiddle.net/Helioz/nj548y0g/