floats within a div - html

Hi i'm trying to make a div within the front page of my site that contains a floating img and some floating text h3, p and a . I then want to loop the div below with different text/pic . When i do this once it works fine but the container div hasn't stretched to fit the content . So when I add another below it overlaps .
code:
<div id="blog">
<h1>BLOG</h1>
<div id="postcont">
<img src="blog1.png" width="40" height="40" />
<h3>Playing At The Phenoix</h3>
<p>So we arrived down at the phenoix about 10 past ten .Rommy was all ready out of it and wasn't sure if he could do...read more </p
>
</div>
<div id="postcont">
<img src="blog1.png" width="40" height="40" />
<h3>Playing At The Phenoix</h3>
<p>So we arrived down at the phenoix about 10 past ten .Rommy was all ready out of it and wasn't sure if he could do...read more </p
>
</div>
</div>
#blog {
float:left;
width:400px;
border-top:#0FF solid 6px;
}
#postcont {
padding:10px;
border-top:1px #FFF solid;
margin-top:10px;
}
#blog h1 {
font-size:20px;
color:#FFF;
padding:10px;
padding-left:0px;
letter-spacing:2px;
}
#blog p {
font-size:15px;
color:#FFF;
float:right;
clear:right;
width:300px;
margin-right:30px;
letter-spacing:2px;
margin-top:5px;
}
#blog a {
font-size:15px;
color:#FFF;
float:right;
clear:right;
width:300px;
margin-right:0px;
letter-spacing:2px;
margin-top:5px;
font-style:italic;
text-decoration:underline;
}
#blog h3 {
font-size:15px;
color:#FFF;
float:right;
clear:right;
width:300px;
margin-right:30px;
letter-spacing:2px;
margin-top:5px;
font-weight:bold;
}
#blog img {
float:left;
clear:left;
}

Block-level elements to not expand to the height of floated elements unless you tell them to. You should add a clearing-element after the last floated element to fix this problem. Instead of:
</div>
</div>
Use:
</div>
<br style="clear: both"/>
</div>
For an extended explanation of this solution, as well as an alternative solution, please see: http://www.quirksmode.org/css/clearing.html

Related

Why is a div id messing my inline-block up?

