html - Positioning a container without it moving when space is changed -
i'm trying position 1 container in specific place - how can , make stay proportionate place when zoom in or out screen?
html:
<?xml version="1.0" encoding="utf-8"?> <!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="test.css"> <link href='http://fonts.googleapis.com/css?family=special+elite' rel='stylesheet' type='text/css'> </head> <body> <div id="huvud"> </div> <div id="nav-yttre"> <div id="nav-mitten"> <ul id="nav-inre"> <li><a href="index.html">hem</a></li> <li><a href="om_oss.html">om oss</a></li> <li><a href="blogg.html">blogg</a></li> <li><a href="marken.html">märken</a></li> <li><a href="hitta_hit.html">hitta hit</a></li> </ul> </div> </div> <div id="main"> <p>hem</p> </div> <div id="right"> <p>this container</p> </div> <div id="fot"> <div id="adress"> <p id="rub">besöksadress</p> <p>vägen 1, 12345 stockholm</p> </div> <div id="kontakt"> <p id="rub">kontakta oss</p> <p>telefon: 08-123 45 67</p> <p>mail: info@hej.se</p> </div> <div id="tider"> <p id="rub">öppettider</p> <p>vardagar: 10-19<br>lördag: 10-17<br>söndag: 11-16</p> </div> <div id="design"> <p>webbplatsen är gjord av md</a></p> </div> </div> </body>
css:
/* header */ #huvud{ width: 1000px; margin: 0 auto; } #header{ display: block; } /* meny */ #nav-yttre{ width: 1000px; height: 35px; margin: 0 auto; background-image: url("rusty-bar2.jpg"); } #nav-mitten{ display: table; width: 100%; padding: 10px; } #nav-inre{ display: table-row; list-style: none; font-family: 'special elite', cursive; font-size: 25px; } #nav-inre li{ display: table-cell; } #nav-inre li a{ display: block; text-decoration: none; text-align: center; color: #eeeeee; } #nav-inre li #here{ color: #221f20; } #nav-inre li a:hover{ color: #221f20; } /* main */ #main{ width: 1000px; margin: 0 auto; min-height: 500px; } #fadein { margin: 10px auto; position:relative; width:281px; height:500px; padding: 5px; box-shadow: 0 0 20px rgba(0,0,0,0.4); } #fadein img { position:absolute; } /* right */ #right{ position: absolute; left: 1450px; top: 200px; background-color: #221f20; height: 300px; width: 200px; } #right p{ color: white; } /* fot */ #fot{ width: 1000px; margin: 0 auto; border-top: solid #221f20 1px; text-align: center; clear: both; } #adress{ width: 334px; float: left; } #kontakt{ width: 333px; float: left; } #tider{ width: 333px; float: right; } #design{ width: 500px; margin: 0 auto; clear: both; text-align: center; background-image: url(rusty-bar-small.jpg); } #design p{ color: #eeeeee; font-weight: bold; } #design a{ color: #eeeeee; } #design a:hover{ color: #221f20; } #rub{ font-weight: bold; } /* allmänt */ p{ font-family: verdana, arial, sans-serif; color: #221f20; font-size: 0.9em; }
fiddle: http://jsfiddle.net/nvsodsfs/1/
and result: http://jsfiddle.net/nvsodsfs/1/embedded/result/
you have div centered , 1000px wide: #huvud
.
place div in #huvud
:
<div id="huvud"> <div id="right"> <p>this container</p> </div> </div>
make #huvud
display: relative
position absolute children position in relation it. looks this:
#huvud { width: 1000px; margin: 0 auto; position: relative; }
make #right
left: 100%
forced outside of new parent , give left margin desired:
#right { position: absolute; left: 100%; top: 200px; background-color: #221f20; height: 300px; width: 200px; color: #fff; margin-left: 100px; /*need more?*/ }
complete example
all other content has been removed simplicity.
make example full-screen , see remain fixed in place on zoom-in/out
/* header */ #huvud { width: 1000px; margin: 0 auto; position: relative; } /* right */ #right { position: absolute; left: 100%; top: 200px; background-color: #221f20; height: 300px; width: 200px; color: #fff; margin-left: 100px; }
other content removed simplicity - div way >>>>>> <div id="huvud"> <div id="right"> <p>this container</p> </div> </div>
Comments
Post a Comment