Position a <div> into another <div> - html

im just trying to do a normal Navigation but i seem to fail at it since i haven't done something like that in a long time. So here is what i got:
<div id="Top">
<div id="Navi">
<div class="Link">
link1
</div>
<div class="Link">
link2
</div>
</div>
</div>
and:
#Top {
width:100%;
min-height:100px;
height:15%;
max-height:200px;
background-color:#C6E466;
border-bottom-width:2px;
border-bottom-style:solid;
border-bottom-color:#4E6011;
position:relative;
}
#Navi {
width:100%;
position:absolute;
top:-1px;
left:-5px;
}
.Link {
height:20px;
margin-left:10px;
min-width:150px;
width:10%;
max-width:200px;
float:left;
background-color:#121212;
color:white;
text-decoration:none;
}
I just want to have:
- a complete header at the Top, which is #Top, convering the whole area at the top from left to right (width:100%).
- In the #Top header i want to display some Links done via #Navi. However i want to display #Navi in the bottom right corner of #Top. So i figured i would do #Top to position relative and #Navi position:absolute, but it doesnt work.
- Then i wanted the link color to be white, but somehow it doesnt work - why?
- Why do i need to use which i think is not cool? Without using the complete #Navi div wouldn't show up!
Thanks a lot!

try giving #Navi
bottom:0px and right:0px;

#Top {
width:100%;
min-height:100px;
height:15%;
max-height:200px;
background-color:#C6E466;
border-bottom-width:2px;
border-bottom-style:solid;
border-bottom-color:#4E6011;
position:relative;
}
#Navi {
width:100%;
position:absolute;
bottom: 0px;
}
.Link {
height:20px;
margin-left:10px;
min-width:150px;
width:10%;
max-width:200px;
background-color:#121212;
color:white;
text-decoration:none;
float: right;
}

not sure what are you trying, but here is a link: http://jsfiddle.net/4JdmH/
<div id="Top">
<div id="Navi">
<div class="Link">
link1
</div>
<div class="Link">
link2
</div>
<div class="clr"></div>
</div>
</div>
#Top {
width:100%;
min-height:100px;
height:15%;
max-height:200px;
background-color:#C6E466;
border-bottom: 2px solid #4E6011;
position:relative;
}
#Navi {
position:absolute;
bottom:0px;
right:0px;
}
.Link {
height:20px;
margin-left:10px;
min-width:150px;
width:10%;
max-width:200px;
float:left;
background-color:#121212;
color:white;
text-decoration:none;
}
.clr {
clear: both;
}

Related

Positioning of div with UL inside

i'm trying to create an horizontal menu on my site.
The idea is to have a layout in this way ----O---- where the - are the links of the menu and the O is a picture put in the middle of the page, so the two list are on the left and on the right and the are around the picture.
I've created the html
<div class="prima">
<ul class="prima_lista">
<li>primo</li>
</ul>
</div>
<div class="seconda">
<ul class="seconda_lista">
<li>secondo</li>
</ul>
</div>
and then i've created the CSS that will organize everything
.prima{
position:absolute;
top:400px;
width:50%;
left:-70px;
border:1px solid red;
}
.seconda{
position:absolute;
top:400px;
width:50%;
right:-70px;
border:1px solid green;
}
ul.prima_lista {
margin:0 auto;
list-style:none;
text-align:right;
border:1px solid blue;
}
ul.seconda_lista {
margin:0 auto;
list-style:none;
text-align:left;
border:1px solid blue;
}
ul.prima_lista li {
display:inline-block;
border:1px solid gray;
}
ul.seconda_lista li {
display:inline-block;
border:1px solid gray;
}
ul.prima_lista li a {
text-decoration:none;
color:#000;
font-size:18px;
}
ul.seconda_lista li a {
text-decoration:none;
color:#000;
font-size:18px;
}
The big problem is the while the first ul/li works perfectly and is well aligned on the right edge of the div... the second one instead present some spaces between the UL and the DIV margin. Is there a way to eliminate this space?
No matter how much i try i haven't find a way to solve this riddle -> http://jsfiddle.net/7voe8jea/
--- i've updated the link to the jsfiddle. first of all for it didn't work... and second because i think i haven't explained myself very well. What i'd like to do is to "push" the second ul to the left of the div just like the first one is aligned to the right edge of the first div.
I saw that rather that using an id for the div you used a class. SO i changed it to an id, and prefixed everything in the css with a #. Here is a link to the js with it working http://jsfiddle.net/fstxsd5g/1/
Here is the html:
<div id="lista">
<div id="prima_lista">
<ul id="prima_lista">
<li>primo</li>
</ul>
</div>
</div>
And the css
#lista {
position:absolute;
height:60px;
width:100%;
top:400px;
border:1px solid #000;
}
*/
#prima_lista{
position:absolute;
top:400px;
height:60px;
width:50%;
left:-70px;
border:1px solid red;
}
ul.prima_lista {
margin:0 auto;
list-style:none;
text-align:right;
}
ul.prima_lista li {
display:inline-block;
/* border-top:1px solid #dededc; */
/* padding-top:16px;
padding-right:40px; */
}
ul.prima_lista li a {
text-decoration:none;
color:#000;
font-size:18px;
}
.seconda_lista{
width:50%;
right:-70px;
}
ul.seconda_lista {
margin:0 auto;
list-style:none;
text-align:left;
}
ul.seconda_lista li {
display:inline-block;
border-top:1px solid #dededc;
padding-top:16px;
padding-right:40px;
}
ul.seconda_lista li a {
text-decoration:none;
color:#000;
font-size:18px;
}
Hope this helps! Littleswany

