CSS two column full width - css

So I have a website which has a header, a footer and two main content columns inbetween.
The left column is for navigation. The right one is a map. I want both to fill the width of the browser. I seem to be facing problems with different resolutions and different browsers. The map always displaces to below the footer or it leaves a white space on the right.
My link: http://www.trashvigil.com/nsdf/www/index1.php
This is my code:
#map{
float:left;
height:572px;
width:79.88%;
border-right: 2px solid #000;
border-bottom: 3px solid #000;
}
#leftnav
{
float:left;
width:250px;
height: 572px;
border-right: 3px solid #000;
border-bottom: 3px solid #000;
}
#map is the map container. #Leftnav is navigation.
Thank you,
Kaushik

You need something like this:
#map {
margin-left:250px;
height:572px;
}
#leftnav {
float:left;
width:250px;
height: 572px;
}
The idea is to float the leftnav and then set a left margin for the map that is equal to the width of the leftnav.
You can see it live here: http://dabblet.com/gist/2767788

#nav {
position:absolute;
left:0px; width:250px;
height:375px; top:50px; /* height of your top bar*/
}
#map{
margin-left:250px;
height:572px;
}

Something like this should be what you need.
<style>
#main
{
width: 900px;
overflow: hidden;
}
#leftnav
{
float: left;
}
#map
{
float: right;
}
</style>
<div id="header">
</div>
<div id="main">
<div id="leftnav">
</div>
<div id="map">
</div>
</div>
<div id="footer">
</div>

Write like this:
#map{
overflow:hidden;
height:572px;
border-right: 2px solid #000;
border-bottom: 3px solid #000;
}
#leftnav{
float:left;
width:250px;
height: 572px;
border-right: 3px solid #000;
border-bottom: 3px solid #000;
}

Related

CSS Border height different on each side

I am wondering if a border like this would be possible in pure css? There will be no content within this box, only an image within the future.
I would like to achieve this in pure CSS, with no jQuery. I have looked around and it seems it isn't really possible, however with CSS constantly evolving I was wondering if it was possible apart from using nested divs etc.
Cheers!
You can fake it. Like this jsFiddle example.
HTML
<div id="wrapper">
<div id="top"></div>
<div id="bottom"></div>
<img src="http://www.placekitten.com/200/100" />
</div>
CSS
#top, #bottom {
width: 200px;
height:50px;
position:absolute;
left:-1px;
}
#bottom {
border-left: 1px solid #f00;
border-right: 1px solid #f00;
border-bottom: 1px solid #f00;
bottom:0;
}
#top {
border-left: 1px solid #f00;
top:0;
}
#wrapper {
position:relative;
width: 200px;
height:100px;
background: #faa;
}
You can do it with only one div if you use pseudo elements. jsFiddle here
HTML:
<div id="wrapper">
<img src="http://www.placekitten.com/200/100" />
</div>
CSS:
#wrapper {
position:relative;
width: 200px;
height:100px;
background: #faa;
border-left: 1px solid #f00;
border-bottom: 1px solid #f00;
}
#wrapper::before {
content: " ";
position: absolute;
width: 100%;
height: 50%;
bottom: -1px;
right: -1px;
border-right: 1px solid #f00;
border-bottom: 1px solid #f00;
}
Just for the 'think' of it, you could also just stick a small graphic at the bottom right of a div (as a background image) and use a border on the left and bottom. Still just manipulating it via css with one small graphic but at least the height and width would be dynamic and not stuck as if using a full image.
Would also avoid A LOT of extra mark-up and css. 1 div, 1 css declaration and 1 small image.

Width not expanding?

I'm working on a map project and for some reason my tooltip's text width will continue to expand as wide as I want until I add a space to my text. If I add a space, it breaks to the next line; what is going on and how do I fix this? I'd like the text on one line without specifying a width so it can automatically set the width, how can I fix this?
In the example below, look at text "Baseball Fields" in the paragraph tag. If it reads "BaseballFields" it will stay on one line. But as soon as I add the space, it will line break.
<div style="width: 750px; height: 1221px; border: 0; padding: 0; margin-top: 10px; display: block; position:relative; background: url('http://www.thefirstacademy.org/filerequest/9701.jpg') no-repeat left top;">
<style type="text/css">
.triangle {
position:absolute;
bottom:-5px;
left:40%;
height:0;
width:0;
border-left:5px solid transparent;
border-right:5px solid transparent;
border-top:5px solid white;
}
.tooltip {
color:#ef4c4c;
background:#ffffff;
padding:17 10;
display:block;
position:absolute;
border-radius:5px;
font:.8em 'MuseoSans-500','Museo Sans';
top:-40px;
box-shadow:0px 3px 3px #000;
border:1px solid #000;
}
</style>
<div class="marker" style="position:absolute;cursor:pointer;left:450px;top:75px;" id="baseball">
<img src="http://www.thefirstacademy.org/filerequest/9702.png" alt="Location Marker" />
<div class="tooltip" >
<div class="triangle"></div>
<p style="padding:0;margin:0;line-height:0;display:block;">Baseball Fields</p>
</div>
</div>
</div>
Just a heads up: in addition to white-space: nowrap; it can be helpful to include display: inline-block; for browser compatibility purposes