My code is here (I'm a newbie just playing with some stuff I've learned; I realize this is hardly a work of art, my links all link back to Codecademy, etc - they're just placeholders) Here's the CSS:
head {background-color:#eed393;}
#links {display:inline-block;
margin-left:35px;
margin-top:8px;
margin-bottom:40px;
vertical-align:top;
}
div:hover {opacity:0.8;
}
#locationhours {
border:none;
border-radius:50px;
width:200px;
height:70px;
text-align:center; font-family:Georgia;
font-size:30px;
background-color:#724d20}
#menu {border:none;
border-radius:50px;
width:200px;
height:55px;
text-align:center; font-family:Georgia;
padding-top:15px;
font-size:30px;
background-color:#724d20}
#catering {border:none;
border-radius:50px;
width:200px;
height:55px;
text-align:center;
font-family:Georgia;
padding-top:15px;
font-size:30px;
background-color:#724d20}
a:link {text-decoration:none;
color:#b0dddf;}
a.fill_div {display: block;
height: 100%;
width: 100%
text-decoration: none;
}
And here's the HTML:
<head>
<div id:"links">
<div id="locationhours";>Location & Hours </div>
<div id="menu";>Menu</div>
<div id="catering";>Catering </div>
<div id="infocontact";>Info & <br> Contact </div>
</div>
I have a div id called #links that I am trying to use for aspects of my links I want to make universal. As you can see, although I am using inline-block, I can't get the links to be in a horizontal line; instead, they bunch up in a vertical line. If I put "div" rather than "#links" in my CSS, the inline-block works, but I'm going to have other div elements I want to use later that I don't want to apply the aspects for the links to. What am I doing wrong?
Here is a demo of your code now inline: http://jsfiddle.net/co738b5s/1/
I found lots of issues. In the "links" div you were using : instead of = to add the id. Also, when you are adding ID's and classes, you do not need the ; that you used. See my html for corrections.
<div id="links">
<div id="locationhours" class="inline">
Location & Hours </div>
<div id="menu" class="inline">
Menu
</div>
<div id="catering" class="inline">
Catering
</div>
<div id="infocontact" class="inline">
Info & <br/> Contact
</div>
</div>
//Had to make a new class for all the menu divs
head {background-color:#eed393;}
.inline {
float:left;
}
#links {
margin-left:35px;
margin-top:8px;
margin-bottom:40px;
vertical-align:top;
}
div:hover {opacity:0.8;
}
#locationhours {
border:none;
border-radius:50px;
width:200px;
height:70px;
text-align:center; font-family:Georgia;
font-size:30px;
background-color:#724d20}
#menu {border:none;
border-radius:50px;
width:200px;
height:55px;
text-align:center; font-family:Georgia;
padding-top:15px;
font-size:30px;
background-color:#724d20}
#catering {border:none;
border-radius:50px;
width:200px;
height:55px;
text-align:center;
font-family:Georgia;
padding-top:15px;
font-size:30px;
background-color:#724d20}
#infocontact {border:none;
border-radius:50px;
width:200px;
height:55px;
text-align:center;
font-family:Georgia;
padding-top:15px;
font-size:30px;
background-color:#724d20}
a:link {text-decoration:none;
color:#b0dddf;}
a.fill_div {;
height: 100%;
width: 100%
text-decoration: none;
}
The CSS display: inline must be applied to each individual member of the list you want to make inline. The display property is best described as the relationship of a node in its parent, not the relationship of all children. Furthermore, display is a non-inheritable property (see W3Schools), so applying it to the parent node #links won't affect its children (#locationhours, #menu, etc.) whatsoever.
When you changed it to affect div, you unknowingly were affecting all of the children, since they too are divs. To quickly fix this problem without any inline CSS, set each list member's div to the class .listmem, like this...
<div id="locationhours" class="listmem">
...so adding this to your CSS should quickly fix the problem:
.listmem {
display: inline;
}

Bad positioned text with display inline in html

I am trying to put a title in a div toolbar next to some pictures. The problem is that my text is not well placed, it should be at least on top of the toolbar but instead it is at bottom and doesn't move.
I would like it to be in the vertical middle at left near the pictures.
Here is a codepen : http://codepen.io/anon/pen/fDojK
And a picture :
Here is the html part of the title bar:
<div id="bar" >
<div id="picturesmenu">
<img src='images/back.jpg' alt='back' />
<img src='images/home.jpg' alt='home' />
<img src='images/reload.jpg' alt='reload' />
</div>
<div id="titlemenu">Main</div>
</div>
<div id="body">
...
And style :
#bar
{
width:100%;
height:50px;
padding-top:3px;
padding-left:10px;
border-bottom:2px solid white;
vertical-align:top;
}
#picturesmenu
{
margin:0;
padding:0;
display:inline;
}
#bar img
{
border:3px solid white;
width:40px;
margin:2px;
}
#titlemenu
{
margin:0;
padding-left:20px;
height:100%;
display:inline;
font-size:20pt;
font-weight:bold;
color:white;
}
#bar span
{
margin-left:20px;
margin-top:200px;
font-size:20pt;
font-weight:bold;
color:white;
}
I tried vertical align and margin but the "Main" text doesn't move...
Thanks in advance before I change anything into tables ;)
[EDIT]
Thank you all for your answers ! I didn't thought about handling the alignment of the content (#titlemenu) instead of the container (#bar), it's not very logical...
You need to work the vertical align for both #picturesmenu and #titlemenu and remove the padding left for that title if you want it to the left. Then work with inline-block elements. Like this:
EDITED WITH CROSS-BROWSER CODE
html, body {
height:100%;
width:auto;
padding:0;
margin:0;
background-color:black;
}
#bar {
width:100%;
height:auto;
padding-top:3px;
padding-left:10px;
border-bottom:2px solid white;
display:block;
}
#picturesmenu {
margin:0;
padding:0;
}
#bar img {
border:3px solid white;
width:40px;
margin:2px;
display:inline-block;
vertical-align:middle;
width:40px;
height:50px;
}
#titlemenu {
margin:0;
padding-left:0px;
display:inline-block;
vertical-align:middle;
font-size:20pt;
font-weight:bold;
color:white;
}
.item {
float:left;
width:120px;
height:120px;
border:2px solid white;
text-align:center;
margin:20px;
padding:20px;
}
.picitem {
height:70%;
margin-bottom:25px;
border:2px solid white;
}
.textitem {
underline:none;
color:black;
font-size:16pt;
color:white;
}
I have forked your CodePen
However, a way better approach would be to give #bar a display:block property and then add inline-block to everything inside, but if you want it to work as in your description, there you go
Add these lines to the #titlemenu in CSS
padding:10px;
display:inline-block;
vertical-align:top;
By vertical-align:top, the block gets aligned to the top of the parentdiv and you set padding to fit the height of the block to the height of the parent div
Demo

