A layout has the following arrangement: (using MVC3 - The whole html is in the Layout.cshtml)
A Top header (containing a Banner and Menu bar)
Contents (Divided in Left and Right panes).
Footer
The contents of the Right pane contain tabs, and the height can vary depending on the opened tab.
I want to make the Contents div auto adjust to the height and not create a scrollbar (Not browser scroll bar).
This is somewhat achieved but it breaks the rest of the CSS.
Here is the CSS :
html {
width: 100%;
height: 100%;
}
body {
width: 100%;
/* height: 100%; */
}
#Wrapper {
border: 1px solid #6A89C1;
height: 100%;
margin: 0px auto;
min-height: 750px;
min-width: 700px;
width: 100%;
font-size: 0.75em;
}
header {
background-color: #abcdef;
height: 19%; /* did not keep it 20% due to some Background repeat issues.. */
margin: 0px;
border-bottom: 2px outset #FFFFFF;
width: 100%;
-webkit-border-top-left-radius: 5px;
-webkit-border-top-right-radius: 5px;
-moz-border-radius-topleft: 5px;
-moz-border-radius-topright: 5px;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
}
#Banner {
height: 72%;
width: 100%;
padding-top: 5px;
}
#Menu {
height: 25%;
width: 100%;
}
#Contents {
height: auto; /*65%;*/
width: 100%;
clear: both;
}
#Contents #LeftPane {
background-color: #E9F1FF;
border-right: 1px solid #B9D4FF;
height: 100%;
min-height: 300px;
width: 24.8%; /* Should not be exactly 25% as it causes RightPane div to shift downwards */
}
#Contents #RightPane {
background-color: #FFFFFF;
height: 100%;
width: 75%;
overflow: auto;
}
.Left {
float: left;
}
.Clear {
clear: both;
}
footer {
background-color: #6A89C1;
clear: both;
height: 15%;
width: 100%;
margin: 0px;
min-height: 50px;
}
#Wrapper, footer {
-webkit-border-bottom-right-radius: 5px;
-webkit-border-bottom-left-radius: 5px;
-moz-border-radius-bottomright: 5px;
-moz-border-radius-bottomleft: 5px;
border-bottom-right-radius: 5px;
border-bottom-left-radius: 5px;
}
The whole center part needs to grow automatically but the Layout (propotions) should be same
Attached also is the image after adjusting to the given CSS
(notice the menu bar Bg and left pane & footer heights )
Hope to have explained the question adequately :)
I would avoid using heights all together, the browser will adjust element heights according to their contents.
You should get the opened tabs height with javascript (or jquery) and assign this height to the content container.
http://www.w3schools.com/cssref/pr_pos_overflow.asp
overflow: auto
causes scroll bar.
You are able to do this using javascript (when tab is changed then change height depending on height of tab). I'm not sure if there is any other way.
Thanks for all the help.. !
found a possible solution of not putting all the contents in the wrapper div rather independent of each other i.e.
The Header div is separate div (parent is the body not the wrapper)
same for Contents and footer div..
Kind regards and again thank you for all the suggestions,
A.Ali
Related
my text is overflowing see the screenshot https://drive.google.com/file/d/1i_9VvP54CAJJSvtsArZiTMMfMzACDS11/view?usp=sharing
here is css:
.card_main {
border: 1px solid black;
margin-top: 30px;
border-radius: 5px;
height: 900px;
background: #ffffff;
width: 100%;
}
.blog_content__text {
width: 95%;
height: 320px;
border-bottom: 1.5px solid lightgray;
margin-left: 2.5%;
margin-top: 20px;
}
.blog_heading {
font-size: 24px;
color: black;
}
.blog_details {
font-size: 16px;
color: black;
opacity: 0.7;
margin-top: 20px;
}
my html
<div className="card_main">
<div className="blog_content__text">
<h1 className="blog_heading">{data.blog_title}</h1>
<p className="blog_details">{data.blog_body}</p>
</div>
<div/>
how to prevent overflowing my text and make the div responsive. I am not an CSS expert. I just start learning css
When using fixed height for a div, you also need to say how the scroll should work. In this case using overflow-y:auto makes sense. You may prefer overflow-y:hidden or always show scrollbars overflow-y:scroll;
If there is no serious limitation in terms of graphics, do not specify the height for a Div to make its height responsive to the content.
.blog_content__text {
width: 95%;
height: 320px;
overflow-y:auto;
border-bottom: 1.5px solid lightgray;
margin-left: 2.5%;
margin-top: 20px;
}
remove the height: 320px;
if you must, use it as min-height: 320px;
try setting a margin-bottom css attribute to the div that contains the text, the value of the margin should equal the height of that white footer that is hiding the text on the bottom.
You can also make use of the following property if you really want to set the height:
height: min-content;
I have a page where I have a div at the bottom of the page which when clicked shows another div, just above the bottom div.
I'd like to avoid the footer divs overlapping the content div higher up the page when the window is resized.
The heights of the divs involved shouldn't change.
Is a CSS-only solution possible?
I've created a jsfiddle here
CSS
html, body {
height: 100%;
width: 100%;
padding: 0;
margin: 0;
}
#container {
height: 100%;
width: 100%;
background-color: white;
border: solid #aaa 1px;
padding: 4px;
}
#content {
height: 300px;
border: solid blue 1px;
}
#footer-content {
height: 100px;
border: solid red 1px;
display:none;
}
#footer-footer {
cursor: pointer;
height: 20px;
border: solid cyan 1px;
}
#footer.expanded #footer-content {
display:block;
}
#footer {
position: absolute;
bottom: 0px;
width: 100%;
}
HTML
<div id="container">
<div id="content">content
</div>
<div id="footer">
<div id="footer-content">footer-content</div>
<div id="footer-footer">Click me to expand</div>
</div>
</div>
JS
$("#footer-footer").on("click", function (evt) {
$("#footer").toggleClass("expanded");
});
Simply add position: relative to the #container. This way the absolute positioning of the footer refers to the container.
http://jsfiddle.net/5bkznxud/5/
You'll probably notice that in the example above there's always a scrollbar on the right. This is because of the borders and padding on #container. Here's an example with outline (border with no calculated width) and without any padding:
http://jsfiddle.net/5bkznxud/6/
TIP: Always use outline instead of border for blocking a layout OR use box-sizing: border-box. This causes a box' dimensions to also calculate for the border. Otherwise a box with width of 100% and border will span slightly wider than you want.
It can be solved by using calc().
In this case you can create a jQuery function that get the height of footer-content and footer-footer -> .height(). Without jQuery, I don't think it's possible.
Here is an example:
html, body {
height: 100%;
width: 100%;
padding: 0;
margin: 0;
}
#container {
height: 100%;
width: 100%;
background-color: white;
border: solid #aaa 1px;
padding: 4px;
min-height: 420px;
}
#content {
height:calc(100% - 135px);
border: solid blue 1px;
}
#footer-content {
height: 100px;
border: solid red 1px;
display:none;
}
#footer-footer {
cursor: pointer;
height: 20px;
border: solid cyan 1px;
}
#footer.expanded #footer-content {
display:block;
}
#footer {
position: absolute;
bottom: 0px;
width: 100%;
}
http://jsfiddle.net/dokmngv0/
Browser support for the calc() feature: http://caniuse.com/#feat=calc
I'm experiencing the perennial problem of getting two columns with content of an uneven height to fill their parent container and be the same length independent of their content which will vary. I'm aware of some of the hacks for this such as using a vertically tiled background image on the parent object to simulate the columns but I also want rounded corners on the columns as well as them being different colours.
The height of the parent object is dictated by the height of the tallest 'child' column which is fine but the vertically smaller column's background shrinks to the size of its content making its background shorter than the background container. In this example I've coloured the usually invisible background object black for visibility and want the larger blue column on the left to fill this area vertically. In the case of the Blue column being taller, I want the inverse to happen and the yellow column to fill the black parent object.
I've simplified the layout to its simplest form to demonstrate the problem and the code and an image follow.
CSS:
html {
height: 100%;
width: 100%;
}
body {
margin: 0px;
padding: 0px;
background-color: rgb(0,50,130);
position: relative;
}
* {
font-family: Arial, Helvetica, sans-serif;
font-size: 1em;
text-align: left;
margin: 0px;
border: none;
padding: 0px;
}
/*auto-centering outer container box*/
.outer {
margin: 0px auto;
width: 960px;
text-align: center;
position: relative;
}
.top {
width: 960px;
height: 150px;
background-color: rgb(255,0,0);
border-radius: 6px;
}
.mid {
width: 960px;
float: left;
height: 100%;
margin-top: 35px;
background-color: rgb(0,0,0);
}
.midmain {
width: 710px;
height: 100%;
background-color: rgb(0,0,255);
float: left;
border-radius: 10px;
padding: 20px 20px 30px 20px;
margin-right: 6px;
}
.midside {
width: 180px;
height: 100%;
background-color: rgb(255,225,0);
float:right;
border-radius: 6px;
padding: 10px 10px 10px 10px;
}
/*Text rules for midside*/
.nav {
width: 180px;
}
.nav a, nav a:link{
display: block;
width: 178px;
height: 28px;
background-color: blue;
border: 1px solid rgb(0,20,100);
padding: 10px 0px 0px 0px;
margin-top: 0px;
margin-bottom: 10px;
border-radius: 6px;
text-align: center;
text-transform: uppercase;
font-weight: bold;
color: white;
text-decoration: none;
}
.nav a:hover {
color: black;
background-color: white;
border: 1px solid rgb(128,0,0);
margin-top: -2px;
margin-bottom: 12px;
}
.bot {
width: 960px;
height: 100px;
float: left;
background-color: rgba(255,255,0,0.5);
margin-top: 10px;
margin-bottom: 20px;
border-radius: 6px;
box-shadow: 2px 2px 3px 3px rgba(0,20,60,0.3);
}
HTML:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Columns</title>
<link href="styles/col.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="outer">
<div class="top">
</div>
<div class="mid">
<div class="midmain">
Main content Main content Main content Main content
Main content Main content Main content Main content Main content Main content Main content Main content Main content Main content Main content Main content Main content Main content Main content Main content
Main content Main content Main content Main content Main content Main content Main content Main content Main content Main content Main content Main content Main content Main content Main content Main content
Main content Main content Main content Main content Main content Main content Main content Main content Main content Main content Main content Main content
</div>
<div class="midside">
<div class="nav">
Home
News
Contact
About
Staff
Gallery
Video
Links
</div>
</div>
</div>
</div>
</body>
</html>
Any advice or help would be greatly appreciated!
Thanks,
Kw
Change the following definitions in your css:
.mid {
width: 960px;
float: left;
margin-top: 35px;
background-color: rgb(0,0,0);
position:relative;
}
.midmain {
position:absolute;
width: 710px;
min-height: calc(100% - 50px);
background-color: rgb(0,0,255);
border-radius: 10px;
padding: 20px 20px 30px 20px;
margin-right: 6px;
}
.midside {
width: 180px;
float:right;
background-color: rgb(255,225,0);
border-radius: 6px;
padding: 10px 10px 10px 10px;
}
With absolute positioning, the child element's height is defined relative to its parent.
If you're not keen on the min-height: calc(100% - 50px);style, you can use the following in its place. It will have the same effect:
top:0;
bottom:0;
I run into this situation as well sometimes. Basically run this against the elements that you wish to find the tallest (height), and apply that css to the other element(s).
Please note that you need (and should always) apply box-sizing:border-box; to all your elements, (ie - * { box-sizing:border-box;}
Fiddle for you
var heights = $(".mid > div").map(function ()
{
return $(this).outerHeight();
}).get(),
maxHeight = Math.max.apply(null, heights);
console.log(maxHeight);
$('.mid > div').css('height',maxHeight);
Also note that you should remove the height from your (2) div elements (since it's going to be overridden. Keep in mind as well that you "may" want to put this function in a $(window).resize() if you're doing responsive (which you should also), and you have media queries that change padding, etc.
I've got a div within a div, both are percentage based for the page but the nested div overlaps slightly to the right.
I'm actually trying to get the white box sit inside the first light blue div with a small margin on all sides so you can see a bit of the darker backround color, making it stand out more.
Editing to point out that the point of the position:fixed is to make the white box move as you scroll.
A solution was posted that involved chaning the position to relative, although this obviously stops the box from moving.
JSFiddle
div {
border-radius: 5px;
}
#header {
height: 50px;
background-color: #F38630;
margin-bottom: 10px;
}
.left {
height: 1300px;
width: 25%;
background-color: #A7DBD8;
float: left;
margin-bottom: 10px;
}
.right {
height: 1300px;
width: 75%;
background-color: #E0E4CC;
float: right;
margin-bottom: 10px;
}
#footer {
height: 50px;
background-color: #69D2E7;
clear: both;
}
#fixedleft {
height: 50px;
width: 25%;
background-color: #FFFFFF;
position: fixed;
margin: 1px 1px 1px 1px;
}
<html>
<head>
<title>Result</title>
</head>
<body>
<div id="header"></div>
<div class="left"><div id="fixedleft"></div></div>
<div class="right"></div>
<div id="footer"></div>
</body>
</html>
Your margin is increasing with the width.
Try:
#fixedleft {
height: 50px;
width: calc(25% - 2px);
background-color: #FFFFFF;
position: fixed;
margin: 1px;
}
I guess that this issue is due to default body margin as it doesn't affect the width of your fixed div(as you can see in the example, it's width is always the same, no matter what margin value you set, unlike it's container's width) :
body { margin:0; }
There is still a problem with the inner margin (1px) that pushes it out of the container, you can use calc for it, here is an example:
JSFiddle
#fixedleft {
background-color: #ffffff;
height: 50px;
margin: 2px;
position: relative;
width: 98%;
}
Please try this instear of
#fixedleft {
height: 50px;
width: 25%;
background-color: #FFFFFF;
position: fixed;
margin: 1px 1px 1px 1px;
}
if you load jQuery..
$(window).bind("resize", function(){
$("#fixedleft").width( parseInt($(".left").width()) -2)
})
$(function(){$(window).resize()})
I am having some trouble with my sticky footer. First of all, my content does not reach the entire bottom of the screen (even underneath the footer .. check on larger monitor). Also, when the window is smaller than the content, the header moves and does not expand 100% in width when you move the horizontal scrollbar. What am i doing wrong?
Here is my testing site: My Site
If you use firebug or Google Chrome's built in Inspect Element, you can see where all the elements are.
Here is some of the css:
.content
{
width: 1100px;
margin: 0 auto;
border-left:1px solid #000;
border-right: 1px solid #000;
background:#222;
min-height: 100%;
height: 100%;
padding-bottom:50px; /* Padding for footer (width) */
}
.contentInner
{
padding:0px 10px 0px 10px;
min-height: 100%;
height: 100%;
}
.footer
{
position: absolute;
bottom: 0;
width: 100%;
height: 50px;
background: #000; /* So you can see it */
}
Here is what it looks like when the content is bigger than the window:
I would also like the Content to extent all the way down the page with the content!
Edit / add your css like this to get rid of smaller screen issues..
.mainContainer {
min-width: 1100px;
}
To get that content background to continue all way down, i suggest using centered background image in .mainContainer and remove content background OR just set .content min-height to some large value like 900px OR use javascript to set content height if smaller than screen height.
if you put your .mainContainer to the width of your .content, it will work.
.mainContainer {
width: 1100px;
}
Is it what you want ?
Replace your CSS to this one.
.content
{
width: 100%;
margin: 0 auto;
border-left:1px solid #000;
border-right: 1px solid #000;
background:#222;
min-height: auto;
height: auto;
padding-bottom:50px;
position:absolute;
}
.contentInner
{
padding:0px 10px 0px 10px;
min-height: auto;
height: auto;
}
.footer
{
position: absolute;
bottom: 0;
width: 100%;
height: 50px;
background: #000;
}