How to place a Div at the bottom of another div? - css

I want to place one DIV (ID eSharing) at the bottom of another DIV (content-primary)
Here is the CSS class for DIV (ID content-primary)
.layout-3 #content-primary {
padding: 0 10px;
width: 502px;
}
#content-primary.article {
padding-bottom: 2.5em;
}
#content-primary {
width: 501px;
}
#content-primary {
clear: left;
float: left;
margin: 12px 0 0;
padding: 0 10px;
width: 500px;
}
Here is the CSS class for DIV ( ID eSharing)
#eSharing {
height: 230px;
margin: 12px 0 0;
overflow: auto;
padding: 0 10px;
position: relative;
}
Screeshot link http://i.stack.imgur.com/bMqXD.png
Screenshot 2

unfortunately, CSS doesn't have the capability to position an item relative to another item in the general case. It seems like the solution may be simple for you though.
You are floating one div and want to place another div right below it?
Why not put both divs inside an outer div, and float the outer div instead? The two inner divs will appear one on top of the other this way.
EDIT: I've kinda spelled it out, but here's an example:
<div id="outer">
<div id="content-primary">Your content</div>
<div id="eSharing">Other content</div>
</div>
and for the CSS, don't float either content-primary or eSharing. Instead, do something like this:
#outer {
clear: left;
float: left;
}
#content-primary {
width: 501px; /* why? */
}
#content-primary {
margin: 12px 0 0;
padding: 0 10px;
width: 500px;
}
#eSharing {
height: 230px;
margin: 12px 0 0;
overflow: auto;
padding: 0 10px;
}

EDIT: Here is another option where you have a main content area "a", sidebar "b", and two adjacent containers below "c" and "d".
Demo: http://jsfiddle.net/L655v/
One more that has a main content area "a", sidebar "b" and a full-sized content area "c" below it...
http://jsfiddle.net/L655v/1/
(trying to mimic what your screen shots may be implying).
Not sure exactly which you're going for but here are several layout options...
Demo: http://jsfiddle.net/aNqak/
Here is the code I used in my fiddle...
HTML...
<div id="a">a</div>
<div id="b">b</div>
<br /><br />
<div id="c">
c
<div id="d">d</div>
</div>
<br /><br />
<div id="e">e</div>
<div id="f">f</div>
CSS...
#a {
background-color: #999;
}
#b {
background-color: #ddd;
}
#c {
background-color: red;
padding: 5px;
}
#d {
background-color: pink;
}
#e {
background-color: blue;
float: left;
width: 75%;
}
#f {
background-color: green;
float: right;
width: 25%;
}

Related

Child of parent with min-height:300px is not inheriting parent's height

I have the div block as shown below:
<div className={'row ge-container'}>
<div className={'a-span3 ge-container-navigation'}>
hello
</div>
<div className={'a-span9 ge-container-content'}>
Okay
</div>
</div>
And the css as
.ge-container {
min-height: 300px;
}
.ge-container-navigation {
background-color: $light-gray-background;
display: inline-block;
float: left;
height: inherit;
margin: 5px 0 0 0;
padding: 10px 8px 0 8px;
border: 1px solid $gray;
}
.ge-container-content {
display: inline-block;
height: inherit;
}
The child is not inheriting the height of parent. I tried the solution by setting min-height of child to inherit by seeing some answers. But, that fails when the height goes above 300px.
Can anyone help with this
Please use display: flex; CSS in .ge-container parent.
This code makes a child flex-box of height 100% using CSS only.
.ge-container {
min-height: 300px;
display: flex;
}
Updated snippet :-
.ge-container {
min-height: 300px;
display: flex;
}
.ge-container-navigation {
background-color:red;
display: inline-block;
float: left;
height: inherit;
margin: 5px 0 0 0;
padding: 10px 8px 0 8px;
border: 1px solid $gray;
}
.ge-container-content {
display: inline-block;
height: inherit;
}
<div class="row ge-container">
<div class="a-span3 ge-container-navigation">
hello
</div>
<div className="a-span9 ge-container-content">
Okay
</div>
</div>
You can also try it with javascript/jquery
$('.ge-container-navigation').height($('.ge-container'));
and, if you want it to update itself in rotation mode:
setInterval(function(){
$('.ge-container-navigation').height($('.ge-container'));
}, 10);
Thanks

Displaying 1 text box and 3 images on the same row

