DIV height not resizing - css

Hi I have a container div for a page (called innercontent) and within that I have a div called tabs2. Tabs2 contains a tabbed navigation that allows content inside a div (within tab2) change. The content inside the div varies, so the height should expand itself if there is a lot of content in that div. The problem is that when changing the tabs in the content area, the div does not resize automatically, so the content cannot be seen. Here is the code:
CSS:
.innercontent {
overflow: hidden;
background-color:#FFF;
padding:24px 30px;
border-radius:5px;
}
#tabs2 {
width: 100%;
height:100%;
}
.div2 {
position: absolute;
visibility: hidden;
width: 100%;
left: 0;
}
HTML:
<div id="tabs2">
<ul>
<li id="One">One
<div class="div2">
<p>Insert content here</p>
</div>
</li>
<li id="Two">Two
<div class="div2">
<p>Insert content here</p>
</div>
</li>
<li id="Three">Three
<div class="div2">
<p>Insert content here</p>
</div>
</li>
</ul>
</div>

Are you sure they have to be absolute? As I don't think they need to be.You could look at using something such as jqueryui http://jqueryui.com/tabs/
Alternatively, amend your html and it should be easier.Essentially move the content divs outside of the but have a data-attribute that links them to a specific link. I'm assuming you use some js at the moment to manipulate showing and hiding as you currently have visibility:hidden. I've changed this to display:none in my example (as visibility still occupies space in the document. When a user clicks a link, hide all the divs by default, then show the one with the correct matching data-attribute.
I've created a fiddle at http://jsfiddle.net/9bH7s/ that shows this and the code is below.
html
<div class="innercontent">
<div id="tabs2">
<ul>
<li id="One">One
</li>
<li id="Two">Two
</li>
<li id="Three">Three
</li>
</ul>
<div class="div2" data-id="first">
<p>Insert content here</p>
</div>
<div class="div2" data-id="sec">
<p>Insert content here</p>
</div>
<div class="div2" data-id="third">
<p>Insert content here this has a lot more <br /><br />and some more content</p>
</div>
</div>
</div>
css
.innercontent {
overflow: hidden;
background-color:#efefef;
padding:24px 30px;
border-radius:5px;
}
#tabs2 {
width: 100%;
height:100%;
}
#tabs2 ul li{
float:left;
list-style:none;
margin-left:10px;
}
.div2 {
display:none;
width: 100%;
clear:both;
}
js
$('#tabs2').delegate('a','click',function(){
$('.div2').hide();
$('.div2[data-id=' + this.id +']').show();
});

1st change::dont indicate any height for .tab2..it will take an automatic height corresponding to the item that it contains
2nd change: you have made position:absolute; and expecting it to be dynamic.how that can be possible.remove it..either make it position:relative; or better choice is not to mention position property at al ...you can use margin-left:100px; to position your div

Related

CSS rules to switch content if it does not fit

Having a menu like this (emphasized by a red rectangle)...
how can I (in pure CSS) make this responsive so that, if there is not enough width available, the menu turns into a drop-down list (or anyway something smaller).
The question is not about implementing the drop-down list itself, but how to switch from one content to the other depending on available space.
I know this is rather simple when using #media max-width queries, but the problem is that I do not know the actual with of the menu items at "design time" - especially because the text gets translated and/or changed, leading to different widths depending on the actual language displayed.
Perhaps, there is some CSS trick that makes a whole "text" line / content disappear if it does not fit the parent container?
Here's a solution I've just come up with that should do the job. I added some style to make the structure more evident but it's not pixel perfect, you'll have to take care of that. Run the snippet in full screen and resize the window to see it in action.
.table-row{
display: table-row;
}
.table-cell{
display: table-cell;
vertical-align: middle;
white-space: nowrap;
}
.wrapper{
height:75px; /*the height of your menu, it's critical to define this value equal to the horizontal menu height*/
overflow:hidden; /*this will hide the horizontal menu when the screen width is too small*/
}
.top_nav{
padding-right:120px; /*allow space for right section*/
background-color: green;
color:white;
}
.top_nav_background{ /* this serves as a background for the rest of the structure, pay attention if you have other z-indexed elements */
background-color:green;
height:85px;
width:100%;
position:absolute;
top:0px;
z-index:-1;
}
.floating-box {
height: 55px;
padding:10px;
float: left;
border: 1px solid #73AD21;
background-color:green;
}
.h-menu{
height: 75px;
float: left;
min-width: 150px;
background-color:yellow;
}
.h-menu-item{
height: 55px;
padding:10px;
border: 1px solid #73AD21;
}
.v-menu{
margin-top:20px;
height: 20px;
background-color:red;
}
.right-items{
position:absolute;
right:20px;
top:20px;
color:white;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="top_nav_background"></div>
<div class="top_nav table-cell">
<div class="wrapper">
<div class="floating-box">Left section.</div>
<div class="h-menu table-row">
<div class="table-cell h-menu-item">item1</div>
<div class="table-cell h-menu-item">item2</div>
<div class="table-cell h-menu-item">item3</div>
<div class="table-cell h-menu-item">long long long item4</div>
</div>
<div class="v-menu">v-menu</div>
</div>
<div class="table-cell right-items">Right section.</div>
</div>
</body>
</html>
In one project I did I came up with a solution where you show part or all of the menu and only show it as a dropdown/side-menu when the screen gets smaller.
The sub-menu is optional and you can just use the main menu for your effect.
http://codepen.io/anon/pen/LRJoEB
<nav id="top-menu">
<ul>
<li class="link menu" tabindex="0">
Menu
</li>
<li class="link">
<a class="help" href="#">Help</a>
</li>
<li class="link">
<a class="account" href="#">My Account</a>
</li>
<li class="sub-nav">
<nav id="sub-menu">
<ul>
<li class="sub-link">
<a class="details" href="#">My Details</a>
</li>
</ul>
<div id="close-menu" tabindex="0"></div>
</nav>
</li>
</ul>
</nav>
Just change the bits and parts to fit your needs, should you get stuck just leave a comment ;)
edit
Just realised you don't want to be using any media queries. I'll see if I can come up with something in that direction, not off the top of my head.

