<DIV> boxes overlapping when adding a third - html

First of all. I´m kind of a rookie when it comes to coding webdesign. Last time I made a website was 20 years ago, and I can say that a lot has happened :-)
To the topic. I´m trying to create a couple of boxes in . I want them all to stay in the middle with a Little space between them.
They need to go down in a row like this:
[] []
[] []
My problem is that when i add my third and fourth they overlap the top boxes!
Link to code on fiddle:
http://jsfiddle.net/2cZtH/7/ enter code here

Here you go. http://jsfiddle.net/2cZtH/8/
You shouldn't really be using position:absolute for this ideally, that takes them out of the DOM and you have to position them all manually. You can give them a width of a % of the containing div and float them left for the same effect with much more ease. :)
div { width:25%; float:left; border-radius: 25px; margin-right:2.5%;
border: 2px solid #A9B8C2;
padding: 20px;
height: 200px;
background: #ECECEC; }
Edit: Of course you can use a set width if you know the width of the containing div.

See the fiddle
Your HTML code had many problems which made it to malfunction.I have changed your code a little. See below for the changed code. Please replace your HTML with this one.
The main problem with your CSS was that you was using position:absolute; which made it look like that. So i've changed that to position:relative.
You can read more about CSS positioning here..
HTML
<div class="container">
<div class="right">
<p id="rcorners"> <a href="#" class="fillthediv">
<img alt="Non-technical" style="float: left;margin-right:10px; width:128px; height:128px" src="images/Artiklar/Alger.jpg" />
<span class="fulldivhead"> Alger i våra kar</span>
<br /><br/>
<span class="fulldivp"> En artikel som beskriver ingående de vanligaste algerna i våra akvarier. Med många bra bilder tillsammans med Beskrivning/Orsak/Bekämpning gör denna artikel till
förmodligen den mest omfattande på webben.
<br/><br/>
</span>
</a>
</p>
</div>
<div class="right">
<p id="rcorners"> <a href="#" class="fillthediv">
<img alt="Non-technical" style="float: left;margin-right:10px; width:128px; height:128px" src="images/Artiklar/Alger.jpg" />
<span class="fulldivhead">De vanligaste växtbristerna</span>
<br /><br/>
<span class="fulldivp">
<br/><br/>
</span>
</a>
</p>
</div>
<div class="right">
<p id="rcorners"> <a href="#" class="fillthediv">
<img alt="Non-technical" style="float: left;margin-right:10px; width:128px; height:128px" src="images/Artiklar/Alger.jpg" />
<span class="fulldivhead">De vanligaste växtbristerna</span>
<br /><br/>
<span class="fulldivp">
<br/><br/>
</span>
</a>
</p>
</div>
</div>

I struggled to understand your code, is this something you are trying to create
http://jsfiddle.net/2cZtH/11/
I created a simple box that is repeated. Using display:inline-block; stacks them in order and causes a line break when it reaches the end of the viewport.
If you are just trying to create three columns using float:left is all you need.
http://jsfiddle.net/2cZtH/15/

Problem solved! By making the right box relative and edit margin-right plus margin-top. Plus link in clear after code. Thanks!

You could put them in a table:
<table>
<tr>
<td>
Top Left Content
</td>
<td>
Top Right Content
</td>
</tr>
<tr>
<td>
Bottom Left Content (Blank)
</td>
<td>
Bottom Right Content
</td>
</tr>
</table>
Put your divs in the table cells, and remove their absolute positioning property as this will prevent the table cells from sizing properly.

Related

Image displayed on margin

I have a table with single row that contains some text (with new-line chars), e.g.:
<td id='line-numbers'>
<span class="number" id="1">1</span><br>
<span class="number" id="2">123</span><br>
<span class="number" id="3">31111</span><br>
</td>
From CSS perspective I added css: margin-right: 15px to line-numbers.
Now I would like to insert images at the end of each row, e.g.:
<td id='line-numbers'>
<span class="number" id="1">1</span><img ...><br>
<span class="number" id="2">123</span><img ...><br>
<span class="number" id="3">31111</span><img ...><br>
where each image will be right-centered and displayed in 'margin' area on the right which height will match height of the font (width should be scaled to height). Please advise how to do it in the most effective way.
Thank you.
p.s. potentially I could introduce additional column on the right, but having no text (except line-break), I found it difficult to match (putting each line into separate table is currently not possible).
Why not put <img/> within the <span>?
Like:
<td id='line-numbers'>
<span class="number" id="1">
1 <img src="" />
</span>
</td>
Using CSS you can align the image to the right.
As you didn't provided any CSS I wasn't able to already implement it for you.

IE 9/8 breaks my div into 2 divs of same id and separates elements

Hey I just made a landing page and it looks fine on chrome
http://www.advicestudents.ro/tommy/homepage/homepage_v1/homepage.html
well the CRT_abs div that holds the heading subtitle and button duplicates on IE 9 and 8 it goes CRT_abs for the text and CRT_abs for the button same goes for the H1 holder DIV !
Dose anyone understands why this happens?
HTML code for holder :
<a href="#"><div id="h1" style="margin-top:-3px;">
<img src="images/h1.jpg" alt="" />
<div class="CRT_abs" style="text-align: center;width: 711px;left: 139px;top: 219px;padding: 0px;">
<div class="CRT_title_s_i CRT_white" style="line-height:16px; font-size:16px; text-transform: none; margin-bottom: 8px;">
Fall Outerwear
</div>
<div class="CRT_gills CRT_white" style=" font-family:ITCCaslon224W01-BookIt;font-size:40px; line-height:40px; margin-bottom: 9px; letter-spacing:1px;">
THE WARM UP
</div>
<div class="CRT_subtitle CRT_white" style="font-size:14px; margin-bottom: 12px;">
The perfect coat for every occasion,
<br />
from vintage bomber to collegiate duffle.
</div>
SHOP OUTERWEAR <span class="CRT_f18 CRT_gills">›</span>
</div>
</div></a>
so some CSS styleing is already inline coded into the HTML as you can see + the Position:absolute on the CRT_abs. I think thats all
The problem was that the first link tag that was wraping the whole main div, moved it to wrap only the image so i got the same effect and no more buggs. The buttons have the right possition now.

html-coding-how do i place a text on image in HTML?

I am designing this for a phone gap application..i want to code this in html..
i have two questions..
Q1)how do i place a text on the image at different positions?
suc as text1,text2,text3,text4 in the image given here.
Q2) how to place it at the centre in the page.i had given
<img src="img/img1.png" style="margin-left:5px;" />
<img align="middle" />
but,this makes no difference.
guidance required.please help.
i have another doubt...after running the program....there is the extension part of the body after the footer...if you drag up....you can see thtat the body that is between the header and footer is extended. and it moves evento the right.
any mistake in the coding?
put them in a Div, then give this Div a background style ;)
the code should be like this:
<div id='container'>
<span> text 1 </span>
<span> text 2 </span>
<span> text 3 </span>
<span> text 4 </span>
</div>
in the css:
#container{background:url(path/to/img) no-repeat scroll 0 0 transparent; background-size:100% 100%; display:block; height:...px; width:...px;}
#container span{width:50%; height:25%;display:block; overflow:hidden;float:left;}
you can add border to the spans, color etc...
You can do that by wrapping image with div and z-index. Your code should look like this:
<div style="position:fixed; top:10px; left:5px; z-index:250; width:ofimage; height:of image;">
<span style="display:block; width:30; height:20; margins if you need; float:left">text1</span>
<span style it accordingly and add float left>text2</span><br>
<spanstyle them as first two>text3</span>
<span>text4</span>
</div>
<img src="your image" style="if any">