Was wondering if i can display 1 text box and 3 images on the same row? All the images are the same size. If possible aswell i'd ideally like a some text underneath each image aswell?
heres the code:
<div class="row">
<div class="side-bar">
<h3> Recent Work </h3>
<p>Here's some of my latest work, covering web design, branding and identity.</p>
View the Portfolio →
</div>
<div class="recent-wrap">
<img src="img/body-metrix.png">
<img src="img/body-metrix-logo.png">
<img src="img/market.png">
</div>
</div>
.row {
display: inline;
float: left;
}
.side-bar {
padding: 10px;
background-color: #f3f3f3;
height: 200px;
width: 250px;
}
.side-bar h3 {
font-weight: bold;
font-size: 19px;
margin-bottom: 5px;
}
.side-bar p {
font-size: 14px;
}
.side-bar a {
font-size: 13px;
}
.recent-wrap img {
max-width: 225px;
min-height: 125px;
border-style: solid;
border-width: 1px;
border-color: #000000;
margin-right: 20px;
margin-bottom: 20px;
}
Ive searched the internet but no luck as yet.
thanks in advance.
There are a number of ways to do this, one example is to float the two child elements:
.side-bar, .recent-wrap {
float: left;
}
This will only work if there is enough room on the parent element for the .side-bar and .recent-wrap to sit next to each other.
Example: http://jsbin.com/poxox/1/edit
CSS:
.row {
width: 250px
}
http://jsfiddle.net/3DCSd/
Here Is a working Fiddle
.row {
display: inline-block; /* changed to inline-block, you don't need
inline and float */
}
.recent-wrap a { /*changed to a , since your images are wrapped in <a> */
max-width: 225px;
min-height: 125px;
border-style: solid;
border-width: 1px;
border-color: #000000;
margin-right: 20px;
margin-bottom: 20px;
}
The rest of the CSS stayed the same
and HTML I just added the text box
<div class="row">
<div class="side-bar">
<h3> Recent Work </h3>
<p>Here's some of my latest work, covering web design, branding and identity.</p>
View the Portfolio →
</div>
<div class="recent-wrap">
<input type="text" id="ss" />
<img src="img/body-metrix.png"/>
<img src="img/body-metrix-logo.png"/>
<img src="img/market.png"/>
</div>
</div>
Try this:
.side-bar {
padding: 10px;
background-color: #f3f3f3;
height: 200px;
width: 250px;
float: left; /* added */
}
.recent-wrap {
margin-left: 270px; /* added (padding + width) of side-bar */
}
Working Fiddle
This approach let the second container stay in line with the first container even if the window size is small.
Here is the sample with textboxes below image: example

How come these DIVs will not display on the same line?

I have the following HTML:
<div id="root">
<div id="left_side">LEFT</div>
<div id="center_s">CENTER</div>
<div id="right_side">RIGHT</div>
</div>
...and CSS:
#root {
background-color: #eee;
}
#left_side {
float: left;
}
#center_s {
margin-left: auto;
margin-right: auto;
width: 65px;
background-color: #ccc;
}
#right_side {
float: right;
}
However, I get the following:
The DIV on the right is on a separate line, which is not what I want. How can I make it stay on the same line as the other DIVs?
Note: you can see a live demo and play around with the code here: http://jsfiddle.net/UDb4D/
It's because your #center_s div expands to the width of the remaining line. If you put #right_side above #center_s in the HTML order, it'll work fine.
See here:
http://jsfiddle.net/UDb4D/2/
Because the center has no float and right-floated elements need to appear first. Add float: left; to your #center_s or move the #right_side div before so it looks like this:
#root {
background-color: #eee;
}
#left_side {
float: left;
}
#center_s {
margin-left: auto;
margin-right: auto;
width: 65px;
background-color: #ccc;
float: left;
}
#right_side {
float: right;
}
<div id="root">
<div id="right_side">RIGHT</div>
<div id="left_side">LEFT</div>
<div id="center_s">CENTER</div>
</div>
I quickly hacked this up. Bare in mind that I'm a developer, not a web designer.
<div id="root" align="center">
<div id="right_side">RIGHT</div>
<div id="center_s">CENTER</div>
<div id="left_side">LEFT</div>
</div>
And...
#root {
background-color: #eee;
}
#left_side {
display: inline;
float: left;
}
#center_s {
display: inline;
margin-left: auto;
margin-right: auto;
width: 65px;
background-color: #ccc;
}
#right_side {
display: inline;
float: right;
}

Question about nested CSS?

I have a box center, and I want to color that box differently depend on the page. I try this
#center {
margin-top: 2px;
padding: 10px 20px; /* CC padding */
width: 100%;
height: 800px;
color: black;
font-size: 11px;
}
#backgroundRed{
background-color: red;
}
#container {
padding-left: 200px; /* LC fullwidth */
padding-right: 240px; /* RC fullwidth + CC padding */
}
#container .column {
position: relative;
float: left;
}
so then I would try this
<div id="containder">
<div id="backgroundRed">
<div id="center" class="column">
abc
</div>
</div>
</div>
however the background of the box does not turn to red, someone explain to me what did I do wrong? btw, I must have class="column"
Maybe what you wanted was this rule?
#backgroundRed div#center {
background-color: red;
}
That means "if div#center is a child of #backgroundRed..."
Your example should make the outer div have a red background.
Try the following code
#backgroundRed{
background-color:red;
overflow:hidden;
}

Avoiding duplicate styles in CSS

