why isn't my list floated inside my second div? - html

This is my HTML:
<div class="topmenucontainer">
<div id="topmenu">
<ul>
<li style="border-right: 1px solid black;">Login</li>
<li>Partner Countries</li>
</ul>
</div>
This is my CSS:
.topmenucontainer {
margin:0 auto;
border:1px solid red;
background-color:#000;
display:block;
}
#topmenu {
margin:0 auto;
border:1px solid red;
/*min-height:25px;*/
background-color:#fff;
width:900px;
display:inline;
}
#topmenu ul {
margin:0px; padding:0px;
list-style-type: none;
float:right;
}
#topmenu ul li {
float:left;
}
And This is how it is displayed
http://img842.imageshack.us/img842/8627/3ktn.jpg
Why the UL isn't displayed where I putted it?I mean why isn't it displayed inside my topmenu div which is white backgrounded and only 900px wide?

You need to add a clear:both div to handle the inner floating
<div class="topmenucontainer">
<div id="topmenu">
<ul>
<li style="border-right: 1px solid black;">Login</li>
<li>Partner Countries</li>
</ul>
<div style="clear:both;"></div>
</div>
</div>

I think you don't need any styles on your .topmenucontainer*. you can get rid of the .topmenucontainer styles
you can try the below styles on topmenu. Do you have a final picture of what you are trying to achieve?
#topmenu {
overflow: hidden;
margin: 0 auto;
border: 1px solid red;
background-color: #fff;
width: 900px;
}

Related

Empty space after unordered list item

There is unwanted space after unordered list shown in IE and Firefox in the last HTML <li> item that can't be removed with reducing the ul width. Anyone have idea how to remove the space? Thanks.
#menubar {
width:249px;
margin:0 auto;
list-style:none;
border:1px solid grey;
border-radius:3px;
margin-top:5px;
padding:0;
height:26px;
}
.toggle {
margin:0;
line-height:16px;
float:left;
border-right: 1px solid grey;
padding:5px 8px 5px 8px;
}
.selected {
background-color:grey;
}
<body>
<ul id="menubar">
<li class="toggle selected">HTML</li>
<li class="toggle">HTML</li>
<li class="toggle">HTML</li>
<li class="toggle selected" style="border-right:none;">HTML</li>
</ul>
</body>
Don’t specify a fixed width on the ul, but make it display as inline-block instead. (And if you need it horizontally centered, then use text-align:center on the parent element.)
div {
text-align:center;
}
#menubar {
display:inline-block;
margin:0 auto;
list-style:none;
border:1px solid grey;
border-radius:3px;
margin-top:5px;
padding:0;
height:26px;
text-align:left; /* reset text-align for list contents, if necessary */
}
.toggle {
margin:0;
line-height:16px;
float:left;
border-right: 1px solid grey;
padding:5px 8px 5px 8px;
}
.selected {
background-color:grey;
}
<body>
<div>
<ul id="menubar">
<li class="toggle selected">HTML</li>
<li class="toggle">HTML</li>
<li class="toggle">HTML</li>
<li class="toggle selected" style="border-right:none;">HTML</li>
</ul>
</div>
</body>

How to fixate this div into this other div? It's a nav bar and it won't align vertically