HTML+CSS Multiple style, line text on a picture

In my last question I asked how could I add text onto the gray area of the picture, some guys suggested using <span>, I ended up with all the text (because it is a span after all, inline) on top of each other in a single line (left picture), even though it was set to display:block. How can I break it into seperate lines as seen in the picture on the right?
and does it make sense using h4/h5 for the styling or I should use different div's or something?
HTML:
<div class="rightCol1">
<img src="pic1.png"><span><h4>2014 02 16</h4><h5>po pirmojo etapo <br> naudingiausi - osvaldas <br> sarpalius ir lukas šukutis</h5></span>
<img src="pic2.png"><span><h4>2014 02 16</h4><h5>geriausias sezono <br> startas per visą klubo <br> istoriją </h5></span>
</div>
CSS:
.rightCol1{
float:right;
margin-right:150px;
margin-top:10px;
}
.rightCol1 a {
background:green;
display: block;
position:relative;
height:200px;
width:100px;
margin-bottom: 160px
}
.rightCol1 a span {
line-height:0px;
display:block;
margin-left:15px;
width:234px;
height:70px;
position:absolute;
bottom:-80;
left:0;
z-index:1;
}
h4{
padding:0;
margin:0;
font-style:;
color:#e6540c;
font-weight:bold;
font-size:14;
}
h5{
padding:0;
text-transform:uppercase;
color:rgb(193,193,193);
}
It's because your span has no line height, so each on the lines will come out ontop of each other. I suggest removing line-height from your span CSS:
.rightCol1 a span {
display:block;
margin-left:15px;
width:234px;
height:70px;
position:absolute;
bottom:-80px;
left:0;
z-index:1;
}

Trying to align my <h1> and <p> elements at left of my image

Im trying to align my title, image and paragraph to the left of my news image.
And Im using float left for doing this but its not working,
Im having this:
But Im trying this:
Do you see where might be the problem?
My fiddle with the problem Im having:
http://jsfiddle.net/upH4U/1/
My html:
<div id="news-content">
<h1>News</h1>
<article id="loop-news">
<div class="img_container">
<img src="../image1.jpg" title=""/>
</div>
<h2><a href="#" >Title of the news</a><br /></h2>
<span id="date">Tuesday, May, 2014</span>
<p>
This is my paragraph and I want to align it to left of my image.
see more
</p>
</article>
<article id="loop-news">
<div class="img_container">
<img src="../image1.jpg" title=""/>
</div>
<h2><a href="#" >Title of the news</a><br /></h2>
<span id="date">Tuesday, May, 2014</span>
<p>
This is my paragraph and I want to align it to left of my image.
see more
</p>
</article>
</div>
My css:
#news-content
{
float:left;
width:480px;
background:#f3f3f3;
}
#news-content h1
{
font-size:20px;
font-weight:100;
margin-bottom:10px;
color:gray;
text-align:left;
}
#loop-news
{
width:400px;
margin-bottom:10px;
text-align:center;
}
.img_container
{
width:160px;
height: 165px;
float:left;
cursor: pointer;
border:3px solid #ccc;
}
#loop-news h2 a
{
font-size:20px;
color:#3B5998;
text-decoration:none;
margin:0 auto 0 5px;
font-weight:100;
float:left;
}
#loop-news a
{
font-size:14px;
text-decoration:none;
margin-left:2px;
}
#loop-news #date
{
font-size:13px;
font-weight:normal;
color:#7a7a7a;
}
#loop-news p
{
font-size: 13px;
text-align:justify;
line-height:25px;
word-spacing:-2px;
width:300px;
float:left;
margin-left:5px;
}
quick answer, use clearfix - there are a few options there
CSS
#loop-news
{
width:400px;
/*margin-bottom:10px; moving margin to seperator*/
/*text-align:center;*/
}
#loop-news p
{
font-size: 13px;
/*text-align:justify;
line-height:25px;
word-spacing:-2px;
width:300px;
float:left;*/
margin-left:5px;
}
#loop-news {
overflow:hidden; /*quick clear fix*/
}
.loop-news-content {
overflow:hidden;
}
#loop-news *:first-child { margin-top:0; }
#loop-news *:last-child { margin-bottom:0; }
#loop-news h2 { margin:0; }
.loop-news-meta { margin-top:0; }
Heres the updated fiddle
http://jsfiddle.net/Varinder/HTNk8/2/
Here's a page to show how to align text relative to an image:http://www.w3schools.com/tags/att_img_align.asp
your width is overflow; dont use it or fix it
#loop-news p
{
font-size: 13px;
text-align:justify;
line-height:25px;
word-spacing:-2px;
float:left;
margin-left:5px;
}
float the image to the right like this fiddle
float:right;
You need to clear your float by adding clear:left; to the same class that uses float: left. In your case, you can use the CSS declaration:
#news-content article { clear: left; }
Also, having multiple elements with the same ID can have unexpected results. You should consider using classes instead.