CSS Navigation Bar Not Flush With Browser

I am building a navigation bar. This is what the HTML looks like
<div class="navhead">TEXT</div>
<div class="navcontainer">
<div class="button">TEXT</div>
<div class="button">TEXT</div>
<div class="button">TEXT</div>
<div class="button">TEXT</div>
<div class="button">TEXT</div>
</div>
And this is what the CSS looks like.
body {
margin:0px;
padding:0px;
font-family:"futura";
margin-top:75px;
height:100%;
width:100%;
}
.navcontainer {
width:100%;
position:fixed;
background-color:#FFF;
height:60px;
top:24px;
border:solid;
color:#000;
border-top:none;
border-bottom:solid;
border-left:none;
border-right:none;
margin:0px;
padding:0px;
}
.button {
width:20%;
height:60px;
float:left;
background-color:#FFF;
color:#000;
text-align:center;
vertical-align:central;
line-height:60px;
transition:background-color 1.5s ease;
margin:0px;
padding:0px;
}
.button:hover {
width:20%;
height:60px;
float:left;
background-color:#000;
color:#FFF;
text-align:center;
vertical-align:central;
line-height:60px;
margin:0px;
padding:0px;
}
.navhead {
width:100%;
color:#FFF;
background-color:#000;
position:fixed;
top:0px;
height:24px;
text-align:center;
font-size:9px;
line-height:24px;
}
The problem I am having is that the last button to the right isn't flush with the browser window. I don't really know what I'm doing wrong. I added everything I thought I needed to the "body" class, but still there's space... I mean, there's no space on top of it, just to the right of the last button.
jsfiddle here
This is a better way to structure your HTML and a more reliable way to create that menu: http://codepen.io/pageaffairs/pen/xaGuq
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
body {
margin:0px;
padding:0px;
font-family:"futura";
margin-top:75px;
height:100%;
width:100%;
}
.navcontainer {
width:100%;
position:fixed;
background-color:#FFF;
top:24px;
border:solid;
color:#000;
border-top:none;
border-bottom:solid;
border-left:none;
border-right:none;
margin:0px;
padding:0px;
list-style: none;
display: table;
table-layout: fixed;
}
.navcontainer li {display: table-cell;}
.navcontainer li a {line-height: 60px;
background-color:#FFF;
color:#000;
text-align:center;
transition:background-color 1.5s ease;
display: block;
text-decoration: none;
}
.navcontainer li a:hover {
background-color:#000;
color:#FFF;
}
.navhead {
width:100%;
color:#FFF;
background-color:#000;
position:fixed;
top:0px;
height:24px;
text-align:center;
font-size:9px;
line-height:24px;
}
</style>
</head>
<body>
<div class="navhead">TEXT</div>
<ul class="navcontainer">
<li>
TEXT
</li>
<li>
TEXT
</li>
<li>
TEXT
</li>
<li>
TEXT
</li>
<li>
TEXT
</li>
</ul>
</body>
</html>

Positioning the DIV at correct position