Can't set footer to bottom

I have this code:
<div id="login-frame" class="frame-container">
<h2>Dash</h2>
<p>Wellcome</p>
<hr>
<div class="alert hidden"></div>
<div class="frame-content">
<div class="row">
<div id="appuntamenti_futuri" class="command-buttons tile col-xs-6 btn">
<b class="title">Appuntamenti futuri</b>
</div>
<div id="storico_appuntamenti" class="command-buttons tile col-xs-6 btn">
<b class="title">Storico</b>
</div>
</div>
<div class="row">
<div id="prenotazioni" class="command-buttons tile col-xs-12 btn">
<b class="title">Prenota</b>
</div>
</div>
<div class="row">
<div id="card" class="command-buttons tile col-xs-6 btn">
<b class="title">Card</b>
</div>
<div id="prepagate" class="command-buttons tile col-xs-6 btn">
<b class="title">Abbonamento prepagate</b>
</div>
</div>
<div id="frame-footer">
<span style="color: #FFFFFF">Developed by</span>
<a href="#" target="_blank">
Someone
</a>
<span id="select-language" class="label label-warning">
Language
</span>
</div>
</div>
and this is a jsfiddle
how you can see the footer isn't on the bottom but there is a blank line after it, I set the background of the body for show you the problem. What I did wrong?
To set any footer element to the bottom you need to use position: absolute or position: fixed. Please read this article about Position in CSS for a complete reference.
Using position: relative on your desired footer element's parent will ensure that your footer element, which now has position: absolute, is relative to its parent. Immediately after, using bottom: 0 on your footer element will shove it straight to the bottom of the screen. From there on, you can set its width to width: 100% and that will create the absolute basic layout of a footer.
Finally it goes without saying, ensure that your html and body elements cover the entire screen, so that your footer is positioned truly at the bottom of the screen. I wrote a very simple example (some sort of template) here:
html, body {
width: 100%;
height: 100%;
}
.my-page-wrapper {
position: relative;
}
.my-bottom-footer {
position: absolute;
bottom: 0;
}
In conclusion, applying the above comments to your code yields the following JSFiddle.
Let me know if you have any questions.
EDIT
Based on my above JSFiddle and the comments below, we have concluded that all was needed was for the footer element to sit directly beneath the login-frame element, for which I removed position: absolute and bottom: 0. The relevant part of the problem, which was the border-top property within the footer element, is all that had to be removed from the code. This can be seen in the updated JSFiddle.
i wanted to do something similar ages ago. try this as a css class on your div
bottom:36px;
position:fixed;
z-index:150;
_position:absolute;
_top:expression(eval(document.documentElement.scrollTop+
(document.documentElement.clientHeight-this.offsetHeight)));
height:30px;
width:500px;
margin-left:205px;
background:#efefef;
color:#000000;
overflow:auto;
Not sure if I'm understanding you correctly but this should be what you want:
#frame-footer {
position:fixed;
left:0px;
bottom:0px;
height:30px;
width:100%;
background:#999;
}

