Navigation bar glitches - html

When I change the resolution of my navigation bar it glitches. Here is my HTML;
<!--Start header-->
<div id="header">
<div id="nav_header">
<ul id="list-nav">
Troll Happy
<li>iPhone Fail</li>
<li>Forever Alone</li>
<li>Rage Comics</li>
<li>Derpina</li>
<li>Okay face</li>
<li>Forums</li>
</ul>
</div>
</div>
<!--End header-->
And my CSS;
#header {
height:66px;
background-color:#000;
position: absolute;
width: 100%;
left:0;
}
#nav_header {
height:50px;
margin-left:100px;
}
ul#list-nav {
list-style:none;
margin:20px;
padding:0;
}
ul#list-nav li {
display:inline;
font-family: Century Gothic, sans-serif;
font-size:13px;
font-weight:bold;
}
ul#list-nav li a {
text-decoration:none;
padding:15px 0;
width:110px;
color:#eee;
float:left;
text-align:center;
border-right:1px solid #353535;
}
You can see what is happening here;
trollhappy.co.uk
As you can see, if you change the resolution the navigation bar goes very glitchy!
Thanks again guys and girls

you just small mistakes, it follows;
u remove the margin-left:100px, insted margin:0px auto; and set width:840px;
#nav_header {
height: 50px;
margin: 0 auto;
width: 840px;
}
ok i understand the misstake, u set the body tag then work perfectly,,,,
body{
margin:-18px 0px 0px 0px;
}
ok friend on small changes do this,u add the min-width:1000px;
#header {
background-color: #000000;
height: 70px;
left: 0;
min-width: 1000px;
position: absolute;
right: 0;
}

Your <li><a> elements are being floated left, which means they'll overspill their container if they can't all fit in a single line because the container is horizontally too small.
For simplicity's sake you'll want to just hide the links rather than implement some nice graceful degradation for smaller screens (just make sure it looks nice with a browser window 960px wide). Just apply the overflow: hidden; style to #nav_header.

Related

How to move a p tag up within a div tag? [duplicate]

