I would want to simulate the behavior of a table with div.
I have a struct of my layout divide into three columns:
div#wrapper {
width:800px;
float:left;
height:100%;
margin-top:7px;
text-align:center;
}
div#left {
width:167px;
float:left;
padding-bottom:50px;
margin-right:3px;
}
div#main {
width:454px;
float:left;
}
div#right {
width:167px;
float:left;
margin-left:3px;
}
wrapper is the container of three columns left,main,right
div "main" have a variable content so in some case is more long and in other case is very short. When the content vary,div wrapper is adapted and it's ok but left and right columns don't adapt to wrapper.
P.S Without doctype there is no problem, infact I set the height of left, main and right to 100% but when I insert transional.dtd , the height of div is not considered.
How can resolve this problem?
Sorry for my english!!
I agree with #Neurofluxation so let's see what I can find on Google:
100% Height Layout Using CSS
and
CSS Faux Columns
You could try to insert:
min-height: 100%;
as well, to cover yourself :)
I try to use
min-height:100%;
but I can solve the problem.
I read in different forum that is not possibile with xhtml fixed height:100% with a div, and that the only one method to solve this problem is to use JQuery?
you should use jQuery
<script type="text/javascript">
$(this).load(function() {
alert(document.documentElement.clientHeight + '+' + $(window).height());
if ($(window).height() - 250 > 300)
$('#content').css('min-height', '224px');
else
$('#content').css('min-height', $(window).height() - 250);
}
);
$(this).resize(function() {
if ($(window).height() - 250 > 300)
$('#content').css('min-height', '224px');
else
$('#content').css('min-height', $(window).height() - 250);
}
);
</script>
<div id="content" style="min-height:350px;">
</div>
just change numeric digits of hights.
Related
I have tried many different techniques in order to vertically align a div to the bottom of another div, does anybody have any idea as to how I could do this? I have tried a lot of things, but nothing seems to be working! :(
<div class="containerBlog">
<div class="infoBlog">
</div>
</div>
The inner div is a cricle in my code.
CSS:
.containerBlog { position:relative; }
.infoBlog { position:absolute; }
JS:
var container = document.querySelector(".containerBlog");
var info = document.querySelector(".infoBlog");
var cHeight = container.offsetHeight;
var iHeight = info.offsetHeight;
var top = cHeight / 2 - iHeight / 2;
info.setAttribute("style", "top:" + top + "px");
Try something like that?
Wait, I totally misunderstood your question. you simply want to position the div to the bottom of the parent?
Simply absolutely position it so.
CSS:
.containerBlog { position:relative; }
.infoBlog { position:absolute; bottom:0; }
You could use the display table and vertical align technique in your css
.containerBlog {
display:table;
vertical-align:middle;
}
.infoBlog {display:table-cell;}
I don't know if I'm clear enough let me know if this helped you
Image
I tried this with the following CSS and HTML. It looks fine when the browser is of full width and scrambled when browser is resized. I WANT the elements to be where there and a HORIZONTAL SCROLL has to appear when the BROWSER is RESIZED. Pretty new to web programming. Text-align:center for positioning the center column would not work because, every time a new text is added in the left or right, it gets relocated and also center column element in ROW1(text) and ROW2(Button) do not appear along the same line. That is, text appears a bit right and the button a bit left. Text-align won't work here.
CSS:
#charset "utf-8";
/* CSS Document */
body
{
background-color:#000;
}
.wrapper
{
width:70%;
margin:0 auto;
padding:2px;
background-color:#fff;
}
.second_row
{
padding:2px;
margin-top:10px;
}
.center_container
{
width:30%;
margin:0 auto;
}
.left_container
{
width:33%;
float:left;
}
.right_container
{
width:33%;
float:right;
}
.topelements
{
margin-top:0px;
color:#777;
padding:2px;
}
.topelements a:link
{
color:#29a3cc;
}
.topelements a:active a:hover
{
color:#29a3cc;
}
.logo
{
overflow:hidden;
}
HTML code:
<div class="wrapper">
<span class="topelements float_left" >Mail us: admin#admin.com</span>
<span class="topelements float_right">Left links My xyz</span>
<span class="topelements center_container">Welcome to xyz ! Sign in or Signup.</span>
</div>
<div class="wrapper second_row">
<span class="left_container">Srini</span>
<span class="right_container">Vas</span>
<form class="center_container">
<input type="text" placeholder="Goooooooooooo!" />
<input type="submit" value="Search" />
</form>
</div>
<div class="wrapper">
If you want to align you object in the center, there are a couple of different ways. First of all, there is the text-align:center; which you don't need right now. There is also object-position:center; which basically does the same, but with an object. This way isn't the best, but you could add a certain percentage of padding to either side but that's not recommended. Lastly, there's alignment-adjust:central;. This may not be perfect for your situation but just try out all of these and see if they work. Good luck!
One way that would work is to set your wrapper width to a fixed value (something in 800px for example). As long as this width was longer than all the content you are putting within that wrapper, everything should work as you want. The browser will automatically place a horizontal scroll bar when the window gets smaller than the width of the wrapper.
This is just a small error I found in the CSS and I don't know if this will help too much. The div you added was not referred to as a div, but a class. For example, if you wanted to style a div in CSS, you would do this:
#divname {
CSS for div goes here...
}
On the other hand, if you wanted to add a little style to a class, you would go like this:
.classname {
CSS for class goes here...
}
If you were wondering what the difference for each is, the answer is simple. A class can define multiple objects while the divs are just limited to one object or element.
Please see this fiddle - http://jsfiddle.net/grimmus/vawE9/4/
<div class="refresh">
<div class="date" id="date">
As of 1/10/2013 16:44 2013 (GMT + 1)
</div>
<div class="loading"id="loading">
Loading...
</div>
</div>
In the blue box i am trying to toggle between the date and loading text. The date text can be varying width and i would like this width to stay the same when the text is hidden and the loading text is shown. The width of the date should expand to the left as far as necessary. The loading text should always be aligned left
I am having difficulty preserving the width of the box when showing the loading text. One solution i thought about was applying visibility hidden to the date text and then relatively positioning the loading text over this div with a higher z-index. It seems quite complicated and hope there is an easier solution.
Suggestions/Advice/Tips most welcome.
p.s needs to work in ie7+
Try this jsFiddle example:
jQuery
setInterval(function () {
$('#date').animate({
opacity: .01
}, 0, function () {
$('#loading').fadeIn(0).delay(2000).fadeOut(0, function () {
$('#date').animate({
opacity: 1
}, 0)
});
})
}, 4000);
CSS
body {
margin:25px;
}
.container {
background:#ccc;
height:50px;
width:100%;
}
.refresh {
background:blue;
color:#ccc;
height:20px;
float:right;
margin-right:25px;
min-width:150px;
text-align:left;
position:relative;
}
.date {
position:relative;
}
.loading {
display:none;
position:absolute;
top:0px;
}
I'm trying to get a vertical-align to work on a div whose display is table-cell.
See http://jsfiddle.net/midnitesonnet/Rwahk/ for html/css.
I can't seem get the to display vertically align to the bottom. Any help would be much appreciated.
Thanks.
You define display:table-cell & position:absolute which create a problem. Just remove your .title DIV height.
#whats_available .title {
position: absolute;
z-index: 1000;
bottom: 0;
left: 0;
text-align: center !important;
width: 100%;
color: #fff;
}
Check this http://jsfiddle.net/Rwahk/5/
http://jsfiddle.net/Rwahk/7/ works as you wanted...
The changes made were to add display: table; to the #whats_available > div and to change the .title to position: relative;
You should change the height of the inner div to something like 30px instead of 100%
http://jsfiddle.net/Rwahk/4/
You shouldn't use dimensions attributes in pure html (the only exception could be image but it's still a bad idea).
I wrote this small jQuery function which might comes in handy to you or to other readers.
jQuery.fn.center = function () {
this.css("position","absolute");
this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
return this;
}
use:
$(selector).center();
Enjoy and have a great day :)
This is driving me nuts. What happens with "width:100%" ? Apparently it just works in IExplore, so I think it's one of those things Microsoft made up.
But then... how do you tell to a element that has to take all available parent's space in a way that all browsers can understand?
Cheers?
A block level element (display:block;) will automatically take up 100% of the width of the parent element. You can resize its width using percentages or pixels. Inline elements (display:inline;) cannot have their width modified.
If you want something to take up all the parent elements space I suggest you try something like this:
.class{
display:block;
width:100%;
}
Width:100% is certainly not a MS fabrication. Understanding things like box model and inline vs block (e.g spans vs divs) elements will help you to understand some of what you will see. The browser differences have less to do with "Width:100%" than with how browsers interpret the box model for a given element, and in particular things like margins, borders, and padding.AFAIK, all browsers will honor width:100%, but how they interpret everything else may impact how much space they give over as "100%".
Remember that 100% is 100% of the PARENT, not the WINDOW.
<body>
<div id = "one" style="width:50%">
<div id = "two" style = "width:100%" />
</div>
</body>
In this case, "two" will still only be 50% of the window wide because it is in a parent that is 50% wide. (1 * .5 = .5)
So, saying that, a specific example of baffling behavior would greatly help people give you a specific answer.
If I understand you correctly, you're asking whether width: 100% is IE-only. The answer is no; it's understood by all mainstream browsers. Source: http://www.w3schools.com/css/pr_dim_width.asp
Note that width:100% will not work on inline tags... So things like or where the property 'display' as value 'inline' are not effected.
If thats news to you I recommend grabbing a book as HTML is not something to learn adhoc.
html {
width:100%;
}
body {
background-color:#f2f2f2;
margin:0;
padding:0;
}
a {
color:#ec3f3f;
text-decoration:none;
font-weight:400;
font-style:normal;
}
a:hover {
color:#262626;
text-decoration:none;
font-weight:400;
font-style:normal;
}
p,div {
margin:0!important;
}
table {
border-collapse:collapse;
}
::-moz-selection,::selection {
background:#ec3f3f;
color:#fff;
}
.ReadMsgBody,.ExternalClass {
width:100%;
background-color:#f2f2f2;
}
#media only screen and max-width640px{
img[class=img_scale] {
width:100%!important;
height:auto!important;
}
img[class=divider] {
width:440px!important;
height:2px!important;
}
table[class=spacer] {
display:none!important;
}
td[class=center] {
text-align:center!important;
}
table[class=full] {
width:400px!important;
margin-left:20px!important;
margin-right:20px!important;
}
table table,td[class=full_width] {
width:100%!important;
}
div[class=div_scale],table[class=table_scale],td[class=td_scale] {
width:440px!important;
margin:0 auto!important;
}
}
#media only screen and max-width479px{
img[class=img_scale] {
width:100%!important;
height:auto!important;
}
img[class=divider] {
width:280px!important;
height:2px!important;
}
table[class=spacer] {
display:none!important;
}
td[class=center] {
text-align:center!important;
}
table[class=full] {
width:240px!important;
margin-left:20px!important;
margin-right:20px!important;
}
table table,td[class=full_width] {
width:100%!important;
}
div[class=div_scale],table[class=table_scale],td[class=td_scale] {
width:280px!important;
margin:0 auto!important;
}
}