Sorry for the n00b questions but here goes:
As seen in the screenshot, I can't align the text list items to the nav bar. Refer to the code so you can see what i'm talking about. It's a bit of a mess but what I basically have is a master div that holds the other divs in attempts to keep them "organized"
If anyone can help, it'd be great. thanks!
Screenshot here: http://imgur.com/dL1eMXR
HTML
<div class="masterwrappernav">
<div class="abovenav">
<div class="logowrappers">
<div id="logo">
<img src="img/logo.png">
</div>
<div id="slogan">
<img src="img/1pyramid.png">
</div>
</div>
</div>
<div class="headernav">
<div class="nav">
<ul>
<li>Home</li>
<li>About</li>
<li>Articles</li>
<li>Devotions</li>
<li>Bible Study</li>
<li>Schedule</li>
<li>Merchandise</li>
<li>Contact Us</li>
<li>Donations</li>
</ul>
</div>
</div>
</div>
CSS
.masterwrappernav {
background-color:#11120D;
width:100%;
height:180px;
margin:0 auto;
}
.abovenav {
background-image:url('/img/wtmot.png');
background-color:#f7f7f7;
width:100%;
height:140px;
margin:0 auto;
box-shadow: 1px 1px 18px #D6D6D6;
}
.headernav {
position:absolute;
background-image:url('/img/grad.png');
background-color:#f7f7f7;
height:40px;
width:100%;
box-shadow: 1px 1px 10px #212121;
text-align:center;
}
.nav {
position:relative;
margin: 0 auto;
}
.nav ul li {
display:inline;
font-family:'Roboto', sans-serif;
font-size:19px;
}
.nav ul li a:link {
border-left:1px solid;
padding:9px 1%;
background-image:url('/img/grad.png');
background-color:#f7f7f7;
color:#454443;
text-decoration:none;
}
Thanks in Advanced
You have a fixed height of 40px on your .headernav. Auto height can fix the alignment problem.
.headernav {
height: auto;
}
Otherwise, if you want exact 40px height for .headernav you can use this snippet below-
.nav ul {
margin-top: 5px;
}
.nav ul li a:link {
padding-top: 0;
padding-bottom: 0;
}
you're messing around with "position: absolute;" without any need IMHO and your UL/LI get some auto-assigned margin/padding - use a RESET!
Look at this jsfiddle for a possible way to a solution.
CSS:
.masterwrappernav
{
background-color:#11120D;
height:180px;
margin:0 auto;
}
.abovenav
{
background-color:#f7f7f7;
height:140px;
margin:0 auto;
box-shadow: 1px 1px 18px #D6D6D6;
}
.headernav
{
background-color:#f7f7f7;
height:40px;
width:100%;
box-shadow: 1px 1px 10px #212121;
text-align:center;
}
.nav
{
margin: 0 auto;
}
.nav ul { margin: 0; padding: 0; }
.nav li { margin: 0; padding: 0; }
.nav ul li
{
display:inline;
font-family: sans-serif;
font-size:19px;
height: 40px;
line-height: 40px;
}
.nav ul li a:link
{
border-left:1px solid;
padding:9px 1%;
background-color:#f7f7f7;
color:#454443;
text-decoration:none;
}
HTML:
<div class="masterwrappernav">
<div class="abovenav">
<div class="logowrappers">
<div id="logo"><!--<img src="img/logo.png" alt="LOGO">--></div>
<div id="slogan"><!--<img src="img/1pyramid.png" alt="PYRAMID">--></div>
</div>
</div>
<div class="headernav">
<div class="nav">
<ul>
<li>Home</li>
<li>About</li>
<li>Articles</li>
<li>Devotions</li><li>Bible Study</li>
<li>Schedule</li>
<li>Merchandise</li>
<li>Contact Us</li>
<li>Donations</li>
</ul>
</div>
</div>
</div>

Fitting nested text inside a div

I have a (left) div which width is set to 30% of the containing parent.
Inside that div I have a paragraph that ignores the column margin. How do I make the text to be wrapped inside the parent div (container)?
the css
body {
margin:0;
padding:0;
border:0;
background-image:url(../img/Background.png);
}
#container {
width:960px;
border:2px solid red;
margin:auto;
}
#header {
margin-top:10%;
border: 1px solid green;
height:150px;
background: #000;
}
ul {
list-style:none;
}
li {
font-size:1.5em;
display:inline-block;
float:right;
margin: 40px;
color:white;
}
img {
border: 1px solid #39C;
}
.left {
width:30%;
height:500px;
border: 1px solid #93F;
}
.left p {
}
and the html
<body>
<div id = container>
<div id = header>
<img src="img/firma.png" width="231" height="80"/>
<ul>
<li> Home </li>
<li> Cds </li>
<li> Bio </li>
<li> Contacts </li>
</ul>
</div> <!--end of header-->
<div class = "left">
<p> fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo </p>
</div> <!--end of left-->
</div> <!--end of container-->
</body>
Add the CSS rule word-wrap:break-word to your .left class:
.left {
width:30%;
height:500px;
border: 1px solid #93F;
word-wrap:break-word;
}
jsFiddle example
https://developer.mozilla.org/en-US/docs/Web/CSS/word-wrap
You may use word-wrap property. Example: http://jsfiddle.net/r7EdS/
.left p {
word-wrap: break-word;
}

