Div doesn't shrink-wrap around resized image - html

I have a div on my page that should have some small divs inside it, with a line of text, images and another line of text, everything centered.
But by some weird reason, the div doesn't wrap around the text even if floated, it looks like it haves the same width as the full-scale image, instead of wrapping around the now smaller image.
<div id="real">
<div class="relspn">
Title:<br/>
<img src="img.png"/><br/>
Another text
</div>
<div class="relspn">
Title:<br/>
<img src="img.png"/><img src="img.png"/><br/>
Another Text Another Text
</div>
</div>
Something like that, but, it doesnt matter if I float the divs, set them as inline-blocks or even inline, the div doesn't gets smaller than the full image.
Here's the css:
#real {
float: right;
position:relative;
width:96%;
padding:20px 0;
}
.relspn {
position:relative;
text-align:center;
float:left;
padding:0.2%;
}
.relspn img {
position:relative;
display:inline;
width:10%;
}
I don't know what's happening, help.
Edit:
http://jsfiddle.net/3SkZV/1/
Updated now, I wrote the div class wrong in the example. >.>
Updated the Fiddle too

Related

how to put an img under a header(div) that contains other divs?

I put a header which contains three divs. One has an image and the other two contain text.I then tried putting an image under it which has the same width of the header. But when I first put it, it was over the header div( I thought it should go under it). I then tried pushing it down by increasing the top margin and it worked. But as I increase the width of it the text in the header moves although it is not touching it!
This is the html code:
<div id="header">
<img id="logo" src="...."> <!---the logo at the top right-->
<div id="name">JANE DOETTE<div> <!---the text that moves - top left -->
<div id="job">Front-End Ninja</div> <!--under the text that moves but doesn't move--->
</div>
<img id="image" src="...."> <!---the image-->
This is the css code:
#header {
height: 6em;
width:80%;
background-color: white;
margin-left:10%;
margin-right:10%;
border-bottom:2px solid #BCBBBB;
margin-bottom:10px;
}
#image{
margin-left:10%;
margin-right:10%;
height:10em;
width:80%;
}
#logo {
height:88px;
width:89px;
}
#name {
color: #BCBBBB;
text-align:left;
float:right;
font-size:2.7em;
font-family:sans-serif;
height:50%;
}
#job {
color: #BCBBBB;
text-align:left;
float:right;
font-size:0.5em;
font-family:sans-serif;
font-weight:bold;
margin-top:0.2em;
}
Those are my questions:
Why doesn't the image automatically go under the header div?
Why does the text move?
Why is the top text the one that moved although the one at the bottom is nearer to the image?
What should I do to get the image under the heading div?
I adjusted the width of the image to 80%. But it seems to be just 20%. Why?
Has it got anything to do with position or display?
***Sorry for not adding an image of it but I don't have a reputation of more than 10 ( I am not allowed to).
***Sorry for the long questions.( I am still a beginner).
***Your answers would be much appreciated.
Your question isn't all that clear (please clarify), I will try to answer regardless, but I might misrepresent your question.
1 / 6 . The biggest problem you have I think is that you don't tell the browser how to 'order' the divs. Should they be under eachother or next to eachother? Use the "display" property for this. Use "display: block" to make sure that page-elements like divs or images are stacked under eachother. Depending on the margin the browser uses the remaining space to stack elements next or above eachother.
2 / 3. Because it floats. A float is relative to other elements on the page. If you make it float right, but the content within it align to the left the box goes left while the content within it stays as far to the left as it can keeping with the contraints of the div container. Therefore it seems to move. Lose the float and use "display: block" to make the div be the full width of the header div.
#name {
color: #BCBBBB;
text-align:left;
font-size:2.7em;
font-family:sans-serif;
height:50%;
display: block;
padding-left: 10px;
}
4 / 5 . Lose the "height" property of the image. Because the image has a relative 'height' property next to a relative 'width' property it distorts the image scaling. Use only the width as a percentage and it will scale proportionally.
You are missing a slash. Instead of
<div id="name">JANE DOETTE<div>
it should be:
<div id="name">JANE DOETTE</div>
After adding the slash it appears fine to me in Chrome and Firefox (except for the missing images obviously). See fiddle. Does that solve all of your questions?

Centered-fixed-width-div with fluid divs on left and right?