This question already has answers here:
How can I vertically align elements in a div?
(28 answers)
Vertically align text next to an image?
(26 answers)
Closed 2 years ago.
I am currently working on a navigation bar for my website, and am super new to CSS and HTML.
I have a header split up into two divs, one for the top half displaying the logo, title, and login page, and another for the navigation buttons. I am running into issues, where my p tag leaves the div that it is inside of, and gets in the way of my navigation buttons. Here is an image of the issue:
[1]: https://i.stack.imgur.com/MoSsk.png
What you are looking at is the inspect element view of a p tag next to an image tag, both within a div.
Here is some html:
header{
background-color: #B71C1C;
color: #FFFFFF;
position:fixed;
top:0;
left:0;
width:100%;
height:150px;
margin-left: 0px;
margin-right: 0px;
}
#bar_logo{
max-height:90px;
max-width:90px;
height:auto;
width:auto;
margin:0;
padding:0;
}
.upper_banner{
width:100%;
height:60%;
margin: 0;
padding: 0;
}
#title_banner{
margin:0;
padding:0;
display: inline;
height:60%;
font-size: 45px;
font-family: Helvetica;
text-align:center;
top: -20;
}
#login{
float: right;
margin:10px;
}
.lower_banner{
width: 100%;
height: 40%;
margin:0;
padding:0;
}
<header>
<div class="upper_banner">
<img id="bar_logo" src="https://picsum.photos/100/100" alt="Title">
<p id="title_banner">
Title of Website
</p>
<a id="login" href="login.html">login</a>
</div>
</header> <!-- added by Rickard -->
I am having some troubles working out this issue, as when I do highlighting over the div "upper_banner" it doesn't highlight past my image on the far right. As you can see, I was attempting to use
top: -20;
in an attempt to move it up 20 px, but no difference. I have a feeling that this issue is because my p tag is starting at a certain point, and because my height is set to a fixed pixel count, it is going down that number of pixels, which leads to it overflowing into the div below.
Apologies for the wicked beginner question, super new to all of this.
Try adding the following in .upper_banner class element's CSS.
display:flex;
justify-content: center;
For more clarity, do search around and study flex boxes and flex alignments. It could help you a lot!
All elements have position: static as default. If you want to move elements around with top or left, you need to change the positioning to relative, absolute or fixed.
Elements align normally at the bottom. If you want a different alignment, you can use vertical-align. It's today better to use display: flex and then control where the elements are with align-items: center or justify-content: center.
You should rarely use float or position: absolute because that makes the elements loose their height, and can mess up the rest of the design.
Inline-elements adjust their width and height to the content, so it doesn't make any sense to give them a height (like your #title_banner).
Here is the code I added, where I target all (*) elements that are children (>) to .upper_banner.
.upper_banner > * {
vertical-align: middle;
}
header{
background-color: #B71C1C;
color: #FFFFFF;
position:fixed;
top:0;
left:0;
right:0;
height:150px;
margin-left: 0px;
margin-right: 0px;
}
#bar_logo{
max-height:90px;
max-width:90px;
height:auto;
width:auto;
margin:0;
padding:0;
}
.upper_banner{
width:100%;
margin: 0;
padding: 0;
}
/* ADDED */
.upper_banner > * {
vertical-align: middle;
}
#title_banner{
margin:0;
padding:0;
display: inline;
font-size: 45px;
font-family: Helvetica;
}
#login{
float: right;
margin:10px;
}
.lower_banner{
width: 100%;
height: 40%;
margin:0;
padding:0;
}
<header>
<div class="upper_banner">
<img id="bar_logo" src="https://picsum.photos/100/100" alt="Title">
<p id="title_banner">
Title of Website
</p>
<a id="login" href="login.html">login</a>
</div>
</header>
Here is an example, where I used flex. Comments are within the code:
header{
background-color: #B71C1C;
color: #FFFFFF;
position:fixed;
top:0;
left:0;
height:150px;
margin-left: 0px;
margin-right: 0px;
/* ADDED */
right: 0;
}
#bar_logo{
max-height:90px;
max-width:90px;
height:auto;
width:auto;
margin:0;
padding:0;
}
.upper_banner{
/*width:100%;*/
margin: 0;
padding: 0;
/* ADDED */
display: flex;
align-items: center;
}
#title_banner{
margin:0;
padding:0;
/*display: inline;*/
font-size: 45px;
font-family: Helvetica;
/* ADDED */
flex: 1 1 auto /* fill up all excessive space, pushing #login to the right */
}
#login{
/*float: right;*/
/*margin:10px;*/
/* ADDED */
padding: 10px; /* margin messes up spacing for flex layout */
align-self: flex-start;
}
/*.lower_banner{
width: 100%;
height: 40%;
margin:0;
padding:0;
}*/
<header>
<div class="upper_banner">
<img id="bar_logo" src="https://picsum.photos/100/100" alt="Title">
<p id="title_banner">
Title of Website
</p>
<a id="login" href="login.html">login</a>
</div>
</header>

How to cut divs both ways to keep the objects in center?

