I'm trying to create a vertical bullet navigator for a website with parallax scrolling. Unfortunately the redirect of the nav isn't working.
here's the jsfiddle: http://jsfiddle.net/r1yq7pLd/
Scrolling seems ok but the anchor doesn't work. Anyone knows the reason?
html:
<div id="wrapper">
<section id="main_bg" data-type="background" data-speed="10">
</section>
<section class="content" data-type="text">
<article>I am absolute positioned</article>
</section>
<nav>
<ul>
<li>•</li>
<li>•</li>
<li>•</li>
<li>•</li>
<li>•</li>
<li>•</li>
</ul>
</nav>
</div>
css:
body{
background-color:#1599D0;
}
#wrapper{
width:100%;
height: 1000px;
}
nav{
top: 35%;
position: fixed;
right: 50px;
width: 30px;
border-left: double rgba(255,255,255,0.4);
border-right: double rgba(255,255,255,0.4);
}
ul li a{
color: rgba(255,255,255,0.4);
font-size: 30px;
text-decoration: none;
text-indent: -9999px;
padding: 0 10px;
}
#main_bg{
background: url("../img/wall_index1.jpg") repeat fixed;
/* Set rules to fill background */
min-height: 100%;
background-size:cover;
/* Set up proportionate scaling */
width: 100%;
/* Set up positioning */
position: relative;
}
.content{
position:relative;
width: 100%;
background-color:#000;
padding: 200px;
font-size: 50px;
color: #FFF;
height: 500px;
}
Note: the menu here is a bit messy due absence of reset.css. Is it possible to insert it in jsfiddle?
It's not to do with the CSS you're using, it's because you've not set your anchors properly. Pag2 and Top are should be set as ids, with the navigation using href to link back to them - you have both set as href. Also, you don't need to actually set separate anchors anymore, you can just use ids within your existing elements. Finally, exclude the hash from the id itself, that's just to tell the link to look for an anchor rather than a new page.
Your html should be:
<div id="wrapper">
<section id="main_bg" data-type="background" data-speed="10"></section>
<section class="content" data-type="text">
<article id="pag2">I am absolute positioned</article>
</section>
<nav>
<ul>
<li>Top</li>
<li>Page 2</li>
<li>...other links</li>
<li>...other links</li>
<li>...other links</li>
</ul>
</nav>
</div>
There's no need for separate top anchor, "#" will always go to the top of the current page.
Incidentally, I'm not sure why you've got bullets within your list - by default, an unordered list (<ul>) will put bullets in for you, so I've replaced your link text with something more meaningful.
Related
Absolutely positioned element's width constrained when parent is relative
I have a navbar that has a menu on hover. The menu will contain tags and the length of the text in the tags will vary.
I want the menu to have a minimum and maxmium width child div has to have min-width/max-width set to. But no matter what the width of the menu is constrained to the min-width point.
Is it possible to make the child div ignore the width of the parent, while still keeping it a child (I cannot move this out of the parent, which I know would be an easy solution)?
here is an example of the behavior I am encountering: https://codepen.io/vee1234/pen/omQxWP
.navBar {
background-color: #222;
width: 50px;
min-height: 100%;
height: 100vh;
}
.navItem {
color: #a1a1a1;
padding-top: 15px;
padding-bottom: 15px;
position: relative;
}
.menu {
font-family: "Open Sans", sans-serif;
position: absolute;
display: none;
min-width: 200px;
max-width: 600px;
background-color: #333;
z-index: 100;
left: 100%;
top: 20%;
}
.menu div a {
display:block;
border: 1px solid red;
}
.navItem:hover .menu {
display: block;
}
<div class="navBar">
<div class="navItem">
<div>Nav Menu Trigger</div>
<div class="menu">
<div class="link">
<a>string of any length</a>
<a>string of any length - but this one is super long</a>
</div>
</div>
</div>
<div class="navItem">
<div>Nav Menu Trigger</div>
<div class="menu">
<div class="link">
<a>string of any length</a>
<a>string of any length - but this one is super long</a>
</div>
</div>
</div>
<div class="navItem">
<div>Nav Menu Trigger</div>
<div className="menu">
<div className="link">
<a>string of any length</a>
<a>string of any length - but this one is super long</a>
</div>
</div>
</div>
</div>
One trick is to make the relative element to be bigger by adding some padding-right that will not affect how text goes inside but will be counted in the width calculation of the absolute element. Then simply color only the part you want. You may also add negative margin to rectify the padding added.
.menu {
width:50px;
padding-right:500px;
margin-right:-500px;
background:#000 content-box;
height:100px;
position:relative;
color:#fff;
}
.menu div{
position:absolute;
top:0;
left:50px;
background:blue;
min-width:200px;
max-width:500px;
}
.menu div a {
border:1px solid;
display:block;
}
<div class="menu">
some text here
<div>
<a>some text here</a>
<a>some text here some text here some text here some text here some text here some text here some text here some text here</a>
<a>some text here</a>
</div>
</div>
Absolute positioning takes the element out of where it actually sits in the DOM and positions it where you tell it to. Because of this, the element looses references to parent elements that would help determine the width. You will need to set the width explicitly.
I'm not sure what the issue here is, but its frustrating the hell out of me. I have a header div, for the logo and links, a wrapper div for the main section, and then a footer. width is set to 100% for all, but for some reason there is an overflow of white space spilling over on the right side and on the bottom. And it does this funky thing where if I move my mouse to the white space below the footer the contact link in my header is selected!
Theirs a fair bit of html and css so I decided to just link you guys to a jfiddle, it will be easier to just show you the problem in action. notice how you can scroll to the right and there is white space, even though the wrapper has background color set to grey, header has background set to white, and footer has background set to grey. all have 100% widths as well.
There is even white space coming in below the footer for some reason.
I hope all this makes sense and thanks for your help. I'm sure its something silly and obvious but I'm still kind of new to this!
http://jsfiddle.net/46andtool/Q2d4K/2/
heres the main div css
/*body element*/
body {font-size: 100%; line-height: 1; max-width: 100%; font-family: 'Source Sans Pro', sans-serif; }
/*contains #main and #footer*/
#wrapper { width:100%; background-color:grey; border: none;}
#main { width:100%; margin: 0 auto; border: none;}/*main body of website, wrapped inside of the wrapper div*/
/*div that contains the banner and navigation*/
.header {width: 100%; margin: 0 auto; background-color: #FFFFFF; padding-bottom: 10px; margin-bottom: 10px;}
/*Logo*/
#banner {float: left; max-width: 100%; margin: 0; padding: 0;}
/*navigation*/
#w { max-width: 100%; background-color: #FFFFFF; margin: 0; padding: 0; }
and the html:
<body>
<div class="header">
<img id="banner" src="img/******.png" alt="*******">
<div id="w">
<nav>
<ul id="ddmenu">
<li>About
<ul>
<li>Our Mission</li>
<li>The Staff</li>
<li>History</li>
</ul>
</li>
<li>Services
<ul>
<li>*****</li>
<li>******</li>
<li>******</li>
</ul>
</li>
<li>Links
<ul>
<li>China</li>
<li>Japan</li>
<li>Canada</li>
<li>Australia</li>
<li>South America</li>
</ul>
</li>
<li>Contact Us</li>
</ul>
</nav>
</div>
</div>
<div id="wrapper">
<div id="main">
<div id="innermain">
<h1>Latest News and Events</h1>
<h2>Welcome to !</h2>
<p>gsfdgdfgsdfgsdfg
</p>
<div id="linebreak"></div>
<p>gfdhgdfhfgh</p>
<br>
<p>hgdhfghgfh</p>
<br>
<p>gdhfgdhfghfgh</p>
<br>
</div>
<div id="rightside">
<h1>Where To Find Us</h1>
<div id="buildingpic"></div>
<div id="map_canvas"></div>
<p id="location">sadfasdfsadsdf<br> asdfsdfa<br> asdfdsfds<br> 555-3423</p>
</div>
</div>
</div>
<div id="footer">
Site design by <a class ="links" href="example#yahoo.com">fsgfdg</a></a> © <?php echo date('Y');?> All Rights Reserved
</div>
</body>
There are a couple things causing issues here.
Your body automatically comes with a margin, so it's going to overflow if you don't specifically set the margin:0px;
Your #footer had a width:100%; but it also had padding:10px. Those are combined, so you had width:100% + 10px of padding. Try to do something like what I provided, which is width:94%; and padding:10px 3%; so your width becomes 94% + 3% + 3% = 100%
Lastly, your #buildingpic element had width:300px which in this case was wider than the container it was in. You would be better off making it width:100% and height:auto; to automatically constraint to the proportions of it's container. In this case I set the max-width:100%;
http://jsfiddle.net/Q2d4K/4/
Also, you're going to have a hell of a time if you always use IDs. Try to use classes for elements so you can re-use them if need be, or at least not have issues with duplication or priority of selection.
Alright this never works when I need to setup two divs (one floating and fixed width) and another div with margin to the size of floating div width.
I tried clear: both, and some other work arounds. Nothing being successful. Is there an overall better way to do this?
HTML:
<div class="usercpwrap">
<ul class="usercptabs">
<li>Account</li>
<li>Friends</li>
<li>Messaging</li>
<li>Reputation</li>
</ul>
<div class="usercpcont">
Ajax load page content from: /usercp/{page}.php
goes here.
</div>
</div>
CSS:
.usercptabs{
float: left;
position: relative;
width: 225px;
margin: 0;
padding: 0;
clear: both;
list-style-type: none;
border-right: 1px solid blue;
}
.usercptabs li{
height: 40px;
line-height: 40px;
padding-left: 10px;
border-bottom: 1px solid blue;
}
.usercptabs li:last-child{
border-bottom: none;
}
.usercpcont{
margin-left: 225px;
}
Try:
.usercpwrap{overflow:hidden;}
DEMO here.
OR:
Clear float.
<div class="usercpwrap">
<ul class="usercptabs">
<li>Account</li>
<li>Friends</li>
<li>Messaging</li>
<li>Reputation</li>
</ul>
<div class="usercpcont">Ajax load page content from: /usercp/{page}.php goes here.</div>
<div class="clr"></div>
</div>
CSS:
.clr{clear:both;}
DEMO here.
only to double the margin because it overrides the exact length of that floating div
.usercpcont{
margin-left: 550px;
}
give clear:both; after usercpcont DIV
<div class="usercpwrap">
<ul class="usercptabs">
<li>Account</li>
<li>Friends</li>
<li>Messaging</li>
<li>Reputation</li>
</ul>
<div class="usercpcont"> Ajax load page content from: /usercp/{page}.php
goes here. </div>
<div style="clear:both;"></div>
</div>
working fine.
I have a div where the elements need to be centered:
<div style="width:800px;margin:0 auto;color:#000;"><h3 style="float:left;color:#000;margin:0 10px;"> Test </h3><h4 style="float:left;padding-top:3px;"> | </h4><h3 style="color:#000;float:left;margin:0 10px;"> Test </h3></div>
However, the elements all just stay to the left. How do I fix this and center all the h3's and h4's?
Here is my example: http://approvemyride.ca/reno/
http://jsfiddle.net/ZeJdc/
HTML:
<div>
<h3> Test </h3>
<h4> | </h4>
<h3> Test </h3>
</div>
CSS:
div {
width: 800px;
margin: 0 auto;
color: #000;
text-align: center;
}
h3 {
color: #000;
margin: 0 10px;
display: inline-block;
}
h4 {
padding-top: 3px;
display: inline-block;
}
Check that out and let me know what you think, if it doesn't look centered when you first open it try stretching the little divider to the left to give the results pane more room.
To clarify, display:inline-block is what's allowing all the headers to be displayed on the same line while text-align:center is what's centering all of your header elements inside the <div>.
Whenever I face any floated container to center horizontally I use the followings. Try wrapping your markup (which needs to be centered; the div in your case) with these:
<div class="center_outer">
<div class="center_inner">
<!-- Put your contents here (which needs to be centered) -->
</div>
</div>
CSS:
.center_outer
{
position: relative;
left: 50%;
float: left;
}
.center_inner
{
position: relative;
left: -50%;
}
Check: http://jsfiddle.net/jduDD/1/ (I have removed the width style)
Hi im trying to set some divs inline and i dont know what else to do.
.menuboton{
display:inline;
padding:0.7em;
border-radius: 4px;
background-color: #093;
}
.menu{
display:inline;
margin-right:4em;
}
There are two classes, first are 4 divs and the another is one div with an <img> inside. Those divs are inside another div:
#elmenu{
margin:auto;
margin-bottom:10px;
width:100%;
border-top:1px solid black;
border-bottom:1px solid black;
}
This is my problem: the 4 divs always are slightly below the one with the <img> inside and cross over the container div (elmenu). For fix that I tried setting it display:inline-block and fix the problem of exceds the container limit but still below the one with <img> inside.
Here the html code:
<div id="elmenu">
<div class="menu" id="logo"><img id="imglogo" src="psds/logo.png" /></div>
<div class="menuboton">Inicio</div>
<div class="menuboton">Posts</div>
<div class="menuboton">Login</div>
<div class="menuboton">Usuario</div>
</div>
Pics:
Using display:inline;
Using display:inline-block;
I want all divs stay at the same level!
Some guess?
Place the Knowit image in left and the menu in right and edit widths accordingly.
HTML:
<div class='container'>
<div class='left'></div>
<div class='right'></div>
</div>
CSS:
.container { overflow: hidden; margin:0; padding:0; }
.left{ float: left; width: 150px; }
.right { float: right; width: 150px; text-align:left; }
Edit on OP request:
To center object within div class use:
text-align:center;
to center align the div container use:
margin: 0 auto;
All this information can be found at http://w3schools.com/
You should try to use span instead of div. Also use float:left
vertical-align: middle on #elmenu should do the trick along with display: inline-block; on the logo and menu items.
first you should build your menu from a list or a nav tag.
Inline-block is a good idea, you can easily size and align your elements.
To build your menu you need:
inline-boxes
text-align:center.
line-height
float (just once)
First element (holding logo for instance) can float left.
set a line-height to size (min-)height of the nav bar.
here we come to this : http://jsfiddle.net/GCyrillus/CaR7a/
.menuboton {
display:inline-block;
padding:0.7em;
border-radius: 4px;
background-color: #093;
line-height:1.2em;
}
.menu {
float: left;/* logo */
}
#elmenu {
padding:0;
margin:0;
list-style-type:none;
line-height:48px;/* logo's height */
text-align:center;
border-top:1px solid black;
border-bottom:1px solid black;
}
a {
color:white;
text-decoration:none;
}
<ul id="elmenu">
<li class="menu" id="logo"><img id="imglogo" src="http://placehold.it/1&1" /></li>
<li class="menuboton">Inicio</li>
<li class="menuboton">Posts</li>
<li class="menuboton">Login</li>
<li class="menuboton">Usuario</li>
</ul>
I hope it is useful
Like my comment, the Css should like this
.menuboton{
float: left;
padding:0.7em;
border-radius: 4px;
background-color: #093;
}
.menu{
float: left;
margin-right:4em;
}
UPDATE:
HTML:
<div id="elmenu">
<div class="menu" id="logo"><img id="imglogo" src="http://www.winphoneviet.com/forum/data/avatars/l/35/35914.jpg?1370081753" /></div>
<div class="menuboton">Inicio</div>
<div class="menuboton">Posts</div>
<div class="menuboton">Login</div>
<div class="menuboton">Usuario</div>
<div style="clear: both;"></div>
</div>
This's Fiddle