I'm a first year web designer and I'm currently working on an assignment where it requires to float two contents side by side. Every time I float the right content to the right side I: 1) lose my whole wrapper 2) the content does not float beside left content
Do you guys have any idea as to what I am doing wrong?
here is my html code:
<div id="wrapper">
<header></header>
<nav>
</nav>
<div id="content">
<div id="left">
<img src="Images/headerOne.png" width="356" height="46" alt="Top Quality Lumber" title="Top Quality Lumber">
<p>Misty Mountain Wood Products is located just east of Edson in beautiful Yellowhead County, Alberta. We offer a complete service from cutting the tree to the finished product. Our mill produces top quality Canadian timber and lumber.</p>
<img src="Images/headerTwo.png" width="356" height="46" alt="Board and Batten siding" title="Board and Batten">
<p>Use our unedged boards (2nd-cut slabs) to create rustic Board-on-Board siding on pole or frame buildings. Great for animal shelters, machine sheds, hay sheds, garden shed, playhouse, barns, wind fencing etc...</p>
<img src="Images/headerThree.png" width="356" height="46" alt="Deal Direct with the Mill" title="Deal Direct">
<p>this is where you write whatever</p>
</div><!--this is the end of the left div-->
</div> <!--this is the end of the content-->
<div id="column">
<img src="Images/shed01.jpg" alt="shed" title="shed">
<img src="Images/batten01.jpg" alt="batten" title="batten">
<img src="Images/shed02.jpg" alt="shed2" title="shed2">
</div><!--this is the end of the column-->
</div><!--this is the end of the wrapper-->
and my css
#wrapper{width: 960px;
margin: 0 auto;
background-color: #4c5834;}
#content{padding-bottom: 10px;
padding-left: 20px;
width: 940px;
float: left;
color: #ffffff;}
#left{width: 600px;
padding-top: 20px;
padding-right: 15px;
padding-left: 15px;
float: left;
background-color: #838b73;}
#column{width: 220px;
background-color: #838b73;
padding-top: 25px;
padding-left: 15px;
padding-right: 15px;
float: right;
margin: 0 auto;}
at the moment it's completely frustrating me and I have no clue what to do
Add float:left to your wrapper class
And move the div with id column to inside the content div.
Example here http://jsfiddle.net/S6g6H/1/
Html
<div id="wrapper">
<header></header>
<nav>
</nav>
<div id="content">
<div id="left">
<img src="Images/headerOne.png" width="356" height="46" alt="Top Quality Lumber" title="Top Quality Lumber">
<p>Misty Mountain Wood Products is located just east of Edson in beautiful Yellowhead County, Alberta. We offer a complete service from cutting the tree to the finished product. Our mill produces top quality Canadian timber and lumber.</p>
<img src="Images/headerTwo.png" width="356" height="46" alt="Board and Batten siding" title="Board and Batten">
<p>Use our unedged boards (2nd-cut slabs) to create rustic Board-on-Board siding on pole or frame buildings. Great for animal shelters, machine sheds, hay sheds, garden shed, playhouse, barns, wind fencing etc...</p>
<img src="Images/headerThree.png" width="356" height="46" alt="Deal Direct with the Mill" title="Deal Direct">
<p>this is where you write whatever</p>
</div><!--this is the end of the left div-->
<div id="column">
<img src="Images/shed01.jpg" alt="shed" title="shed">
<img src="Images/batten01.jpg" alt="batten" title="batten">
<img src="Images/shed02.jpg" alt="shed2" title="shed2">
</div><!--this is the end of the column-->
</div> <!--this is the end of the content-->
</div><!--this is the end of the wrapper-->
CSS
#wrapper{width: 960px;
margin: 0 auto;
background-color: #4c5834;
float:left;
}
#content{padding-bottom: 10px;
padding-left: 20px;
width: 940px;
float: left;
color: #ffffff;}
#left{width: 600px;
padding-top: 20px;
padding-right: 15px;
padding-left: 15px;
float: left;
background-color: #838b73;}
#column{width: 220px;
background-color: #838b73;
padding-top: 25px;
padding-left: 15px;
padding-right: 15px;
float: right;
margin: 0 auto;}
Change your CSS to:
#wrapper{
width: 960px;
margin: 0 auto;
background-color: #4c5834;
}
#content{
padding-bottom: 10px;
padding-left: 20px;
width: 600px;
float: left;
color: #ffffff;
}
#left{
padding-top: 20px;
padding-right: 15px;
padding-left: 15px;
background-color: #838b73;
/****I removed the width and float from here****/
}
#column{
background-color: #838b73;
padding-top: 25px;
padding-left: 15px;
padding-right: 15px;
float: left;
width:200px;
margin: 0 10px;
}
Here is a fiddle: http://jsfiddle.net/YpukY/
Just so you know, you want the total width (object width + padding + margin + border) of both columns to be less than the width of the container.
You can float them both left as long as they're not too wide they'll be side by side.
Not sure if you wanted the column div to float to the left of the main div, or wanted a right div next to your left.
I have added both, here: http://jsfiddle.net/nivas/afZx6/
The idea is that the width of the wrapper should be large (wide) enough to hold all of the divs side by side. If not the floated divs would wrap around to the "next line".
The new HTML (removed some content to make things more clear):
<div id="wrapper">
<header></header>
<nav></nav>
<div id="content">
<div id="left">
<p>this is where you write whatever</p>
</div>
<div id="right">A new column, within the "content"</div>
</div>
<div id="column">The far right column</div>
</div>
So in the CSS below,
width(2) should be >= width(3) + margin(3) + padding(3) + width(4) + margin(4) + padding(4)
width(1) should be >= width(2) + margin(2) + padding(2) + width(5) + margin(5) + padding(5)
(again removed some rules for clarity):
#wrapper { /*1*/
width: 700px;
background-color: #4c5834;
}
#content { /*2*/
width: 500px;
float: left;
color: #ffffff;
background-color: #ededed;
}
#left { /*3*/
width: 300px;
float: left;
background-color: #838b73;
}
#right { /*4*/
background-color: yellow;
float: left;
height: 55em;
color: black;
width: 150px;
}
#column { /*5*/
width: 40px;
background-color: #838b73;
float: left;
height: 35em;
}
Your right column isn't floating beside your left content because there's not enough room in the wrapper. Your wrapper is 960px and your left content is 940px - there's no space for a 220px column next to it.
As for the wrapper, it looks like you'll want to add a height assignment; otherwise that wrapper is 960px x 0px
You float the #content with 940px to the left and the #column with 220px to the right. The #wrap has 960px so both of #content and #column don't fit inside #wrap. So if your propose is to float #content with #column then you have to reduce the widths. If your propose is to float #left with #column you have to put #left and #column inside #content
You need to give '#wrapper' the appropriate size to contain '#content' and '#column', that way you won’t see this particular issue anymore.
For example:
Total '#content' width (“width”640+”Padding”20) + Total '#column' width (“”width”220+”Padding”15+15) = appropriate '#wrapper' width
960+250 = 1210px
Then you will get what you want.
Yet you will find another issue, if you declared a background to your '#wrapper' you won’t see it because wrapper won’t be able to define the floated elements size.
To fix that add the next '< div style=”clear:both;” >< /div >' before your closing wrapper.
In addition, “I think” if you set the float of '#column' to left instead of right, you will get the same effect and it will be easier for you to understand what’s going on.
Hopefully it clarified the Issue; else I’m happy to provide more explanation.
Good luck!
IN-ACTION:
<div id="wrapper">
<div id="content">
<div id="left">
<img src="Images/headerOne.png" width="356" height="46" alt="Top Quality Lumber" title="Top Quality Lumber">
<p>Misty Mountain Wood Products is located just east of Edson in beautiful Yellowhead County, Alberta. We offer
a complete service from cutting the tree to the finished product. Our mill produces top quality Canadian timber
and lumber.</p>
<img src="Images/headerTwo.png" width="356" height="46" alt="Board and Batten siding" title="Board and Batten">
<p>Use our unedged boards (2nd-cut slabs) to create rustic Board-on-Board siding on pole or frame buildings. Great for
animal shelters, machine sheds, hay sheds, garden shed, playhouse, barns, wind fencing etc...</p>
<img src="Images/headerThree.png" width="356" height="46" alt="Deal Direct with the Mill" title="Deal Direct">
<p>this is where you write whatever</p>
</div><!--this is the end of the left div-->
</div> <!--this is the end of the content-->
<div id="column">
<img src="Images/shed01.jpg" alt="shed" title="shed">
<img src="Images/batten01.jpg" alt="batten" title="batten">
<img src="Images/shed02.jpg" alt="shed2" title="shed2">
</div><!--this is the end of the column-->
<div style="clear:both"></div>
</div><!--this is the end of the wrapper-->
CSS
#wrapper{width: 1210px;
margin: 0 auto;
background-color:#F00;
}
#content{padding-bottom: 10px;
padding-left: 20px;
width: 940px;
float: left;
color: #ffffff;}/*960*/
#left{width: 600px;
padding-top: 20px;
padding-right: 15px;
padding-left: 15px;
float: left;
background-color: #838b73;}/*630*/
#column{width: 220px;
background-color: #838b73;
padding-top: 25px;
padding-left: 15px;
padding-right: 15px;
float:left;
margin: 0 auto;}/*250*/
Related
I have code that embedded video within text. However the space between the title and the video
is too high.
<section id="Number">
<article class="container">
<div class="row">
<div class="span12">
<div class="sub_header">
<h2>ABC Number</h2>
The following video will be saparated too high from ABC Number with only one line (but the line seems too high)
<div class="video">
<div class="vdwrapper">
<div class="fluidvids" style="width:100%;position:relative;padding-top:56.2%">
<iframe src="https://player.vimeo.com/video/87745355?
title=0&byline=0&portrait=0" width="100%" height="100%"
frameborder="0" style="position:absolute;top:-0.85px;left:0"></iframe>
</div>
</div>
</div>
<div class="featurecont"> <p> Number is a proxy phone number assigned to you when
you sign up on with your regular mobile number.</p>
<p>Number can be used in many ways, you can register your Number as a separate
profile on can keep your real phone number entirely anonymous. You can share your
Number with lesser known people or acquaintances that you meet at various places, or
while posting Ads. This way, people can only reach you on and cannot call you on your
personal mobile number.
</p>
<p>Another cool advantage of Number is that your Number can also be transferred to
non-SIM devices like , etc. This would allow your kids and family members to stay
connected with you and have safe and secure communications.</p></div>
</div>
</div>
</div>
The css is as follows:
.chaatzvideo {
position: relative;
padding-top: 50px;
padding-bottom: 50px;
background: url('../images/tv.png') center center no-repeat;
background-size: 78%;
}
.row {
margin-left: -20px;
*zoom: 1;
}
.span12 {
width: 980px;
}
.vdwrapper {
margin: 0 auto;
text-align: center;
width: 75%;
}
.container,
.navbar-static-top .container,
.navbar-fixed-top .container,
.navbar-fixed-bottom .container {
width: 980px;
}
#Number .sub_header h2{background: url('../images/features/Chaatz-Notop.png') no-repeat
center top; padding-bottom: 50px; padding-top:110px}
You are having padding top and bottom for "#Number .sub_header h2"... try to use something like this
#Number .sub_header h2 {
background: url('../images/features/Chaatz-Notop.png') no-repeat center top;
padding-bottom: 20px;
padding-top:20px
}
DEMO
Okay now, I've got kind of a big one.
I'm working off a base wireframe (attached) and I'm having trouble implementing this layout. Basically, we've got a container div that has several more divs inside of it. Each of the interior divs are the components of the product and all have the exact same structured content flow - an image, title of the product, and links to the documentation. In the wireframe there are 7 component divs displayed (one is kinda hidden under my MSPAINT).
Desired achievements
The title and links must float next to the image icon, regardless of font size/line-height of the text of either.
The title MUST stay on one line. It is not allowed to wrap.
The interior divs must line up next to each other until they don't fit anymore, then wrap to the next line.
I can dynamically load content into the container div, but that div needs to be able to handle differing numbers of components. When users select product type and version, the number of components can and will change.
What is known
Some component titles will be short (7-ish chars) some will be long (27-ish chars).
All icons will be roughly 50x50 px.
There will be, at most, 8-9 component divs for some selected products.
There will be, at fewest, 3 component divs for some selected products.
Things I've given up on
Fine, we can fix the width and height of the component divs, see if I care.
Multiple divs. Whatever. The component divs don't need to have more nested divs. I'm an idiot and that was foolishness (I'm sure the answer is a component div with only an image and 2 paragraph elements, with the image floating left).
The code I've developed is huge and ugly as I've tried and commented out many things. Here's a jsFiddle with some generic code that I think has a minimal amount of damage done to it.
HTML
<div id="container">
<div class="component" id="1">
<div class="icon">
<img src="img.png"></a>
</div>
<div class="title">
<p>Product Item #1</p>
</div>
<div class="links">
<p>HTML PDF</p>
</div>
</div>
<div class="component" id="2">
<div class="icon">
<img src="img.png"></a>
</div>
<div class="title">
<p>Product Item 2</p>
</div>
<div class="links">
<p>HTML PDF</p>
</div>
</div>
...
// More component divs here.
</div>
CSS
#container {
border: 1px solid red;
overflow: auto;
margin-left: auto;
margin-right: auto;
width: 900px;
}
.component {
border: 1px solid black;
margin: 3px;
overflow: auto;
float: left;
padding: 3px;
}
.icon {
float: left;
}
Thanks so much for your help!
Maybe I would have done something like this FIDDLE
Component structure:
<div class="component" id="1">
<img class="icon" src="http://upload.wikimedia.org/wikipedia/commons/thumb/4/43/SemiPD-icon.svg/50px-SemiPD-icon.svg.png">
<h1 class="title">Generic Product Name #1</h1>
<p class="links">
HTMLPDF
</p>
</div>
I made also some changes to the css part:
#container {
border: 1px solid red;
overflow: auto;
margin-left: auto;
margin-right: auto;
width: 600px;
padding-bottom: 3px;
}
.component {
border: 1px solid black;
margin-top: 3px;
margin-left: 3px;
overflow: auto;
float: left;
padding: 5px;
}
.title {
margin-left: 55px;
font-size: 1.0em;
font-weight: bold;
}
.links {
margin-left: 55px;
}
.icon {
float: left;
}
I've been on this for days and read every conceivable article on css, overflow, and layout.
I have a page with a banner (position: absolute), below which is a div containing two block divs. The second block div, in turn has another div containing text.
I would like the inner-most DIV display a scroll bar when the window is resized.
I've read the posting on ensuring height is set on all containing elements, I've set overflow-y: auto in all the right places. Just doesn't work.
The containing DIV looks like this: http://i.imgur.com/oDHM4.png
I want the green part to scroll when the browser window is resized (y-direction only).
Scrollable DIVs in any design are so useful... but shouldn't be this hard.
Any and all help appreciated.
Danny
MARKUP
The markup is very simple:
<body>
<div id="page-header" style='background:blue;'>page-header</div>
<div id="page-content">
<div id="configContent" style='height: inherit; background: steelblue;'>
<h1 id='panTitle'>Panel Title</h1>
<div id='panProbes' class='libPanel' style="background: maroon;">
<p>panProbes</p>
<div id="probesCT1" class="configtable" style='background: red;'>
<p class='pTblTitle'>probesCT1</p>
</div>
<div id="probesCT2" class="configtable" style='background: grey;'>
<p>probesCT2</p>
<div id='pTbl' style='background: green;'>
<div class='pRow'>1st para in pTbl</div>
<div class='pRow'>some data</div>
<div class='pRow'>some data</div>
<div class='pRow'>some data</div>
<div class='pRow'>some data</div>
<div class='pRow'>some data</div>
<div class='pRow'>some data</div>
<div class='pRow'>some data</div>
<div class='pRow'>some more data</div>
<div class='pRow'>some more data</div>
</div>
</div>
</div>
</div>
</div>
</body>
** STYLING **
Here's the CSS cut down to the core essence:
html, body {
position:absolute;
margin: 0px;
padding: 0px;
height: 100%;
width: 1010px;
overflow: hidden;
}
#page-header {
position: absolute;
left: 5px;
top: 5px;
height: 60px;
width: 100%;
}
#page-content {
width: 100%;
height: 100%;
margin-top: 95px;
}
#configContent {
height: 100%;
width: 300px;
padding-left: 0px;
border-width: 3px;
margin-left: 30px;
margin-right: auto;
}
.libPanel { height: 100%; }
#probesCT1 { width: 150px; margin: 0 auto 0 30px; }
#probesCT2 {
width: 200px;
/* height: 100%; */
margin: 0 30px 50px 30px;
padding: 0 10px 10px 10px;
}
#pTbl { overflow-y: auto; }
.pRow { margin-bottom: 10px; }
For overflow-y: auto to work and make scroll bars, that div must have a specific height set. So in this example (with your html above) I set it to 200px, which was less space than necessary to display the content without a scroll bar, and thus shows a scroll bar. However, if set to 100% it does not work, because 1) you need to uncomment the height of the containing divs, and 2) your content in that div is less than needed to fill the height of the div, so no scroll bar shows up. With more content added, you get a scroll bar.
What I think you really want is to insure you always have a scroll bar if needed, but even then, you need to make sure the div does not extend below the bottom of the page or you could still have problems with the scroll bar itself going off the page. I've configured something that is probably more what your intent is, but note that I had to use multiple nested relative or absolute elements to achieve the effect. I also had to guess on some height positioning for the top of elements to clear your titles.
I am attempting a very simple procedure here, basically trying to center the client logos within this main clients div. I've just recently started with this web design business and while I can read some of the solutions out there, I'm having trouble applying them to my structure.
Basically I have a few client boxes, each is going to have a PNG image inside of them:
<div id="clients">
<div class="client-box">CLIENT LOGO</div>
<div class="client-box">CLIENT LOGO</div>
<div class="client-box">CLIENT LOGO</div>
<div class="client-box">CLIENT LOGO</div>
<div class="client-box">CLIENT LOGO</div>
</div>
I'd like to be able to center the client-box's on the client's div that has a fixed weight. I've tried using display: inline-block but that didn't seem to do much. I'm assuming that's because I've already forced them to float: left but I don't know how I can maintain their position in the div without doing so. Like I said I'm quite a novice with CSS and this is what I've been doing for all my CSS.
Here's what I have for clients and client-box CSS:
#clients {
background-image: url("img/images/clients_bg.png");
border-bottom: 1px solid #333333;
border-top: 1px solid #666666;
float: left;
margin-top: 120px;
padding: 10px;
width: 778px;
}
.client-box {
background: none repeat scroll 0 0 #bcb546;
float: left;
font-family: verdana;
font-size: 11px;
height: 60px;
margin-right: 10px;
opacity: 0.8;
padding-top: 40px;
text-align: center;
width: 100px;
}
.client-box:hover {
opacity: 1;
}
From my understanding, this shouldn't be hard to achieve, but so far I have not had any luck probably because my brain is fixated on a certain way of doing things and it just won't budge. Any help would be greatly appreciated.
You can see the live site here.
Thank you SO.
I've tried using display: inline-block
but that didn't seem to do much.
float: left forces display: block, so display: inline-block would have no effect.
On .client-box, you need to:
remove float: left
add display: inline-block.
Finally, on the parent element (#clients), you need to add text-align: center.
If your outer div is of a fixed width you can set the margins for the inner div to take up the appropriate space.
eg:
<div class="outer">
<div class="inner">
stuff
</div>
</div>
CSS
.outer { width: 600px; }
.inner { width: 400px; margin-left: 100px; margin-right: 100px; }
Alternatively you can use margin-left: auto; margin-right: auto; however that (like everything else in the world) doesn't work in IE.
Hope this helps!
I will add a wrapper to the client-boxes, whose width is equal to the total width of client-boxes.
For example, in the live site you post above, there are 5 client boxes, and each of them are 100px width with 10px margin-right. So add a div wrapper with width 5 x (100 +10) = 550px, and center the wrapper with "margin-left:auot" and "margin-right:auto".
<div style="width: 550px;margin-left: auto; margin-right: auto;">
<div class="client-box">CLIENT LOGO</div>
<div class="client-box">CLIENT LOGO</div>
<div class="client-box">CLIENT LOGO</div>
<div class="client-box">CLIENT LOGO</div>
<div class="client-box">CLIENT LOGO</div>
</div>
It doesn't stay where I want it, look at this:
<div style="float: left; width: 30%">
<img src="{avatar}" alt="" />
</div>
<div style="float:right; width: 70%; text-align: left">
{message}
</div>
<div style="clear:both"></div>
Internet Explorer:
Mozilla Firefox:
I want the text to be in the top (tried vertical-align: top), and i'd like the image to be in the white box in IE.
Hope someone more skilled can help me out.
Thanks!
Can't figure out the problem :/
Edit: Added whole code
* { padding: 0; margin: 0; }
body {
font: 11px Geneva, "Trebuchet MS", Arial, Verdana, sans-serif;
width: 999px;
background: #EFEFEF;
}
#content {
width: 400px;
}
.thread-content {
padding: 5px;
border: 1px solid #CECFCE;
background: #FFF;
}
div.header {
border: 1px solid #CECFCE;
background: #FFF;
margin-bottom: 10px;
}
<div id="content">
<div class="header">{title}</div>
<div class="thread-content">
<div style="float: left; width: 30%; padding: 5px">
<img src="{avatar}" alt="user avatar" />
</div>
<div style="float: right; width: 70%; text-align: left">
{message}
</div>
<div style="clear:both"></div>
</div>
</div>
Be sure the margin of both are set to 0:
<img src="{avatar}" alt="" style="float: left; width: 30%; margin: 0px"/>
<div style="float:right; width: 70%; text-align: left; margin: 0px">
{message}
</div>
<div style="clear:both"></div>
As css can be really tricky, some other solutions to try:
Let both float left, should make no difference.
Make sure the border doesn't increase the size.
Descrease the width of one a bit, IE is stubborn.
This happens because the sum of the (external) widths of the two floating divs is larger than the internal width of the external box, so they don't fit in the same row.
Try increasing the width of the external div, decreasing its padding, decreasing the width or margin or padding of the internal boxes.
Code works fine when I tried it. You sure there isn't any padding or margin on the image or the text? That would mess up the percentages you're using. If you have it examine the image and text in Firebug to see what styles are being applied.
When you say width: 30% or width: 70% it implies the width of the content inside the div excluding the padding, border and margin of the div. Looking at the images I am sure you have added some padding etc to both divs. Also I do not see any 'background: #fff' in your code, so I am not sure which one is the 'white' box.
Ok, did I get voted down because I used a table?
I am not by trade a designer, I am actually a programmer and I know there are hard-core css designers that cringe at the idea of using a table layout but it seems to works for me. The graphic designers that I work with give auto generated table layout from fireworks to work with which is a real pain.
Anyway the way I personally would try to accomplish the dersired effect though pure css would be more like.
<html>
<head>
<title>SandBox</title>
<style type="text/css">
#outerDiv
{
margin:0;
background-image:url(myImage.gif);
background-position:top left;
background-repeat:no-repeat;
padding-left:30%;
min-height:200px;
background-color:#777777;
}
#innerDiv
{
background-color:#333333;
}
</style>
</head>
<body>
<div id="container" style="width:500px;">
<div id="outerDiv">
<div id="innerDiv">content goes here</div>
</div>
</div>
</body>
Note: I am not a designer. I also made this a wiki. So please edit or at least leave a comment if you going to vote down.