My body div collapses under the left bar navigation when i begin to minimize the window.
Can somebody please advise on what i have done wrong or what more i need to do.
Much appreciated, thank you.
css snippet:
#navigation {
float: left;
min-width: 20%;
margin: 0;
margin-top: 5px;
font-weight: normal;
}
#centerDoc {
float: left;
width: 80%;
padding: 0 0 20px 0; /*top right bottom left*/
margin-top: 0px;
}
#header{
position: relative;
width:100%;
height:96px;
margin-left: 5px;
}
#footer {
font-family: Trebuchet MS;
font-size: x-small;
padding:2px;
margin:0px;
background-color:#CBE3F6;
color:#fff;
border-bottom: 1px solid #9EC4E2;
border-top: 1px solid #9EC4E2;
text-align:center;
width: 100%;
}
#wrapper{
position: relative;
margin-left: 5px;
}
#container {
width: 100%;
height:100%;
}
Template of a page:
<?php require_once 'includes/header.php';?>
<div id="wrapper">
<?php require_once 'includes/nav.php'; ?>
<div id="centerDoc">
</div> <!--centerDoc !-->
</div> <!-- wrapper !-->
</div> <!--container !-->
</body>
Remove float attribute from #centerDoc, and add margin-left: 20%. to it
Then change min-width: 20% in #navigation to width: 20% or max-width: 20%. Without this the text inside centerDoc flows under the #navigation.
You might want to keep your measurement synchronized. You have width: 80% in #centerDoc and min-width in #navigation. It might be easier to picture the layout if you'd used plain width in both occasions and assigned the min/max-width attributes to the body of the page (so the widths of the #navigation and #centerDoc are relative to the common parent of them).
Edit: CSS:
#navigation {
float: left;
width:20%;
}
#centerDoc {
width: 80%;
margin-left:20%;
}
#header{
width:100%;
height:96px;
}
#container {
max-width: 1200px;
min-width: 600px;
}
Removed the #wrapper. See the max-/min-width´ in the#container. The scrollbars appear into the browser when the page is less then 600 pixels wide. The page also doesn't become wider then 1200 px. This allows you to define thewidths of the#navigationand#centerDoc` as percentages.
With the following HTML everything should work properly. (Althought I don't know what's inside nav.php. Hopefully nothing that clears the floating of the #navigation)
<div id="container">
<?php //require_once 'includes/header.php';?>
<div id="navigation">
<?php //require_once 'includes/nav.php'; ?>
<p>Sample text. Sample text. Sample text. Sample text. Sample text.</p>
</div> <!--navigation !-->
<div id="centerDoc">
<p>Sample text. Sample text. Sample text. Sample text. Sample text. Sample text.</p>
</div> <!--centerDoc !-->
</div> <!--container !-->
I would change min-width in #navigation to max-width.
That way we make sure that the left navigation bar has not more than the 20% of the width of the page.
Edit:
#navigation {
float: left;
width: 20%;
margin: 0;
margin-top: 5px;
font-weight: normal;
}
#centerDoc {
float: right;
width: 80%;
padding: 0 0 20px 0; /*top right bottom left*/
margin-top: 0px;
}
Related
I have two columns 41% and 59% of the total screen width each. The height of the columns is 1102px.
In the first column I have 4 divs. The first one is for the navigation and it can be maximum 60px. The second one is for a logo I am using. The third one is for text and the fourth one is the trickiest one. I am using an image which does not have the same size and ratio. I want the image to get the 100% of the width.
My challenge is to get the height of the first image and the text divs to be dynamic depending on the heigh of the bottom image in the first column. For example, the margins are really big when the screen size is big :
body{
color: #fff;
font-family: Arial;
}
.wrapper{
background-color: #484848;
}
#col1{
float:left;
width:41%;
height: 1102px;
background-color: #E90649;
position: relative;
}
img#productImg{
width:100%;
height:auto;
}
img#product{
max-width:100%;
}
#col2{
float: left;
width:59%;
height: 1102px;
background-color: #124;
}
div #centerText{
width: 70%;
margin: 0 auto;
height:455px;
}
#productLogo{
margin-top: 2%;
margin-left: auto;
margin-right: auto;
display: block;
max-width: 70%;
}
.list {
padding-right: 14px;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
li {
display: inline;
padding-left: 4px;
color: #000;
font-size: 18px;
font-weight: lighter;
}
div.nav{
padding-top: 3%;
height:24px;
padding-left: 5%;
}
#productImg img{
width:100%;
position: absolute;
bottom: 0;
left: 0;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="wrapper">
<div id="col1">
<div class="nav">
<ul>
<li>HOME</li>
</ul>
</div>
<img id="productLogo" src="https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-logo.png?v=9c558ec15d8a"/>
<div id="centerText">
<h1>#############</h1>
<p2>#############</p2>
<h3>#############</h3>
</div>
<div id="productImg"><img src="https://www.w3schools.com/css/img_fjords.jpg" /></div>
</div>
</div>
<div id="col2">aaaaaaaaa</div>
</body>
</html>
I used the #media screen-size feature but still I am not happy with the results as I have to put many lines in the CSS. Ideally, the part with the first logo (stackoverflow) and the text will be vertically aligned to center and the padding-top, padding-bottom will have the same value (percentage). The height of this div will depend on the height of the bottom image (JS parsing possible here?) and thus the text can be dynamic using the vw or vh in the CSS.
Is there an easier way to align the divs in the column and keep everything without breaking (that was the initial problem)?
I'm working on my portfolio site and having trouble getting my divs to size together.
Here it is: I have one body div, inside there are two child divs.
The body div should have max-height 100%, max-width: 100% so that it doesn't exceed the browser window.
The left div contains an image which I want to scale to the parent body div (max-height 100%, max-width 70%).
The right div contains text about the image, it needs to scale to the height of the left div (there is also footer that sits at the bottom of this div).
This shouldn't be so hard, its almost working but right now my image container (left div) is not being contained to the body div.
html,
body {
height: 100%;
}
.Info {
float: left;
width: 25%;
padding-left: 15px;
padding-top: 10px;
/*margin-left: 78%;*/
border-left: 1px black solid;
/*position: absolute;*/
}
.InfoText p {
margin-top: -10px;
}
div img {
max-width: 100%;
max-height: 100%;
margin: 0 auto;
box-shadow: 5px 5px 15px #888888;
}
.ImageContainer {
float: left;
height: 100%;
max-width: 70%;
padding-right: 15px;
position: relative
}
section.ImageContainer img {
float: left;
object-fit: cover;
}
#SideQuote {
margin-top: 30px;
}
.StuffInBody {
position: relative;
padding-top: 15px;
float: left;
display: flex;
}
footer p {
position: absolute;
bottom: 0%;
margin: 0;
}
<div class="StuffInBody">
<div class="ImageContainer">
<img class="contained" src="images/TheGMODebate copy.jpg" alt="" />
</div>
<div class="Info">
<div class="InfoText">
<p>ILLUSTRATION</p>
<p>Title: <em>The GMO Debate</em>
</p>
<p>Media: Gouache</p>
<div id="SideQuote">
<p class="ClickToEnlarge">Full screen image click here.
</p>
</div>
<footer>
<p>© Brooke Weiland 2015</p>
</footer>
</div>
</div>
</div>
It's very hard to make a reliable interface using floats.
It changes default behaviour and put your element outside of the flux.
You should be able to do what you want using only flex.
The property box-sizing: border-box also makes miracles (margin and padding easier to manage).
Also, the object-fit property is not enough supported by browsers to be used now IMHO.
http://caniuse.com/#feat=object-fit
I found site template.
body {
font: 10pt Arial, Helvetica, sans-serif;
background: #54463d;
margin: 0;
}
h2 {
font-size: 1.1em;
color: #752641;
margin-bottom: 0;
}
#container {
width: 500px;
margin: 0 auto;
background: #f0f0f0;
}
#header {
background: #8fa09b;
font-size: 24pt;
font-weight: bold;
color: #edeed5;
padding: 5px;
}
#content {
float: left;
width: 329px;
padding: 10px;
border-right: 1px dashed #183533;
background: #fff;
}
#content p {
margin-top: 0.3em
}
#sidebar {
float: left;
width: 120px;
padding: 10px;
}
#footer {
background: #8fa09b;
color: #fff;
padding: 5px;
}
.clear {
clear: both;
}
It works ok if content height more than menu height:
http://jsfiddle.net/R6MYH/1/
But, in another case, the site is not displayed correctly:
http://jsfiddle.net/a5SFM/
Make slight change in your design as mentioned below :
Put divs with id content and sidebar inside one div with float:left
Remove float:left from css #content and #sidebar
Add display:table-cell in css #content and #sidebar
Live Demo This will work in all cases.
Your inner html will look like :
<div style="float:left">
<div id="content">
<h2>Title</h2>
<p>There is only one sentence.</p>
</div>
<div id="sidebar">
<p>Lorem ipsum</p>
<p>Dolor sit amet</p>
<p>There is at text. Not really!</p>
<p>Link 4</p>
</div>
</div>
Advantages:
The main advantage of using display:table-cell is you don't have to set min-height. It will work even your side bar contains height of 1px.
More user friendly
Compatible in all the browsers (ie > 7)
You don't have to do any extra work like javascript/jquery.
create a div inside #container and put #content and #sidebar inside it.
and then replace float: left in css of both #content and #sidebar with display: table-cell
like this: http://jsfiddle.net/aneelkkhatri/a5SFM/6/
no use of min-height
A more general solution, would be to implement this using JavaScript (jquery)
Add this script to your document
$(document).ready(function () {
$("#content").height($(window).height() - $("#header").height() - $("#footer").height() - 40);
});
This will make the content height as same as the browser's window height in all cases
Don't forget to add this to inside your tag
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
Check it out here: http://jsfiddle.net/basharmadi/Mqy7y/
Try adding this to #content:
min-height:300px;
This will "extend" down the content div no matter what.
Try to put a min-height to your content div:
min-height: 200px;
Here:
#content {
float: left;
width: 329px;
padding: 10px;
border-right: 1px dashed #183533;
background: #fff;
min-height: 200px;
}
jsfiddle
I have a logo and text on the page and my items are floated left but this causes the bottom of the logo to cut off. No minus margins or paddings are used. Looking with XRAY and webdeveloper style finder I see that the img is getting cut short with no other elements around it, (it is just floated left). If I remove the float from the .logo the image appears whole, but larger and out of position
Here is the jsfiddle http://jsfiddle.net/9LGRx/ It seems to be a FF bug, works ok in Chrome and Safari.
html > body > header > div.wrapper > a.logo > img
HTML code
<header>
<div class="wrapper">
<a href="/" class="logo">
<img src="images/logo.png" alt="Showhouse logo">
</a>
<h1>Welcome to ShowHouse</h1>
<p class="text">
Show off your property management skills with ShowHouse - the only online property
management software that will effortlessly handle and help to improve every aspect of
your <strong>residential</strong> and <strong>commercial lettings</strong>, <strong>sales</strong> and <strong>block management</strong>.
</p>
</div>
</header>
SCSS Code
h1{
color: #fff;
float: left;
clear: both;
}
img{
max-width: 100%;
float: left;
}
header{
background-image: url('../images/header-bg.jpg');
float: left;
width: 100%;
/*height: 417px;*/
.logo{
float: left;
width: 60%;
margin: 20px 0 20px 0;
}
.logo img{
max-width: 100%;
}
.text{
float: left;
clear: both;
color: $color-white;
font-size: 1.2em;
margin-top: -10px;
}
}
Try adding this to your css:
.logo img{
max-width: 100%;
display: block;
height: 150px;
}
(put the real height of your image or the height you want to display)
I think this problem is best explained by images. This is how my accordion looks:
When you click on the small plus/minus icons the slides under each chapter will expand/collapse. However when the content in the accordion grows too tall, it grows out from its container. So if I click on more plus icons the accordion will look like this (not pretty):
As you can see, the container is not growing taller together with the accordion and it does not look good.
This problem only occurs in IE7 and IE8. It works in Firefox and Chrome.
The HTML looks like this (simplified):
<div id="content">
<div class="box2 rounded-corners">
<div class="chapters">
<h3>Obsah</h3>
<div id="accordion">
<ul>
... // accordion content - too long
... // accordion content - too long
</ul>
<div class="clear"> </div>
</div>
<div class="clear"> </div>
</div>
<div class="training-body">
... // content to the right of the accordion
</div>
</div>
</div>
The CSS, again siplified:
html, body {
height: 100%;
width: 100%;
overflow: auto;
}
#content {
background: white url('/images/background_middle.png') left top repeat-x;
padding: 13px;
min-height: 40em;
height: auto !important;
height: 40em;
}
/* this is the div with rounded corners */
#content .box2 {
background: white;
padding: 0 15px 15px;
border: 1px solid #C5E3F8;
position: relative;
}
/* left sidebar 98
#content div.chapters {
float: left;
width: 224px;
}
/* orange heading "OBSAH" */
#content div.chapters h3 {
color: #ff6e19;
text-transform: uppercase;
font-size: .9em;
text-align: center;
padding-bottom: .5em;
margin-top: 1em;
margin-bottom: 0;
}
#content div.chapters h3 a {
color: #ff6e19;
}
/* accordion */
#accordion {
width: 226px;
border-top: 1px solid #c5e3f8;
}
#accordion ul {
padding-left: 0;
margin-top: 0;
margin-bottom: 0;
margin-left: 0;
}
/* area to the right of the accordion */
#content div.training-body {
float: left;
padding-left: 0px;
width: 748px;
line-height: 1.3em;
}
Hmmm, after a lot of research, it turned out that the curvycorners plugin is causing the problem, here's what you have to do:
Download the latest version of the plugin (also try to upgrade your jQuery, but this is only a tip)
change your rounded-corners CSS to the following:
.rounded-corners {
-moz-border-radius:2ex;
-webkit-border-radius:2ex;
}
in your JS and after toggleing the ULs, you need to redraw the corners, refer, using the following:
$this.parent().parent().children('ul').toggle();
curvyCorners.redraw();
EDIT sorry, my first answer was incorrect
The problem is with the min-height you set. IE 7 and 8 support min-height, but incorrectly handle !important, not giving it priority over the the next declaration. To solve just remove the two height lines. If you want to support IE6 add the height rule like the following
...
min-height: 40em;
}
* html #content {
height: 40em;
}