I am working on a wordpress site.
I have these decorative titles that are constructed like this:
(the following is not the real html structure, it is just as example purpose)
<div class="decoration-left"> <div class="title"> <div class="decoration-right">
.title has a h1 title inside.
.decoration-left, and .decoration-right, are empty divs, with a decorative background.
I need the title to be centered all the time.
I first tried to give all the three divs a 33.3% width, which worked nice on big screens, but as i reduce the window the title breaks into two lines, and it looks ugly. I need the title to have a constant width therefore. I dont want the text to be smaller.
Right now, i have the .title div with "width:auto" which works fine. however i need the left and right decorative divs to take each one, half of the remaining space in a responsive/fluid way.
attaching picture for better understunding.!
My guess is: put your DECORATIVE divs inside the TITLE div, and your TITLE div inside a WRAP div. Make the TITLE div with 'position: relative; display:inline-block; background:#fff;' the DECORATIVE ones with 'position:absolute; left:-50px;' and 'position:absolute; right:-50px;', and the WRAP with 'text-align:center; background:url(LINE IMAGE LINK) center repeat-x;'.
I know it's hard to understand, but I am mostly sure it will work that way. I'll try making it look better by coding some of it:
HTML:
<div class="title-warpper">
<div class="title">
<div class="decoration-left"></div>
<span>YOUR TITLE HERE</span>
<div class="decoration-right"></div>
</div>
</div>
CSS:
div.title-wrapper {
background:url(LINE IMAGE LINK) center repeat-x;
text-align: center;
}
div.title {
position:relative;
background:#fff;
display:inline-block;
}
div.decoration-right{
position:absolute;
right:-25px;
background:url(DECORATION BG LINK);
width:25px;
height:25px;
}
div.decoration-left{
position:absolute;
left:-25px;
background:url(DECORATION BG LINK);
width:25px;
height:25px;
}
I set the decoration divs for 25px, but use what you need. Just remember to adjust them and the left and right properties to fit your needs.
if you don't mind the title overlapping the decorative divs on some screen sizes then you can absolute position the decorative divs with
position:absolute;
left:0px; (OR right:0px;)
give them whatever width and height you like.

Some CSS problems to vertically extend the content of a div until the end of its container in a layout

I am creating an HTML\CSS tabless layout starting from a psd file and I am having a litle problem.
This is my final result that I would obtain:
and this is my HTML\CSS result: http://onofri.org/example/WebTemplate/
As you can see I have some problem with the left sidebar because the last blue box (the #c div) does not extend vertically to the end of the #container div and so don't match with the footer background immage.
The pnly "solution" that I have found (but this is not a correct solution) is to increase the value of the min-height* property of the **#c div of my sidebare. For example if I increase this value from the original 234px to 334px it seems to work well.
But this is not a real solution because if the amount of content change of the page change this problem occurs again.
How can I solve? What can I do to extend the height of the #c div until the end of its container
Tnx
Andrea
Here's a little trick I use sometimes:
What you need to do is have both the #content and #sidebar divs within a container div. You tell that container div to have a class of "clearfix" and it will stretch itself to be the height of the tallest column. You can then give the container div a background image if you want to make the background of each column look like it stretches the whole length.
For example, a 1px high repeating background like this might work: http://i.stack.imgur.com/W84Xa.jpg
THE CSS:
.clearfix:after{
content:”.”;
display:block;
clear:both;
visibility:hidden;
line-height:0;
height:0;}
.clearfix{
display:inline-block;
}
html[xmls].clearfix{
display:block;
}
*html.clearfix{
height:1%;
}
#container{
width:770px;
}
#content{
width:542px;
float:left;
}
#sidebar{
width:228px;
float:left;
}
THE HTML:
<div id="container" class="clearfix" >
<div id="content">
Content Div Text
</div>
<div id="sidebar">
Sidebar Div Text
</div>
</div>

Why won't div float next to image? (goes behind image instead)

I'm trying to have an image, and then to the right of the image I want a div box to be there. I've been trying to search for the reason for this, but I cannot find it. I'm assuming div's can't be floated next to images for some reason because I've successfully done it with text.
http://jsfiddle.net/n8ZDQ/1/
(you can see the red div box is actually mostly behind the image, only part of it is popping out the right side)
HTML:
<img src="http://stignatiusyardley.org/pictures/NFP/NFP%20family%20image.jpg" style="float:left;width:370px;height:246px;" />
​
CSS:
#optin {
width:466px;
border:1px solid #CCCCCC;
height:166px;
background-color:red;
}​
The div itself is not floating! Try adding float: left to #optin.
The DIV is a block level element by default. Only inline or inline-block elements will display the way you want. To get the effect you need, you need to either make the DIV display: inline-block or float: left.
Adjust the css of #optin to float as well
#optin {
width:466px;
border:1px solid #CCCCCC;
height:166px;
background-color:red;
float: left;
}​

Centering the div

Simple one that doesn't seem to want to work..
I want to centre a div inside a 100% wide div.
HTML.
<div id="body-outside">
<div id="body-inside">
content
</div>
</div>
CSS.
#body-outside{
width:100%;
float:left;
background-color:#F7B3DA;
}
#body-inside{
width:1280px;
margin:0 auto;
background-color:#F7B3DA;
float:left;
}
The content is staying on the left of the screen at the moment.
Any ideas?
Thanks.
Get rid of float:left;. This pushes it to the left despite setting the margin to auto.
You may also want to think about using text-align: center in the body outside portion.