I am trying to build a nav-bar that stays on top, fixed and in the middle. But if the screen size is large enough some unused space can be used left and right according to my needs and also there's a bit of space in the middle.
Now, if someone resizes the browser window, I need to start stripping off the unused space from the screen and keep only the essential divs of the parent div.
For reference have a look at Facebook's Desktop navbar.
How do I achieve this with html and css?
Also, if someone resizes so much that the objects will be affected anyway, I would want them to just getting cut off the screen without altering their positions.
<html>
<head> <style>
.navbar {
position:fixed;
background: #000;
height: 30px;
width: 100%}
.logo_div{
margin-left:7%;
float:left;
width:32px;
display:inline-block;
height:32px;
}
.search_div {
width: 450px;
display: inline-block;
margin-left:15px;
float:left;
}
#search_box {
width:100%;
border-radius:5px;
border:1px solid #819597;
padding:4px;
border-bottom-right-radius:0px;
border-top-right-radius:0px;
border-right:none;
height:24px;
font-family: Arial;
font-size:16px;
font-weight:lighter;
outline:none;
}
#search_box:focus {
border-right:none;
background-color:#FCFCDA;
}
li {
text-decoration:none;
padding:5px;
padding-bottom:0px;
margin:1px;
margin-top:0px;
list-style:none;
display:inline-block;
}
.menu {
padding:3px;
float:left;
display:inline-block;
padding-left:10px;
}
ul {
margin-top:0px;}
#static_head{
width:1024px;
margin:0 auto;
position:absolute;
text-align:center;
}
.user_controller {
display:inline;
margin:0 auto;
height:100%;
width:auto;
}
</style>
</head>
<body>
<div class="container">
<div class="navbar" id="dHeaderfixed">
<div id="static_head">
<div id="logo_div" ></div>
<div class="search_div">
<form action="search.php" method="get" id="search_form" name="livesearch">
<input type="text" id="search_box" name="query"></form>
</div>
<div class="menu">
a list of things
</div>
<div id="ui_user_control">some stuff</div></div>
</div></div></div>
Now, the blank unused spaces should be in the navbar at the left of the logo div, this will be as long as required according to screen size. Again there will be unused space between the search box and the menu div and another unused space at the right of the menu div, so when the user resizes the browser window, all of those elements stay in the middle,and if resized further, the screen just cuts them out instead of altering their positions. Thanks!
https://jsfiddle.net/xhzxduz2/2/
CSS
nav {
position: fixed;
left: 0;
top: 0;
background: red;
height: 48px;
min-width: 320px;
width: 100%;
}
.content {
max-width: 960px;
margin: 0 auto;
color: white;
background: blue;
height: 100%;
}
HTML
<nav>
<div class='content'>
YOUR MENU HERE
</div>
</nav>

Navbar item moves down when resizing

I'm creating my first responsive website. I have a navbar inside a container that is centered horizontally.
Everything has a size with a percentage (is there a term for this?). The navbar scales down when I resize the window correctly. But my last list item (navbar item) will move down.
I have tried a lot with the min-width stuff, and I know it has something to do with this. But all solutions on the internet say I should give the navbar (or the ul?) a fixed width (xxxx px). This I don't want because I want it to fully scale.
HTML:
<body>
<div id="container">
<nav>
<ul>
<li><span class="navbaritem">Test1</span></li>
<li><span class="navbaritem">Test2</span></li>
<li><span class="navbaritem">Test3</span></li>
<li><span class="navbaritem">Test4</span></li>
<li><span class="navbaritem">Test5</span></li>
</ul>
</nav>
</div>
</body>
CSS:
#charset "utf-8";
/* CSS Document */
html
{
width:100%;
height:100%;
}
body
{
background-image:url(images/background.png);
background-repeat:repeat;
min-height:100%;
margin:0px;
overflow: auto;
}
#container
{
height:100%;
width:73.20%;
background-color:#00CC00;
margin: auto;
left:0; right:0;
top:0; bottom:0;
position:absolute;
}
#navbar
{
min-width:100%;
min-height:13.28125%;
position:absolute;
background-color:#FF0000;
}
nav {
position:relative;
background-color:#FF0000;
color: #888;
display: block;
width:100%;
height:13.28125%;
}
nav ul
{
list-style-type:none;
width:100%;
height:100%;
margin:0;
padding:0;
}
nav li
{
display: table;
float:left;
border-style: solid;
border-width: 1px;
border-color:#333;
width:20%;
height:100%;
text-align:center;
box-sizing:border-box;
}
.navbaritem
{
font-family: Cambria;
color:#CCCCCC;
font-size:36px;
display: table-cell;
vertical-align: middle;
}
You can change the width of the menu item to 20% and apply box-sizing:border-box. Your problem was due to insufficient width at smaller screen sizes when you are mixing border size in px and width in %.
See the fiddle

Fluid css floats