Styling dynamic content where there isn't always content

OK, so my title is terrible. Anyway-
I'm trying to style a simple "product info" template. The CMS I use is drawing in dynamic product information from tags. Looks like this- the divs are styled so they line up as two columns:
<div class="specslabel">
<strong>
{rs_size_lbl} <br />
{rs_material_lbl} <br />
{rs_application_lbl} <br />
{rs_fitting_system_lbl}
</strong>
</div>
<div class="specs">
{rs_size} <br />
{rs_material} <br />
{rs_application} <br />
{rs_fitting_system}
</div>
It all works fine when all those tags are pulling in information properly. However, sometimes one of those fields (it draws from a CSV file) is empty. The tags are smart and won't show the {_lbl} (field label) content if there is no content in the according field. Then there is a blank line, obviously because of the line break.
If I don't use line breaks, the "_lbl" tags all stack up (since the labels are generally short text). Is there another way to style this so that when no content is drawn in, there is no line break- but when there is content, there is a line break?
Rewrite your HTML to put the label with the item.
<div><span class="specslabel">{rs_size_lbl}</span><span class="specs">{rs_size}</span></div>
<div><span class="specslabel">{rs_material_lbl}</span><span class="specs">{rs_material}</span></div>
<div><span class="specslabel">{rs_application_lbl}</span><span class="specs">{rs_application}</span></div>
<div><span class="specslabel">{rs_fitting_system_lbl}</span><span class="specs">{rs_fitting_system}</span></div>
Then, define your CSS as
.specslabel {
display: inline-block;
width: 45%;
}
.specs {
}
What will happen is, when neither the label nor the data gets anything, your html for that line item will be rendered as <div></div>, which has no height by default. Thus the blank space will be collapsed when there is nothing in the div to show.
I'd recommend altering your markup to something like this:
<div class="specs">
<div class="spec">
<span class="label">{rs_size_lbl}</span>
<span class="data">{rs_size}</span>
</div>
<div class="spec">
<span class="label">{rs_material_lbl}</span>
<span class="data">{rs_material}</span>
</div>
<div class="spec">
<span class="label">{rs_application_lbl}</span>
<span class="data">{rs_application}</span>
</div>
<div class="spec">
<span class="label">{rs_fitting_system_lbl}</span>
<span class="data">{rs_fitting_system}</span>
</div>
</div>
Then style span.label and span.data to have a fixed width so they align properly. If they're empty, they should be invisible.
If you format it in the following manner there'd be no issues:
<style>
strong span { float:left; clear:left; }
</style>
<strong>
<span>{rs_size_lbl}</span>
<span>{rs_material_lbl}</span>
<span>{rs_application_lbl}</span>
<span>{rs_fitting_system_lbl}</span>
</strong>
Otherwise, you'd need to alter the server script to output the <br/> appropriately ...