Why can't I center my menubar?

I'm pretty new to HTML and CSS. I'm making a menu bar horizontal and I can't seem to align it to center of screen. I have tried margin:0 auto; and <body align=center> but neither seems to work.
Here is my code:
<html>
<head>
<style>
#menu {
margin:0 auto;
float:left;
list-style:none;
padding:0;
border-top:1 solid #ccc;
border-left:1 solid #ccc;
border-bottom:1 solid #ccc;
}
#menu li {
float:left;
background-color:#f2f2f2;
}
#menu li a {
display:block;
padding:10px 80px;
text-decoration:none;
color:#069;
border-right:1px solid #ccc;
font-weight:bold;
}
#menu li a:hover {
color:#c00;
background-color:#fff;
}
</style>
</head>
<body>
<ul id="menu">
<li>Home</li>
<li>Gallery</li>
<li>Contact</li>
<li>FAQs</li>
<li>Donate</li>
</ul>
</body>
</html>
As you can see, I'm using margin:0 auto;, but it doesn't work.
You have float elements. Floating elements will not follow that centering unless your container is treated as a block, or inline block.
To reach the desired result, you'd want to do something like in this example.
By adding a container, center margin and using display: inline-block on the #menu they will be centered like normal content. Note that this might not work in IE, in which case, you should add a line with *display: inline;.
Example | Code
HTML
<div class='container'>
<ul id="menu">
<li>Home</li>
<li>Gallery</li>
<li>Contact</li>
<li>FAQs</li>
<li>Donate</li>
</ul>
</div>
CSS
.container{
text-align: center;
width: auto;
margin: 0 auto;
}
#menu {
margin:0 auto;
display: inline-block;
list-style:none;
padding:0;
border-top:1 solid #ccc;
border-left:1 solid #ccc;
border-bottom:1 solid #ccc;
}
#menu li {
float: left;
background-color:#f2f2f2;
}
#menu li a {
display:block;
padding:10px 10px;
text-decoration:none;
color:#069;
border-right:1px solid #ccc;
font-weight:bold;
}
#menu li a:hover {
color:#c00;
background-color:#fff;
}
Give your menu a width if you want to center it inside it's parent element (in this case, the body.) Additionally, remove your float - it's not going to center if you're floating it one direction or another.
You can give the menu a width width: 400px; or what your desired width is. Then, you can set the left and right margin to auto margin-left: auto; margin-right: auto;
You need to give a width to your menu and remove float:left
eg.
#menu {
margin:0 auto;
list-style:none;
padding:0;
border-top:1 solid #ccc;
border-left:1 solid #ccc;
border-bottom:1 solid #ccc;
width:900px;
display:block;
}

horizontal menu coloring goes wrong

<div id="header">
<div id="logo">
<h1>Look Around You</h1>
</div>
<div id="horNav">
<ul class="horNav">
<li class="horNav">HOME</li>
<li class="horNav">SUBMIT-CONTACT</li>
</ul>
<ul class="horNav-last">
<li class="horNav">TAGS</li>
</ul>
<ul class="advertisment">
<li>ABOUT</li>
<li>ADVERTISEMENT</li>
</ul>
</div>
</div>
css is:
#wrapper{
width:80%;
margin:0 auto;
min-width:920px;
}
#header, #logo{
width: 100%;
float:left;
}
#horNav{
background:black;
width: 80%;
color:white;
margin: 0 auto;
}
#horNav a{
background: black;
}
.horNav li{
float:left;
border-right:1px solid #828282;
}
.horNav-last li{
float:left;
}
.advertisment li{
float:right;
border-left:1px solid #828282;
}
#horNav a{
display:block;
padding:5px 10px;
color:white;
font-size: 13px;
}
#horNav a:hover{
background:#828282;
}
what happens is that unordered lists are colored black in separate corners and middle of #horNav is white as you can see it HERE but of course it needs to be all black. how to fix this?
#horNav {
overflow: hidden;
display: block;
width: 100%;
}
#horNav can be whatever width you want e.g. 80% as it is now, and if you want it to be centred you can reintroduce the margin: 0 auto;.