css container div not aligning to top of page

I have a two-column layout. I have a #mainContainer div that contains all of the following (except the #footer):
Across the top: a header div (#intro)(contains a small gradient image),
and a #hero div (contains images)
To contain the two columns: a #content div
Within the #content div on the left: a #mainContent div
Within the #content div on the right: a #sideBar div
Across the bottom (outside the #mainContainer div): a #footer div on the bottom
(including a gradient image like the header div)
Simple, right? But I'm having trouble getting the #mainContainer div to be at the top of the browser (no spaces or that 6-8px default margin/padding all browsers have at the top) and getting the #footer div to span across the entire bottom of the browser window (not inside any of the Div's ). (disregard inline styles in footer). Could someone help me out?
UPDATED: ADDED HTML
body {
font-family:Arial, Helvetica, sans-serif;
margin:0;
padding:0;
background:#bbb;
text-align:center;
}
#mainContainer {
width:980px;
margin: 0 auto;
background: #fff url(../i/content-box-header-gray.jpg) repeat-x;
text-align:left;
/*height: 700px;*/
}
#intro {
/*top:0;*/
margin: 0;
text-align:left;
}
#hero {
width:960px;
padding-left:10px;
padding-right:10px
}
#content {
width:960px;
padding-left:10px;
padding-right:10px;
}
#mainContent_left {
float:left;
width:640px;
margin:0;
padding-right: 20px;
background:#ccc;
}
#sideBar {
float:left;
width:300px;
margin:0;
/*padding-right: 20px;*/
background:#ffd;
}
#footer {
width:960px;
clear:both;
background:#cc9;
}
HTML:
<title>Descriptions </title>
<link rel="stylesheet" href="css/mainstyles.css" type="text/css" />
</head>
<body>
<div id="mainContainer">
<div id="intro"><h2>introducing</h2></div>
<div id="Hero">
<ul>
<li class="name"></li>
<li class="textJoin">is a member of </li>
<li class="name"></li>
</ul>
</div>
<div id="content">
<div id="mainContent">
<h3>First Topic title</h3>
<p>floated left image and text</p>
<p>Some content</p>
<p>Some content</p>
<h3>Second Topic title</h3>
<p>Some content</p>
<p>Image here</p>
<h3>Third Topic title</h3>
<p>(floated left image here) Some text</p>
<h3>Fourth Topic title</h3>
<p>(floated left image here) Some text</p>>
<h3>Fifth Topic title</h3>
<p>(floated left image here) Some text</p>
<p>Image here</p>
<p>(link to FAQ page)</p>
</div>
<div id="sideBar">sidebar content
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</div>
<div id="footer_warranty">footer content
<div id="wf_logos" style="float:left; padding:0 10px 0 0;"><p>contact info</p>
</div>
<div id="wf_footerCopy" style="float:left; padding:0 10px 0 0;">
<p>some text</p></div>
<p style="clear:both;" />
</div>
</div>
<p style="clear:both;" />
</div>
</body>
</html>
I am unable to reproduce your problem. However, I have created a fiddle for you, where I have also added some CSS reset rules which should take care of a problem such as this, cross any and all browsers.
You should always use a reset CSS when you start a new site. That way, it's all on your terms and you don't have to "code away" specific browser behaviour.
I have also created some placeholder code since you did not provide any.
I hope the reset fixes your problem.
http://jsfiddle.net/dekket/eERsK/
Edit:
Check this new fiddle. Out to work.
http://jsfiddle.net/dekket/6bTkZ/
Try importing Meyer's reset stylesheet:
http://meyerweb.com/eric/tools/css/reset/
try adding float:left and overflow:hidden to your #mainContainer
you need to set the html and body css margin and padding properties to 0.
use the following in your css file
html, body {
margin: 0;
padding: 0;
}

CSS: centering block elements

So I have a bunch of elements that need to have a specific width, height and padding and need to be centered within their parent element:
<div class="pages">
<a>Page 1</a>
<a>Page 2</a>
<a>Page 3</a>
</div>
How do I do this? I don't know how many elements there will be so .pages can't have a defined width so margin:auto; won't work.
In the stylesheet or style tag:
margin-left: auto; margin-right: auto
You can wrap all those in one single div and center this one, this will be the usual approach I believe.
<div id="wrapper" style="margin-left:auto; margin-right:auto">
<div id="page1"> ... </div>
<div id="page1"> ... </div>
...
</div>
If you have working code, please post it.
It sounds like what you're looking for is margin: auto on the elements you want to center, like so:
#my_div {
margin: auto;
}
CSS CODE
div {
display:table-cell;
width: 200px;
height: 200px;
vertical-align:middle;
background: red;
}
HTML CODE
<div>
Hello...This is Vertically Centered!
</div>
<div>
Hello...2!
</div>
<div>
Hello...3!
</div>
SAMPLE DISPLAY