Image next to a Division

How can I put an <img> next to a <div> so the image vertically aligns in the middle?
<img src="http://devcentral.f5.com/weblogs/images/comment-icon.gif"><div style="font:10pt Arial;padding:5px;background-color:#ccc;"><span style="float:right">No. 1</span><span style="font-weight:bold;padding-right:10px">John Doe</span><span style="color:#808080">11/14/2010 3:23:44</span></div>
I know how to do it using a table:
<table style="font:10pt Arial">
<tr>
<td style="vertical-align:middle"><img src="http://devcentral.f5.com/weblogs/images/comment-icon.gif"></td>
<td style="width:100%">
<div style="padding:5px;background-color:#ccc;border-top:1px solid #DEDEDE"><span style="float:right">No. 1</span><span style="font-weight:bold;padding-right:10px">John Doe</span><span style="color:#808080">11/14/2010 3:23:44</span></div>
</td>
</tr>
</table>
But I wonder if I could do it without a table.
Thanks in advance!
Rain Lover
To be honest from your example I have a feeling you may be taking slightly the wrong approach for this.
Personally I would attach this icon to the div as a CSS background-image. Afterwards, you could apply padding to the left of the div equal to the width of the image (plus a few more pixels for spacing). Then, you will be able to use background-position to do something like this:
background-position:0px center;
This will give you the higher degree of control that I think you're after.
With block elements such as img and div, you cannot position them vertically in the centre of something without actually having a something (element) to vertically centre them inside of.
Having said that it is still not possible aside from using some sort of hack. The far simpler method would be to use a relative position on one of the elements and offset its position such that it visually creates the same effect, or use a margin/padding to do the same.
It can be done the following way. There is no easy way to center unless you have it inside an element with a specific height and can be played with. This can be viewed at http://jsfiddle.net/jawilliams346614/CvpUB/1/
<div>
<img src="http://devcentral.f5.com/weblogs/images/comment-icon.gif" style="float:left; padding:5px;">
<div style="font:10pt Arial;padding:5px;background-color:#ccc;">
<span style="float:right">No. 1</span>
<span style="font-weight:bold;padding-right:10px;float:left;">John Doe</span>
<span style="color:#808080">11/14/2010 3:23:44</span>
</div>
</div>
now if you increase your font size, you will have to change padding to:
padding-top: 5px; // change in sync with bottom to center in text
padding-bottom: 5px;
padding-left: 5px;
padding-right: 5px;