CSS horizontal centered line

How can I achieve this view with CSS:
------------------TITLE
or
TITLE------------------
I have
<div id="titleBlock">
<div id="title">Some text</div>
<div id="titleLine"></div>
</div>
And my styles are:
#titleLine {
border-top: 1px solid black;
width: 84%;
clear: both;
height: 20px;
}
#title {
height: 10px;
float: right;
}
My approach is here: jsFiddle
However the line width is defined with percents and I need it adjust automatically with CSS.
This may be what you are after: http://jsfiddle.net/XpSWX/1/
Hope this helps
<div id="titleBlock">
<div id="title">Some text</div>
<div id="titleLine"></div>
</div>​
#titleLine {
border-top: 1px solid black;
width: 84%;
float:left;
height: 20px;
margin-top:8px;
}
#title {
height: 10px;
float: right;
}​
http://jsfiddle.net/sY2SV/1
<div id="titleBlock">
<div id="title">Some text</div>
<div id="titleLine"></div>
</div>​
#titleLine {
border-top: 1px solid black;
width: 84%;
float:right;
height: 20px;
margin-top:8px;
}
#title {
height: 10px;
float: left;
}​
http://jsfiddle.net/sY2SV/2
Here is a solution:
#titleBlock {
width:100%;
}
#titleLine {
background:black;
position:absolute;
z-index:1;
left:0px;
top:14px;
width:100%;
height: 1px;
}
#title {
display:inline-block;
padding:4px;
background:white;
position:relative;
z-index:2;
/* Only variable to change... Just say left and it woulb be title------- */
float:right;
}​​​​
DEMO
Hey now you can used this
HTML
<div class="hello"><span>Hello i m sony</span></div>
Css
.hello{
background:green;
text-align:left;
position:relative;
}
.hello span{
padding-right:10px;
background:green;
display:inline-block;
position:relative;
z-index:1
}
.hello:after{
content:'';
border-top:solid 5px red;
position:absolute;
right:0;
left:0;
top:7px
}
Live demo
http://tinkerbin.com/1guJzKcI
Check my answer in Horizontal Line in Background using Css3
You can do it with a 1% gradient like this
.datedAside {
background: linear-gradient(0deg, transparent 49%, #000 50%, transparent 51%);
}
.datedAside span{
background: #FFF;
padding: 0 0.5rem;
}
You'll nedd the extra span to be the same background color as the background of the component to make it look like it has "deleted" the line going behind the text.
For text, it's best to use text-align

CSS: Placing divs left/center/right inside header

I've been trying to create a site with the following structure:
But I can't seem to get the header correct (e1 left, e2 centered, e3 right). I want the three elements e1, e2 and e3 to be left, middle and right positioned. This is what I'm trying:
<div id="wrapper">
<div id="header">
<div id="header-e1">
1
</div>
<div id="header-e2">
2
</div>
<div id="header-e3">
3
</div>
</div>
<div id="nav">
links
</div>
<div id="content">
content
</div>
<div id="footer">
footer
</div>
</div>
With this css:
#wrapper
{
width: 95%;
margin: 20px auto;
border: 1px solid black;
}
#header
{
margin: 5px;
}
#header-e1
{
float: left;
border: 1px solid black;
}
#header-e2
{
float: left;
border: 1px solid black;
}
#header-e3
{
border: 1px solid black;
}
#nav
{
margin: 5px;
}
#content
{
margin: 5px;
}
#footer
{
margin: 5px;
}
Can someone give me tips to what I can do? The structure is going to be used on a mobile website.
UPDATE
The code I have above gives me this:
But I want the 2 centered and the 3 on the right side. I don't want to set the width to a percent because the content in the elements may vary, meaning it may be 20/60/20 - 10/80/10 - 33/33/33 or something else.
Utilize the Magic of Overflow: Hidden
If you can swap the html position of 2 & 3 like so:
<div id="header-e1">
1 is wider
</div>
<div id="header-e3">
3 is also
</div>
<div id="header-e2">
2 conforms
</div>
Then you can set this css which will cause 2 to "fill" the available space because of the overlow: hidden on it. So if 1 & 3 expand, 2 narrows (shrink window down to see what happens at really small size).
#header-e1 {float: left;}
#header-e2 {overflow: hidden;}
#header-e3 {float: right;}
Technically, you could keep your current html order and your float: left on both 1 & 2 and make 3 the flex div with overflow: hidden. You could do the same with 1 by reversing the order of the html completely and setting 2 & 3 to float: right with 1 having overflow: hidden. To me it would seem best to have the middle flex, but you know your application better than I.
If you are trying to make the site with a responsive width, you can try the following (33% is roughly one-third):
#header-e1 {
float: left;
width:33%;
border: 1px solid black;
}
#header-e2 {
float: left;
width:33%;
border: 1px solid black;
}
#header-e3 {
float: left;
width:33%;
border: 1px solid black;
}
You could also used fixed widths for the divs. If you want the further from each other you can play with their left/right margins etc. Hope that helps!
Here is an edit for no widths:
#wrapper {
position:relative; (add to wrapper)
}
#header-e1 {
position:absolute;
left:0;
border:1px solid black;
}
#header-e2 {
position:absolute;
left:50%;
border:1px solid black;
}
#header-e3 {
position:absolute;
right:0;
border: 1px solid black;
}
You need to give the divs in your header a width, and float header-e3 left.
Note: They all have the same CSS properties, so just give them the same class like .headerDivs and then you don't have repeating code
Edit: here is a working jsfiddle: http://jsfiddle.net/eNDPG/
I'm using a similar idea to what RevCocnept suggested with the width: 33%, except using display: inline-block instead of float: left. This is to avoid removing the div elements inside #header from the flow of the page and causing the height of #header to become zero.
#header > div {
display: inline-block;
width: 31%;
margin: 5px 1%;
}
Demo
You can do something like this:
HTML
<div>
<div id="left">Left</div>
<div id="right">Right</div>
<div id="center">Center</div>
</div>
CSS
#left {
float: left;
border: 1px solid red;
}
#right {
float: right;
border: 1px solid blue;
}
#center {
margin-left: 50px;
margin-right: 50px;
border: 1px solid green;
text-align: center;
}
The centered <div> must come as the last one in the HTML code.
Here's a JS Bin to test: http://jsbin.com/evagat/2/edit
<style type="text/css">
body {
margin:0;
}
#header {
width:100%;
**strong text**margin:auto;
height:10%;
background-color:red;
}
#left {
width:20%;
float:left;
#margin:auto auto auto auto;
height:100%;
background-color:blue;
}
#right {
float:right;
width:20%;
#margin:auto auto auto auto;
height:100%;
background-color:green;
}
#middle {
position:relative;
left:0;
right:0;
margin:auto;
height:80%;
background-color:yellow;
width:100%;
}
#middle1 {
width: 80%;
margin:auto;
height:45%;
background-color:black;
}
#middle2 {
width: 80%;
margin:auto;
height:40%;
background-color:brown;
}
#middle3 {
width: 80%;
margin:auto;
height:15%;
background-color:orange;
}
#midmain {
width: auto;
margin:auto;
height:100%;
background-color:white;
}
#footer {
width:100%;
margin:auto;
height:10%;
background-color:red;
}
</style>
now check comment for html design.

CSS BaseLink and additionalLinks within a Div

I have the following structure:
<div class="boxLayer">
<div class="text">Result</div>
<div class="additionalLink"></div>
</div>
.boxLayer{
position: relative;
float:left;
height:28px;
width:100%;
border-top: 1px solid #cccccc;
background-color: #fff;
}
.boxLayer a {
display:block;
height:100%;
width: 100%;
background: white;
}
.boxLayer a:hover{
background-color: #ffeecc;
}
The idea is to have a box with a text shown at the left side of this box and an additional link at the right side of the box. When i hover over the box, the backgroundColor of the box is shown, also when i hover over the text or the second link. I have managed to create the Box, but when i add the text or the link, the hover-Effect of the box is not shown.
I am not sure this will be your answer
please check the fiddle:
.boxLayer {
position: relative;
height:auto;
float:left;
width:100%;
border-top: 1px solid #cccccc;
background-color: #fff;
}
.boxLayer:hover {
background-color: #ffeecc;
}
<div class="boxLayer">
<div class="text">Result</div>
<div class="additionalLink"> </div>
</div>

Resources