CSS - Trouble aligning text elements on the same line

I am trying to create a footer bar which has a text element aligned on the left and one thats aligned to the right, however I'm having some difficulty.
This is what I have so far:
HTML
<div id="footer_bar">
<div id="footer_bar_content">
<p>
Left Text
</p>
<p class="align_right">
Right Text
</p>
</div>
</div>
CSS
#footer_bar
{
width:100%;
position:absolute;
margin:0;
bottom:0;
height:30px;
border-top:2px #eeeeee solid;
background-color:#f7f7f7;
}
#footer_bar_content { padding-left:15%; padding-right:15%; }
#footer_bar_content p { line-height:30px; margin:0; color:#222; font-size:11px; display:inline; }
.align_right { text-align:right; width:100%; }
Please could someone help me work out what is wrong? The align_right class doesn't appear to have any effect.
Is this what you are looking for. Take a look at fiddle. http://jsfiddle.net/GD8tL/1/
Use float instead of align
#footer_bar
{
width:100%;
position:absolute;
margin:0;
bottom:0;
height:30px;
border-top:2px #eeeeee solid;
background-color:#f7f7f7;
}
#footer_bar_content { padding-left:15%; padding-right:15%; }
#footer_bar_content p { line-height:30px; margin:0; color:#222; font-size:11px; display:inline; }
.align_right{ float:right;}
#footer_bar_content p.align_right {float:right; width:100%;}
Try this if you want your text on the right side, and play a bit with the width, because you want to give 100% of the main div's width, which is the whole place, so probably it will be displayed in new line.
<div id="footer_bar">
<div id="footer_bar_content">
<p>
Left Text
<span style="float: right;">
Right Text
</span>
</p>
</div>
</div>
You must remove width = 100% in class align_right and use "float: right" instead of "text-align:right"
CSS:
.align_right { float:right;}
Code: JSFIDDLE
instead of paragraph you should take left.. similar for right and use .left{float:left} and .right{float:right} then .footer_bar_content:after{clear:both} will work for u
You can try float right or left accordingly,
Html
<div id="footer_bar">
<div id="footer_bar_content">
<p class="left">
Left Text
</p>
<p class="right">
Right Text
</p>
</div>
</div>
StyleSheet
#footer_bar
{
width:100%;
position:absolute;
margin:0;
bottom:0;
height:30px;
border-top:2px #eeeeee solid;
background-color:#f7f7f7;
}
#footer_bar_content { padding: 0 15%; }
#footer_bar_content p { line-height:30px; margin:0; color:#222; font-size:11px; display:inline; }
.right { float:right; }
.left { float:left; }
Here is the Demo