CSS div content size question - html

I have a structure like this
<div id="first">
<div id="second">
<div id="third">
<div id="fourth">
text
</div>
<div id="fourth">
text2
</div>
</div>
Some other stuff...
</div>
</div
Here's the css for it at the moment:
#first {
width:960;
}
#second {
position:relative;
}
#third {
position:relative;
top:0;
right:0;
}
#forth {
position:relative;
top:0;
left:0;
}
Now I would like from the fourth items to stay in a row and from the third item to stay on the right side of the second div. The second div also has a width 960 like the first one.
What's the problem with this? why it isn't working?

Edited and should work(untested):
<div id="first">
<div id="second">
<div id="third">
<div class="fourth"> <!-- changed to class -->
text
</div>
<div class="fourth"> <!-- changed to class -->
text2
</div>
</div>
Some other stuff...
</div>
</div> <!-- was missing closing bracket -->
And the style:
#first {
width:960px; /* was missing px */
}
#second {
position:relative;
}
#third {
float:right /* Makes the element float on the right side. Might want to clear in a later id/class to avoid quirks */
position:relative;
/* Removed redundant top:0; and right:0; */
}
.fourth { /* Changed to class and fixed spelling */
position:relative;
/* Removed redundant top:0; and right:0; */
}
ID's should be used for elements that will only be used once. Classes should be used for elements that can/will be used multiple times.

For the forth div, why not use inline-div? [not sure it works on IE7 and below]..and im think the third can be floated to the right.
Also shouldn't you be using classes as opposed to multiple elements with the same id?
#third {
float: right;
position:relative;
top:0;
right:0;
}
#forth {
display:inline-block
position:relative;
top:0;
left:0;
}

First, 960 isn't a width. Without a units specifier, it's just a number. 960px is a width.
Second, those other divs are positioned correctly, but their widths are 100% (the default), so they just look like they're stacked. The positioning is not noticeable because of that.
Edit: You also misspelled "#fourth" in your CSS selector.

Related

How to place a DIV in the bottom of the first page in print mode using html and css bootstrap

I want the output to be something like this. I tried to make the <div> element position: absolute but it pushed all the way down to the last page.
Instead I want to accomplish this without using any PDF libraries.
many different ways to do this. Here are two. The first uses flexbox and the second uses absolute positioning.
answer updated.
.container2{
display:flex;
height:100vh;
width:100vw;
justify-content:center;
}
#page4{
background:pink;
position:relative;
}
#bottom2{
position:absolute;
height:20vh;
width:30vw;
left:calc(50vw - 30vw/2 + 10vw);
background:purple;
top:calc(100vh - 20vh);
}
#content{
height:35vh;
width:80vw;
background:white;
margin-top:10vh;
}
<div class='container2' id='page4'>
<div id='content'>
</div>
<div id='bottom2'></div>
</div>
<div class='container2' id='page5'>
</div>
<div class='container2' id='page6'>
</div>

resize css property on absolutely positioned div?

My site is like this:
Left div | right div
Inside my left div, I have a position absolute element "custombox" that shows up over the "right div" (its got z-index:999), just because I want the code to be on the "left div side". My custombox has a css property "resize:both", which does not work. WHen I put a "position:relative" on my leftbox, then the position of my "custombox" is messed up and literally goes into "left div", which I don't want. How can I make my "custombox" resizable? (if absolutely needed, js plugins are okay)
.leftdiv {
background:red;float:left;width:50%;height:300px;
}
.custombox {
position:absolute;
top:10px;
right:50px;
z-index:999;
background:yellow;
height:100px;
width:100px;
resize:both;
}
.rightdiv {
background:blue;float:right;width:50%;height:300px;
}
<div>
<div class="leftdiv">
<div class="custombox">
I like staying in the blue, but I want to be resizeable too.
</div>
He
</div>
<div class="rightdiv">
blue
</div>
</div>
Fiddle attached:
http://jsfiddle.net/axhqg20x/3/
Changing the overflow property of .custombox to scroll makes it resizable:
.custombox {
position:absolute;
top:10px;
right:50px;
z-index:999;
background:yellow;
height:100px;
width:100px;
resize:both;
overflow:scroll;
}
http://jsfiddle.net/axhqg20x/4/

Image background doesn't fill in all divs