I'm trying to teach myself CSS and have the following markup:
<style type="text/css">
#content { display: block; width: 250px; height: 50px; background-color: #330000; }
/* pink */
#one { height: 25px; width: 25px; background-color: #FFCCCC; float: left; margin: 10px; }
/* hot pink */
#two { height: 25px; width: 25px; background-color: #FF0099; float: left; margin: 10px; }
/* tan */
#three { height: 25px; width: 25px; background-color: #CC9900; float: left; margin: 10px; }
/* aqua blue */
#four { height: 25px; width: 25px; background-color: #33FFFF; float: left; margin: 10px; }
/* yellow */
#five { height: 25px; width: 25px; background-color: #FFFF00; float: right; margin: 10px; }
</style>
</head>
<body>
<div id="content">
<div id="one"></div>
<div id="two"></div>
<div id="three"></div>
<div id="four"></div>
<div id="five"></div>
</div>
The page is working correctly, but I'm interested in removing the duplicate code within the CSS itself. I.e. have all height, width, float all in one defintion then override the background color for each of the #id values
When I tried:
#content { height: 25px; width: 25px; float: left; margin: 10px }
then put:
#one { background-color: #FFCCCC; }
#five { background-color: #FFFF00; float: right; }
that didn't work.
Basically I'm trying to remove the amount of duplicate markup.
What am I missing?
You have to specify the node after #content:
#content div { SAME RULES }
#one { INDIVIDUAL }
#five { INDIVIDUAL }
or you can do this:
#one, #two, #five { SAME RULES }
#one { INDIVIDUAL }
You can also give each of those divs a class name and do
.divs { SAME RULES }
#one { INDIVIDUAL }
You want:
#content div {
i.e. "All the div elements that descend from the element with the id 'content'"
I recommend giving http://css.maxdesign.com.au/selectutorial/ a read.
You could use classes. Define a base class that contains the common properties:
/* Generic class for all four elements */
div.button { height: 25px; width: 25px; float: left; margin: 10px; }
and then define 1-4 (I'm using classes here as well, as it is the best practice in many cases, but you can carry on using IDs if you want to):
div.one { background-color: #FFCCCC; ... }
div.two { background-color: #FF0099; ... }
and then assign the base class and the specific class:
<div id="one" class="button one"></div>
the "button one" part will let both classes' properties apply to the element.
Here ya go, #content div is what you want. You can go deeper if you needed, ie #content div span a would reference an anchor, nested in a span that's nested in the div that's nested in something with the ID of #content.
http://jsfiddle.net/eDhXs/
#content { display: block; width: 250px; height: 50px; background-color: #330000; }
#content div { height: 25px; width: 25px; float: left; margin: 10px; }
/* pink */
#one { background-color: #FFCCCC; }
/* hot pink */
#two { background-color: #FF0099; }
/* tan */
#three {background-color: #CC9900; }
/* aqua blue */
#four { background-color: #33FFFF; }
/* yellow */
#five { background-color: #FFFF00; }
This is where you would make use of classes. IDs are great for when you have a particular element that is unique to the page. But classes, you can define a set of attributes (even set an attribute more important than another). Furthormore, an element can have more than one class where they can't IDs
So what I would do is this
#pink { background-color: #FFCCCC; }
#hotpink { background-color: #FF0099; }
#tan{ background-color: #CC9900; }
#aquablue { background-color: #33FFFF; }
#yellow { background-color: #FFFF00; }
.box {
height: 25px;
width: 25px;
float: left;
margin: 10px;
}
And specify them in your HTML like this
<div id='pink' class='box'></div>
I like this version the best, because if you ever need to select this element in the DOM explicitly, it would look like
#pink.box {
height: a different height;
}
There are actually three alternative solutions to your problem
First solution
The first one is very close to what you've written yourself except that it should define CSS for any DIV underneath the one with the id="content":
#content div { height: 25px; width: 25px; float: left; margin: 10px }
Second solution
I should point out that this one is probably more common and gives more flexibility especially if you want subDIVs to not have common classes (in your case sizing). This one changes your markup a bit because you can define multiple CSS classes on a single HTML element:
<div>
<div class="content one"></div>
<div class="content two"></div>
<div class="content three"></div>
<div class="content four"></div>
<div class="content five"></div>
</div>
This way your CSS classes change a bit. You have to replace # with a . (dot):
.content { height: 25px; width: 25px; float: left; margin: 10px }
.one { background-color: #FFCCCC; }
...
.five { background-color: #FFFF00; float: right; }
Third solution
This one is very similar to the second one, except that it keeps the IDs of sub DIVs:
<div>
<div id="one" class="content"></div>
<div id="two" class="content"></div>
<div id="three" class="content"></div>
<div id="four" class="content"></div>
<div id="five" class="content"></div>
</div>
And CSS:
.content { height: 25px; width: 25px; float: left; margin: 10px }
#one { background-color: #FFCCCC; }
...
#five { background-color: #FFFF00; float: right; }
You have two options, the first is to use the parent container (in this case the div #content) to set default attributes to each of it's nested divs, to do this you could use code like this:
#content div {
repeat-attributes-here;
}
This will set attributes for every div inside #content.
The second option is to use classes to define the common attributes. The benefit of this is you can still have other divs with different styling options (in case you add something new where you don't want the repeated functionality.
To do this you would do this:
#one {
unique-functionality-here
}
.layout-block {
repeat functionality here
}
Then define the div in the CSS like this:
<div id="one" class="layout-block"></div>
Hope that helps!

Resources