I am new to CSS and have been trying lately to position the DIV where I wish too, but some properties like float and margin and confusing me. In the image below I am trying to place the white div to the right of the logo.
Since I am not able to post pictures yet on the post, I uploaded here
Html :
<body>
<header>
<div class="header">
<div class="logo">
<img src="images/logo.png" />
</div>
<nav>
<div class="navigation">
</div>
</nav>
</div>
</header>
</body>
css :
.header {
max-width:1200px;
min-width:200px;
height:170px;
margin:0 auto;
margin-top:10px;
background-color:rgba(0, 0, 0, 0.5);
border-radius:3px;
}
.logo {
width:230px;
}
.logo img {
margin-left:20px;
margin-top:31px;
border-right:solid #FFF 1px;
padding-right:33px;
height:auto;
width:auto;
}
.navigation {
width:500px;
height:100px;
margin-left:200px;
background-color:#FFF;
position:fixed;
}
Change .navigation's position:fixed; to position:inline-block; and add margin-top to make them in line vertically depending on how tall each is
Or you could float:left; both of them
Replace below .logo img and .navigation with your CSS with this, here is the fiddle
.logo img {
margin-left:20px;
margin-top:31px;
border-right:solid #FFF 1px;
padding-right:33px;
height:auto;
width:auto;
float:left;
}
.navigation {
width:500px;
height:100px;
margin-left:200px;
margin-top:31px;
background-color:#FFF;
position:fixed;
}
place float:left; in your .logo img {...} class
place margin-top:31px; in your .navigation {...} class

Creating a horizontal nav bar easily in a header

I have a certain Header with my Logo and title. Just to the right of the Title Mobility group I want to create a nav bar that touches the bottom of the header with different tabs all the way to the right of the header. Messing around I was able to create something, but I can't seem to position it correctly.
http://jsfiddle.net/jHJK2/
http://jsfiddle.net/jHJK2/embedded/result/
I just can't figure out how to add this navigation bar to my header div.
HTML code:
<div id="page">
<div id="header">
<a href="http://wireless.fm.intel.com/test/index.php">
<img src="http://wireless.fm.intel.com/test/logo2.png" border=0 >
</a>
<h2><a href="http://moss.ger.ith.intel.com/sites/MWG-IS/Pages/Default.aspx" border=0>Mobility Group</a></h2>
<div id="navigation">
About
Reports
Documents
Checklists
License Tools
Presentations
Software Releases
</div>
</div>
<div id="main"></div>
<div id="footer"></div>
</div>
CSS Code:
html, body {
padding:0;
margin:0;
height:100%;
}
#page {
min-height:100%;
position:relative;
height:100%;
}
#header {
background-color:#115EA2;
height:100px;
width:97.5;
}
#main {
width:1300px;
margin-left:auto;
margin-right:auto;
background-color:#F1F2F3;
min-height:90%;
height:auto;
height:89%;
margin:0 auto -50px;
vertical-align:bottom;
}
#footer {
position:fixed;
width:100%;
bottom:0;
height:35px;
background-color: #115EA2;
}
#header img {
float:left;
display:inline;
}
#header h2 {
text-align:center;
font-size:44px;
color:#FFFFFF;
left:0px;
top:20px;
font-weight:bold;
font-family: Sans-serif;
float:left;
margin-top:20px;
margin-left:20px;
text-decoration:none;
}
#header h2, a, a:visited, a:hover, a:active {
color: #FFFFFF;
text-decoration: none;
}
Navigation Bar Code:
#navigation {
position:relative;
top:0;
left:0;
right:0;
bottom:0;
width:70%;
background-color:gray;
color:green;
height:35px;
text-align:center;
padding-top:15px;
}
#navigation a {
font-size:14px;
padding-left:15px;
padding-right:15px;
color:black;
text-decoration:none;
}
#navigation a:hover {
color:blue;
}
Update
Just wanted to say Thank you all for your help.
Adapting your current method to a more html5 approach, you can use header and nav tags do better markup your document. Absolute positioning also gives you better control over your elements. You would set the header to a relative position, and the nav to absolute, and offset it by the height of your header.
nav {
position: absolute;
top: 100px;
left: 0;
right: 0;
bottom: 0;
min-width: 800px;
text-align: left;
height: 20px;
padding: 10px 20px;
}
Here is your updated fiddle
And here is an update with the nav to the right, a bit messy though:
http://jsfiddle.net/jHJK2/5/
Not 100% sure if this is how you want it since your request wasn't very clear, but here's what I made.
http://jsfiddle.net/jHJK2/2/
Changes:
HTML:
<div id="header">
<div id="navigation"> //moved this before the other elements
About
Reports
Documents
Checklists
License Tools
Presentations
Software Releases
</div>
<a href="http://wireless.fm.intel.com/test/index.php">
<img src="http://wireless.fm.intel.com/test/logo2.png" border=0>
</a>
<h2><a href="http://moss.ger.ith.intel.com/sites/MWG-IS/Pages/Default.aspx" border=0>Mobility Group</a></h2>
</div>
CSS:
#navigation {
width:100%;
background-color:gray;
color:green;
height:35px;
text-align:center;
padding-top:15px;
}
#navigation a {
font-size:14px;
padding-left:15px;
padding-right:15px;
color:black;
text-decoration:none;
}
#navigation a:hover {
color:blue;
}
Make the following CSS changes:
Demo in jsFiddle
#header {
background-color:#115EA2;
height:100px;
width:97.5;
position: relative;
}
#navigation {
position:absolute;
/* top:0;
left:0;*/
right:0;
bottom:0;
width:70%;
background-color:gray;
color:green;
height:35px;
text-align:center;
padding-top:15px;
}