Break out of parent div's

When i have a div with position: absolute, and in it is another div with position: absolute the inner div will position in the frame given through the outer (wrapper) div.
Now i want to create a class (css) called error_message that positions itself exactly in the center middle of the site, indifferent from where the it is called, so i need it to break out of every div wrapped around the error_message div.. how do i do this?
i had a similar problem with positioning a hoover-text centered below a floated image button list.
for me the solution was using the "fixed" value for the "position" property
position: fixed
then you can position your error message from top left of the body again.
i use another wrapper div to position all hoover texts center center.
found the solution here:
CSS nested Div with position absolute?
the code is not the code from the picture you see, the picture is just for illustration.
stylesheet in less format (see http://lesscss.org/)
<style>
.button
{
float: left;
position: relative;
a
{
&:hover, &:focus
{
.titlePos
{
.title
{
display: block;
}
}
}
.titlePos
{
position: fixed;
top:50%;
left:50%;
width: 400px;
margin-left: -200px;
.title
{
position:relative;
display: none;
top: 130px;
text-align: center;
}
}
}
</style>
html:
<div id="wrapper">
<div id="content">
<ul>
<li>
<div class="button">
<a href="#" >
<div class="buttonImage">
<img />
</div>
<div class="titlePos">
<div class="title">Button Hoover Text1</div>
</div>
</a>
</div>
</li>
<li>
<div class="button">
<a href="#" >
<div class="buttonImage">
<img />
</div>
<div class="titlePos">
<div class="title">Button Hoover Text2</div>
</div>
</a>
</div>
</li>
<li>
<div class="button">
<a href="#" >
<div class="buttonImage">
<img />
</div>
<div class="titlePos">
<div class="title">Button Hoover Text3</div>
</div>
</a>
</div>
</li>
<li>
<div class="button">
<a href="#" >
<div class="buttonImage">
<img />
</div>
<div class="titlePos">
<div class="title">Button Hoover Text4</div>
</div>
</a>
</div>
</li>
</ul>
</div>
</div>
You should try using css's position:fixed property, instead of position:absolute, for the error div. position:fixed will position an element based on the browser window, with no regard for where it falls in the DOM. If you want it to be centered in the window, regardless of window size, you could make the fixed-position div cover the entire screen (left: 0, right: 0, etc). and then text-align the error message inside of it.
I'm not sure why would you want that div to break out of parent div. Maybe try working on a fresh html structure for those?
http://haslayout.net/css-tuts/Horizontal-Centering and http://haslayout.net/css-tuts/Vertical-Centering
These should help you out!
I think the only way to have a div break out of all parent divs is to have an absolute positioning on all of them, which will obviously create its own set of problems.
Why not simply have a pre-defined, hidden div as a direct child of the body, instead of wrapping it in the markup. You can then easily position it as you want, and insert the error messages in it with the help of jQuery. An obvious advantage to this method is that you would only have to write this div once, and dynamically insert the error message into it. I would even suggest having a look at jQuery UI which allows you to easily create dialogs, both normal and modal, besides tons of other features.
UPDATE
Since JS is not allowed, an easy way to do this would indeed be displaying the div only if there was an error. So the PHP code would be ...
if (isset($error)) {
echo '<div class="show_error">' . $error . '</div>';
}
... and the CSS class for it would be ...
.show_error {
width: 400px; // error element's width
height: 200px; // error element's height
position: absolute;
top: 50%;
left: 50%;
margin-top: -100px; // minus half the height
margin-left: -200px; // minus half the width
}
Of course, you can further style the error div as you wish, but these are needed to position it dead-center.
Hope this helps !
I have found a solid CSS solution here:
https://front-back.com/how-to-make-absolute-positioned-elements-overlap-their-overflow-hidden-parent/
Let’s add another parent and move the position:relative one level up
(or, in your context, you could maybe simply use an existing upper
parent).
HTML
<div class="grand-parent">
<div class="parent">
<div class="child"></div>
</div>
</div>
CSS
.grand-parent {
position: relative;
}
.parent {
/*position: relative;*/
overflow: hidden;
}
.child {
position: absolute;
top: -10px;
left: -5px;
}
Result:

Resources