float div in between 2 left/ right aligned divs - html

I have a div floated left, and a div floated right with a variable gap in between the 2 (responsive).
I need to be able to fill the gap in the middle with a colour, but only the gap in the middle (it can not flow behind the other 2 divs, as these divs have transparent backgrounds)
how can I achieve this with html structure like:
html
<div class="nav-wrap">
<ul class="nav">
</ul>
<div class="filler"></div>
<ul class="nav right">
</ul>
</div>
css
.nav-wrap{
float:left;
width:100%;
}
.nav{
float:left;
height:50px;
width:200px;
margin:0;
padding:0;
}
.nav.right{
float:right;
}
.filler{
?????
}

For filler, give it a margin that is equal to the width of the navs:
.filler{
margin: 0 200px;
background-color: blue;
}
To make this work, put both navs before the div in the HTML:
<div class="nav-wrap">
<ul class="nav">
</ul>
<ul class="nav right">
</ul>
<div class="filler">X</div>
</div>
Fiddle: http://jsfiddle.net/yyZz6/1/

You can use table layout of this purpose.
.nav-wrap{
width:100%;
display:table;
table-layout:fixed;
}
.nav{
display:table-cell;
height:50px;
width:200px;
margin:0;
padding:0;
}
.filler{
display:table-cell;
background: ?;
height:50px;
}
Example

You can use the following html:
<div class="nav-wrap">
<ul class="nav left">
</ul>
<div class="filler"></div>
<ul class="nav right">
</ul>
</div>
With the following styles:
.nav-wrap{
padding:0 200px;
overflow:auto;
}
.nav{
height:50px;
width:200px;
margin:0;
padding:0;
}
.nav.right{
float:right;
margin-right:-200px;
}
.nav.left{
float:left;
margin-left:-200px;
}
.filler{
width:100%; float:left;
}
Example

Consider using flex-grow of CSS flexbox
.filler{
background: SaddleBrown; flex-grow: 1;
}
Fiddle

If you are trying to achieve responsive design you should not use fixed width. Instead i suggest you try this:
<div class="nav-wrap">
<ul class="nav">
</ul>
<div class="filler">
</div>
<ul class="nav">
</ul>
</div>
<style type="text/css">
.nav-wrap{
float:left;
width:100%;
}
.nav, .filler{
border: 1px solid black;
}
.nav{
float:left;
height:50px;
width:13%;
margin:0;
padding:0;
}
.filler{
float: left;
width: 64%;
}
<style>

Related

I want to find a css that div automatically occupy the rest of the horizontal dimension

If you have two child divs in the parent div, and one of the child divs occupies the width of a particular value, i want to find a css that the other child div automatically occupy the rest of the horizontal dimension.
* {
margin:0;
padding:0;
}
a {
text-decoration:none;
}
li {
list-style:none;
}
img {
height:100%;
border:0;
}
body,html {
width:100%;
height:100%;
}
body {
background-color:#161716;
padding:2%;
box-sizing:border-box;
}
#container {
width:100%;
height:100%;
background-color:aquamarine;
display:flex;
flex-flow:row wrap;
align-items:center;
justify-content:space-between;
}
#scroll {
width:2%;
height:20%;
margin-right:1%;
background-color:burlywood;
}
#container_in {
width: calc(100% - 26%);
height:100%;
margin-left:1%;
margin-right:1%;
background-color:deepskyblue;
}
#side {
width:20%;
height:100%;
margin-left:1%;
background-color:bisque;
}
#header {
width:100%;
height:15%;
}
header {
display:table;
width:100%;
height:100%;
background-color:darkviolet;
}
#logo {
width:fit-content;
height:100%;
background-color:azure;
}
#logo a {
width:fit-content;
height:100%;
}
#navi {
display:table-cell;
width:auto;
height:100%;
background-color:navajowhite;
}
<!doctype html>
<html>
<head>
<title>Untitled</title>
<link href="css/index.css" type="text/css" rel="stylesheet">
</head>
<body>
<div id="container">
<div id="scroll">
</div> <!-- scroll end -->
<div id="container_in">
<div id="header">
<header>
<div id="logo">
<a href="#">
<img src="img/logo.jpg">
</a>
</div> <!-- logo end -->
<div id="navi">
<nav>
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</nav>
</div> <!-- navi end -->
</header>
</div> <!-- header end -->
</div> <!-- container_in end -->
<div id="side">
</div> <!-- side end -->
</div> <!-- container end -->
</body>
</html>
Once the entire structure is like the code above.
My question is the div#header section.
The div#header header is a child element of the div#header.
The div#header header contains two child div.
The parent area(div#header header) contains #logo and #navi.
The width of the #logo area is given as width: fit-content; to match the image size of the #logo child area.
Then the other child #navi can not use the same method as width: calc (100% - 10px) without knowing the width value of the #logo child.
I would like to use css only so that the rest of the #logo area in the div # header header area is automatically occupied by #navi.
Make it simple with flex property
add flex:1 to the div you want to give all the remaining space
#container_in{
flex:1;
}
Minimal coded working snippet here:
#container{
display: flex;
align-items: center;
text-align: center;
}
#container div{
padding: 5px 10px;
}
#container_in{
flex:1;
background: blue;
}
#scroll{
background: red;
}
#side{
background: green;
}
<div id="container">
<div id="scroll">scroll</div>
<div id="container_in">It will occupy remaining space</div>
<div id="side"> side</div>
</div>
Working Demo here