Positioning two floating blocks in absolute positioned division

here is the code
http://jsfiddle.net/77NBM/12/
two grey squeares ("float 1" and "float 2") have to be positioned beside each other in absolute positioned division "submenu_container" related to < li > "menu 3".
Can plz somebody help me to get it? :(
Thx!
If you'll always have two elements ("float1 and float2") of 100px each, you can set the width of .submenu_container to 220px and they will float beside each other. like this http://jsfiddle.net/77NBM/13/
If the width of the elements ("float1 and float2") is dynamic, I suggest you set the width of .submenu_container dynamicly width javascript or jQuery. for example:
$('#main_menu li').each(function(index) {
var menuWidth=0;
$(this).children().children().each(function(index) {
menuWidth+=$(this).outerWidth();
}
$(this).children('.submenu_item').width(menuWidth)
});
The width of your submenu is being constrained by the width of your li element, just add some width to your submenu and they should float:left naturally
CSS
#top{
width:500px;
height:300px;
position:relative;
margin:0px auto;
background:#ccc;
}
#navigation{
position:absolute;
width:100%;
height:50px;
top:250px;
left:0px;
background:#f00
}
#main_menu{
width:auto;
height:50px;
margin-left: 0;
padding-left: 0;
list-style-type: none;
}
#main_menu li{
width:100px;
height:50px;
margin-right:10px;
float:left;
background:#ff0;
position:relative;
}
#main_menu li a{
display:block;
width:inherit;
height:inherit;
}
.submenu_container{
position:absolute;
background:#00f;
padding:5px;
left:-5px;
width:275px;
}
.submenu_item{
width:100px;
height:100px;
float:left;
background:#eee;
margin:5px;
}
http://jsfiddle.net/77NBM/17/
By the way, your html markup is full of errors, you need to take a look at that.
HTML
<div id="top" class="center">
<div id="navigation">
<ul id="main_menu">
<li>
Menu 1
</li>
<li>
Menu 2
</li>
<li>
Menu 3
<div class="submenu_container">
<div class="submenu_item">
Float 1
</div>
<div class="submenu_item">
Float 2
</div>
</div>
</li>
<li>
Menu 4
</li>
</ul>
</div>
</div>
#top{
width:500px;
height:300px;
position:relative;
margin:0px auto;
background:#ccc;
}
#navigation{
position:absolute;
width:100%;
height:50px;
top:250px;
left:0px;
background:#f00
}
#main_menu{
width:auto;
height:50px;
margin-left: 0;
padding-left: 0;
list-style-type: none;
}
#main_menu li{
width:100px;
height:50px;
margin-right:10px;
float:left;
background:#ff0;
}
#main_menu li a{
display:block;
width:inherit;
height:inherit;
}
.submenu_container{
width:auto;
position:absolute;
background:#00f;
padding:5px;
left:-5px;
}
.submenu_item{
width:100px;
height:100px;
float:left;
background:#eee;
margin:5px;
}