I'm trying to create a fluid element for a site i'm working on, Check out this JS fiddle and make your browser a bit wider, you will see a grey line, a black box, and then a grey line.
When the browser's width is lower the right side line breaks down to the next line, but i want this to stay together no matter how wide the browser is. I generally use float's but have tried a few things, as you can see some css is commented out cause i'm playing with it.
Does anybody have some cool tricks to show me? Any help would be greatly appreciated! Let me know if you need any info.
http://jsfiddle.net/r8Xka/
CSS
header .lower{
overflow:hidden;
width:95%;
margin:40px auto 0 auto;
}
header .lower .line{
/*float:left;*/
display:inline-block;
background:#eaebeb;
width:35%;
height:8px;
/*display:block;*/
position:relative;
top:18px;
}
header .lower a{
/*float:left;*/
display:inline-block;
margin:0 20px;
/*display:block;*/
background: #000;
width: 141px;
height: 42px;
}
HTML
<header data-behavior="randomHeader">
<div class="lower">
<div class="line"></div>
Play Video
<div class="line"></div>
</div>
</header>
You have 3 column: left - fluid, middle - fixed, right - fluid. You would need some js to make it work.
Or some html/css trick like this:
<header data-behavior="randomHeader">
<div class="lower">
<div class="line"></div>
<div class="center">
Play Video
</div>
</div>
</header>
Css:
header .lower{
width:95%;
margin:40px auto 0 auto;
position: relative;
}
header .lower .line{
background:#eaebeb;
height:8px;
}
.center{
text-align: center;
position: absolute;
top: -20px;
left: 0;
width: 100%;
}
header .lower a{
border: 10px solid #FFF;
display:inline-block;
background: #000;
width: 141px;
height: 42px;
}
See working fiddle

Google Chrome: Text will not minimize correctly

Google Chrome is really throwing a roadblock at me and I need some help.
I am setting up a menu and the text is wrapping when zooming out (<50%). I do not want to use white-space: nowrap and I cannot make my menu wider. Safari, Firefox, even IE - no problems however when zooming out with chrome it forces a word wrap. Any ideas. Please let me know if more html/css is needed, i tried to simplify things:
CSS:
#page{
display: block;
overflow:visible;
font:"Times New Roman", Times, serif;
text-align: center;
margin: auto;
width: 100%;
height: 1000px;
background:#956e41;
}
#header{
width:auto;
max-width:1105px;
margin:auto;
position: relative;
overflow:visible;
}
#mainPicture{
height:475px;
width: 1105px;
background-image:url(images/main.jpg);
background-repeat:no-repeat;
margin: auto;
position: absolute;
}
#headerFrame{
height:80px;
margin: auto;
width: 1080px;
background-color: #a15535;
position: relative;
}
#logo{
height: 150px;
width: 340px;
margin: auto;
background-image:url(images/logo.png);
float: left;
}
#menuFrame{
width:auto;
max-width: 740px;
margin: auto;
width: 1080px;
display:inline-block;
}
#menu{
width:auto;
font-size:16px;
font-weight:600;
margin: 0 0 0 0 ;
text-align:right;
display:inline-block;
}
#menu ul{
margin-left: 80px;
}
#menu ul li{
list-style:none;
float:left;
margin: 0 0 0 10px;
padding: 0 10px 10px 0;
}
HTML:
<div id="page">
<div id="header">
<div id="mainPicture"></div>
<div id="headerFrame" class="borderSq">
<div id="logo">
<!--<img src="images/logo.png" />-->
</div>
<div id="menuFrame">
<div id="menu">
<ul>
<li class="border li">menu1<br /><span>text</span></li>
<li class="border li">THE menu1<br /><span>text</span></li>
<li class="border li">menu1<br /><span>text</span></li>
<li class="li">menu1<br /><span>text</span></li>
</ul>
</div>
</div>
</div>
</div>
</div>
Some of the CSS may look redundant, i lost my cool and started just throwing stuff at it... never good.
Demo: http://jsfiddle.net/X48ng/
^Open with chrome and zoom out.... you'll see (scroll right too for text)
John
Ok I think i see exactly what is causing it but its a bit of a fiddle with what you want from this,
After messing with the fiddle a bit I managed to stop the menu items being pushed to a new line when zooming out to 33% by removing the margin-left on the #menu ul{} item,
As shown here:
js Fiddle (still happens when zoomed out to 25% but now can zoom out to 33% instead of just 50%)
The only thing I can think of that is causing this is; as the page is resized the margin is being enlarged or something along those lines,
if anyone can help improve this answer, please do.
steve.