How to move title of header for it to line up with main content of the page?

I have a row with columns on my main content section and i gave it a width of 1000px and centered it with margin:0 auto. Currently my title of the header is all the way to the left of course and i want it to line up right where the row will begin. How can i achieve this?
http://jsfiddle.net/zck9c8ud/
<header>
<nav>
<ul>
<h1>title of page</h1>
<li>Home</li>
<li>Portfolio</li>
<li>About</li>
</ul>
</nav>
</header>
<div class="row">
<div class="col">col1</div>
<div class="col">col1</div>
<div class="col">col1</div>
</div>
*{
margin:0px;
padding:0px;
}
header{
background:orange;
color:white;
padding:10px;
}
header h1{
display:inline;
position:relative;
left:200px;
}
nav ul{
display:inline;
}
nav ul li{
display:inline-block;
color:white;
position:relative;
left:70px;
}
.row{
width:1000px;
margin:0 auto;
}
.col{
background:#999;
width:33%;
float:left;
margin:10px;
padding:10px;
color:white;
height:400px;
}
I'm not sure if I understood your question properly, but here's how I tried to solve it:
TLDR: Just check out this fiddle: http://jsfiddle.net/arnellebalane/LLzmseoq/
First, I just wrapped the header and the row in a separate container called .wrapper, which I gave a width of 1000px.
<div class="wrapper">
<h1>title of page</h1>
<div class="row">
<div class="col">col1</div>
<div class="col">col1</div>
<div class="col">col1</div>
</div>
</div>
Then I changed the width of .row to 800px and the the width of h1 to 200px (adjust these values if you want`.
Then I floated them to separate directions so that they will sit beside each other.

Problems with Clearfix

I've been having trouble applying clearfix to a number of divs, I've followed several tutorials, found here and here, but still my div named Bar will not expand to hold both the logo and nav divs.
Here is my markup, any and all advice would be greatly appreciated.
I have made the divs some strange colours to help see where they are ending and help with trying to see what is going on exactly.
<div id="bar" class="group">
<div id="nav">
<ul>
<li>Home</li>
<li>What We Do</li>
<li>Our Work</li>
<li>Our People</li>
<li>Contact Us</li>
</ul>
</div>
<div id="logo">
<img src="images/logo.png" title="" alt="" />
</div><!--Close Logo-->
CSS:
body{
margin:0;
}
.group:after {
content: "";
display: table;
clear: both;
}
#bar{
background-color: #e2871a;
width:100%;
}
/*NAVIGATION */
#nav{
color:#fff;
float:right;
margin-right:50px;
background-color:chartreuse;
}
#nav>ul{
list-style:none;
padding:0;
margin:0;
}
#nav>ul li{
display:inline;
}
#nav>ul a>li {
color:#fff;
padding-bottom:100px;
background-color:blue;
margin-right:15px;
}
#nav>ul a>li:hover{
border-bottom:3px solid white;
}
#logo{
float:left;
width:15%;
margin-left:5%;
background-color:red;
}
Problem is:
#nav>ul li{
display: inline;
}
Top/bottom padding or margin doesn't affect the height of inline elements relative to their parent. Make it block or inline-block

Three flexible (percentage) Columns in flexible Area

I need to arrange three columns of divboxes with 33% width of the outer box, besides a fixed-width menu.
http://jsfiddle.net/uvw5c/1/
So i want the red, yellow, green area beides the orange menu, in ANY case of width of #menu.
<div id="container">
<div id="menu">
menu
</div>
<div id="dialogbox">
<div id="outer">
<div class="inner" style="background-color:red;">
col1
</div>
<div class="inner">
col2
</div>
<div class="inner" style="background-color:green;">
col3
</div>
</div>
</div>
</div>
​
#container{
width:500px;
background-color:grey;
height:300px;
}
#menu{
width:300px;
float:left;
height:100%;
background-color:orange;
}
#dialogbox{
float:left;
height:100%;
width:100%;
}
#outer{
background-color:blue;
height:300px;
margin: 0 auto;
padding:0;
width:100%;
}
.inner{
padding:0;
margin:0;
width:33%;
background-color:yellow;
height:100%;
float:left;
}
​
​
Thanks in Advance for any hints!
For this specific case you can do away with a lot of the markup and use display: table; and table-cell;. Set the width of the menu, and the others will automatically fill the rest equally.
HTML:
<div id="container">
<div id="menu">
menu
</div>
<div class="inner" style="background-color:red;">
test
</div>
<div class="inner">
test
</div>
<div class="inner" style="background-color:green;">
test
</div>
</div>
​
CSS:
#container{
width:500px;
display: table;
height: 300px;
}
#menu{
width: 100px;
background: #00f;
display: table-cell;
}
.inner{
padding:0;
margin:0;
background-color:yellow;
height:100%;
display: table-cell;
}
Fiddle: http://jsfiddle.net/Kyle_Sevenoaks/uvw5c/5/
Make a div containing both the menu and the .inner elements.
Also check that width of inner must be 33.3% and 33.4% for one element (maybe the one in the middle)
I found a solution with the help of a friend:
http://jsfiddle.net/t39yV/2/
its very smart to use margin-left on the #dialogbox ;)
#container{
width:100%;
background-color:grey;
height:300px;
}
#menu{
width:100px;
float:left;
height:100%;
background-color:orange;
}
#dialogbox{
margin-left:100px;
height:100%;
}
#outer{
background-color:blue;
height:300px;
margin: 0 auto;
padding:0;
width:100%;
}
.inner{
padding:0;
margin:0;
width:33.3%;
background-color:yellow;
height:100%;
float:left;
}

#CSS Wrapper does not recognise content

Since last week I am again trying to make a website after an absence of about 2 years. It went pretty well until I noticed that when I minimize the browser, the content does not stay in the wrapper.
I have been looking for solutions on this website and on google but I cant seem to find the right one. Most solutions mention problems with #float and overflow but I do not use float (hope that this is not the problem) and I have been playing with the overflow but I cant get it to work.
Below you can find the CSS and HTML code I used.
The HTML:
<div id="wrapper">
<div id="content">
<div id="header">
<div id="logo">
<img src="style/images/logo.gif" width="184" height="73" alt="logo" />
</div>
<div id="menu">
<ul id="navlist">
<li id="active">1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
</div>
</div>
<div id="main">
Title
subtitle
</div>
<div id="footer">
<div id="left_banner">
</div>
<div id="right_banner">
</div>
</div>
</div>
</div>
and the CSS
html, body, ul, li {
margin:0px;
padding:0px;
height:100%;
}
#wrapper {
text-align: center;
background:url(images/bg.gif);
background-repeat:repeat;
height:100%;
width: 100%;
overflow:auto;
}
#content {
background-color: #fff;
margin: 0px auto;
width: 780px;
height: 100%;
border-left:#fd5d78 4px solid;
border-right:#fd5d78 4px solid;
}
#header {
position:relative;
height:120px;
}
#logo {
position:absolute;
right:43px;
top:37px;
}
#menu {
position:absolute;
bottom:0px;
left:58px;
}
#main {
position:relative;
left:25px;
top:35px;
width:730px;
height:320px;
}
#footer {
position:relative;
width:730px;
left:25px;
top:70px;
background-color:#0F0;
clear:both;
}
#left_banner {
position:absolute;
left:0px;
width:349px;
height:134px;
border:#fd5d78 2px solid;
background-color:#FFF;
}
#right_banner {
position:absolute;
right:0px;
width:349px;
height:134px;
border:#fd5d78 2px solid;
background-color:#FFF;
}
Thanks a mil for your help.
Try adding display:block; to the #wrapper
jsfiddle
I know you said you don't use floats, but here is a solution using them. One of the biggest problems you had was you were setting the two footer banners to absolute positions, which throws off the 100% height on the parent div. With floats and overflow:hidden you are able to bring those divs back into the 100% calculation.
I had to make many changes to your css, so take what I have in the jsfiddle as your starting point.