Background should shows in all divs but it's not visible.
http://jsfiddle.net/uxUqJ/1/
I need to my backgroud be shows in all divs. Background is defining in styles container div. Etc.
<div id="container">
<div id="1"></div>
<div id="2"></div>
<div id="3"></div>
</div>
How can I fix this?
I think you need to add overflow:auto; to your css... I've also removed the quotes
#content{
width:1049px;
overflow:auto;
background: #000 url(http://s1.wp.com/wp-content/themes/pub/dark-wood/images/postflowerback.png) ;
}
the Div currently has no height... however what do you want to do with the background regards repeating or position, here's a good reference point https://developer.mozilla.org/en/CSS/background
You must specify height property and set repeating of background.
#content{
width:349px;
height: 700px;
...
}
Alternately, you could add <div style="clear:both;"></div> after the closing for text3. This would then stretch the container divs around the elements even though they are floated.
You have your elements floated. You need to clear the float before closing the wrapper element in order to have the #content to grow normally:
See this working Fiddle Example!
CHANGE YOUR MARKUP TO THIS:
<div id="content">
<div id="text">
<div id="text_1">...</div>
<div id="text_2">...</div>
<div id="text_3">...</div>
<div style="clear:both;"></div> <!-- Add this line -->
</div>
</div>
Additionally, you can remove the inline style and use a class.
Change your css to smart way
<style>#content{ display:table;
width:1049px;
background: url("image_src") ;
}
#text{
display:table-row;
width:1049px;
padding-left:27px;
padding-right:28px;}
#text_1,#text_2,#text_3{ display:table-cell;
padding-left: 40px;
width: 278px;
}#text_3{
padding-right:40px;
}
</style>
Clear the #text div.
add the following styles:
#text {
zoom:1; /* For IE 6/7 (trigger hasLayout) */
}
#text:after {
content:"";
display:table;
clear: both;
}
DEMO:
http://jsfiddle.net/uxUqJ/13/

CSS - How to float correctly into pseudocolumns

Please see the image below. Assume that these are all divs with the given ids. Also, let's assume that they carry the same weight semantically so they should be at the same point in the html hierarchy:
<div id="1"></div>
<div id="2"></div>
<div id="3"></div>
<div id="4"></div>
What is the proper CSS to position them correctly so as to appear as in the image below? The solution should flow properly as the browser is resized and preferably work on >=IE7.
Think of this as an action panel (#1) and 3 information displays (#2, #3, #4) so it is probably expected for 2,3,4 to expand in width to fill the browser window and flow below the action panel as the browser shrinks.
Use this
#id1, #id2, #id3, #id4{ float:left; }
#id1{ width:50%; height:300px; background-color:red; }
#id2{ width:50%; height:50px; background-color:blue; }
#id3{ width:25%; height:250px; background-color:green; }
#id4{ width:25%; height:250px; background-color:yellow; }
demo at http://jsfiddle.net/gaby/wsEt6/
I altered your ids as they are not allowed to be numeric.
http://www.w3.org/TR/html4/types.html#h-6.2
EDIT: I just read the bottom piece, so my example is fixed (width)...
An id can't be a number, but to keep your example I'll use the numbers spelled out.
CSS:
.container { overflow:hidden; /* Clear Floats */ width:400px; }
#one, #two, #three, #four { float:left; }
#one { width:200px; }
#two { width:200px; }
#three { width:100px; }
#four { width:100px; }
Example: http://jsfiddle.net/DOSBeats/CqSTY/
I would suggest to use container divs for those. Something like this:
<div id="one" class="left"></div>
<div class="right">
<div id="two"></div>
<div id="three"></div>
<div id="four"></div>
</div>
Wrap #1, #2, #3, #4 in a container div, #0.5. Float the #1 div left and have a width of 50%. Wrap #1, #2, #3 in a container div named, #container - float that right with a width of 50%.
Do the same thing for the divs inside #container
check if this helps you out just remember to modify divs as you need it all in the div play with them according to the screen size you need :
http://jsfiddle.net/z747R/

Vertical alignment and spacing for two divs

I'm stuck with a vertical align issue. I have 2 divs. First one has auto height (depends on the browser size), the other one has fixed height and is positioned at the bottom of page. Also, the second div needs margin.
An exact example of what I want to do:
http://img199.imageshack.us/img199/9569/79106387.jpg
I tried:
<html>
<body>
<style>
* { margin: 0; padding: 0; }
body { background: #a7daf6; }
</style>
<div style="width:200px; height:100%; position:absolute; background:#000; opacity:0.6"> </div>
<div style="width:200px; height:40px; position:absolute; background:#eee; bottom:0; opacity:0.6"> </div>
</body>
</html>
but I can't give margin to second div. Any ideas?
try to add this for first div:
<div style="width:200px; position:absolute; top:0px; bottom: 42px; background:#000; opacity:0.6"> </div>
and remove margin-top from second one
If I understand correctly, you can simply apply to the first <div> this style: top:-42px.
If you need content inside the <div>, you can add another <div> with padding-top: 42px.
Like this:
Live Demo
<div style="width:200px; height:100%; position:absolute; background:#000; opacity:0.6; top:-42px">
<div style="padding-top:42px; color:#fff">hello</div>
</div>
Giving any element an absolute position will remove it from the flow of the document.
Not matter what the margin is other elements will not be affected.