hide webpage element partially - html

My webpage has static navigation menu at top, but is lowered a bit and background is visible above it. When text in page is scrolled down it goes beneath menu and then is again visible above the menu. How can I hide the part of text which is above menu. Also the background will be an image.
If I place the text in <div> element below menu and set overflow:auto, scroll bar is then moved to the side of div element, not the page body as it is intended to be.
EDIT: Here is jsfiddle link http://jsfiddle.net/EmpireGlitch/N9xg2/
HTML:
<div class="topline">
<div class="menu">
<ul class="interpage_navigation">
<li>Choice 1
</li>
<li id="active_tab">Choice 2
</li>
</div>
<div id="top_seperator"></div>
</div>
<div class="article">
<h1>Lorem ipsum</h1>
<p>Lorem ipsum.</p>
</div>
CSS:
.menu .interpage_navigation li {
background-color: rgba(25, 102, 25, 0.8);
}
.side, #top_seperator, #active_tab {
background-color: rgba(50, 205, 50, 0.8);
}
.topline {
position: fixed;
top: 60px;
width: 100%;
}
#top_seperator {
height: 40px;
width: 100%;
clear: both;
}
.menu {
margin:0px;
margin-left:100px;
position: absolute;
bottom: 40px;
}
.menu > ul {
overflow: auto;
list-style-type: none;
padding:0px;
padding-left: 15px;
margin:0px;
//border: solid blue 1px;
}
.menu li {
float:left;
margin:0px;
}
.menu .interpage_navigation li {
width:120px;
height: 40px;
margin-right: 15px;
font-family: verdana, arial;
text-align: center;
line-height: 40px;
text-decoration: none;
text-transform: uppercase;
}
.article {
background-color: rgba(200, 200, 200, 1);
margin-bottom: 20px;
padding:20px;
padding-top: 5px;
font-size: 18px;
position: absolute;
top: 0px;
margin-top: 125px;
left: 30%;
right:15%;
z-index: -1;
}

I have used the :before pseudo element to create an element to place over the top of the page - http://jsfiddle.net/N9xg2/1/
The problem with this is that it is dependant on having a solid colour.
You may want to re-think how you're positioning the article - using position:absolute is going to really limit you.

My solution was similar to Richard's, except I just gave .menu a background (and tweaked its padding).
.menu {
margin:0px;
padding-left:100px;
position: absolute;
bottom: 40px;
background-color: white;
width: 100%;
padding-top: 20px;
}
Demo here
But I know you want to use an image background. You can solve that problem by using:
background-attachment: fixed;
Demo here

Related

How could I show my navigation bar over my body / section text?

My problem is when I scroll up, the text on the page goes through my navbar and it looks really unprofessional and I need to fix it. I want to make it so that my navigation bar is layered on top of my body / section text (body text includes navigation bar but section only includes text not on my nav bar),
I tried adding a background-color and that worked except when I used my dark / light mode switcher, I have css properties for dark mode and light mode but I can't use a background color otherwise when you switch, it will still show the background color for light mode (or whatever mode you were deigning for).
I also tried Z-Indexes since that is supposed to work but no, literally did nothing. Which was really weird. I wish I could elaborate more but that's all I can say, it just didn't work. Here is an example of what I did but I can't actually show you the exact code since I already deleted those Z-Indexes since they didn't work.
EXAMPLE NAV BAR CSS {
z-index: 100;
}
EXAMPLE SECTION / TEXT CSS {
z-index: -100;
}
Here's my navigation bar code:
<ul>
<div class="without-dark-ul">
<img class="logo" width="100px" src="\imgs\logo.png">
<h1 class="logo-side">[PRIVATE] Accounting</h1>
<h2 class="logo-side-slogan">The best, afforadable accounting.</h2>
<br>
<hr>
<h3 class="navbar-text">Navigation</h3>
<div class="navbar">
<li><a class="main-nav" href="#">Home</a></li>
<li>Pricing</li>
<li>Contact</li>
</div>
<div class="vl"></div>
<h3 class="dark-mode-text">Dark / Light Mode</h3>
</div>
<div class="ul-dark">
<li class="li-dark">
<span>Dark</span>
<span>Light</span>
</li>
</div>
</ul>
And here's my CSS for my navbar (and I've got some in navbar CSS and some in dark mode CSS, I honestly don't know why I did it like that though.)
/* START NAVBAR */
.logo-side {
margin-left: 140px;
margin-top: -95px;
font-size: 40px
font-
}
.logo-side-slogan {
margin-left: 140px;
margin-top: -30px;
}
.logo {
margin-top: 20px;
margin-left: 20px;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
position: fixed;
/* position: -webkit-sticky; Safari */
/* position: sticky; */
top: 0;
width: 100%;
z-index: 100;
}
ul > hr {
margin-left: 10px;
margin-right: 10px;
margin-top: -10px;
}
li {
float: left;
}
li a {
display: block;
text-align: center;
padding: 14px 16px;
text-decoration: none;
color: inherit;
}
li a:hover {
background-color: rgb(105, 103, 103);
}
.main-nav {
background-color: #383838;
color: white;
}
.navbar {
margin-left: 20px;
margin-top: 30px;
padding-bottom: 70px;
}
.navbar-text {
margin-left: 20px;
margin-bottom: -20px;
}
.navigation-bar {
background-color: #262626;
position: absolute;
}
/* END NAVBAR */
/* START DARK MODE */ (This includes some nav bar CSS properties.)
.li-dark {
list-style: none;
width: 100%;
height: 60px;
text-align: center;
text-transform: uppercase;
transition: 0.5s;
}
.ul-dark.active li {
transform: translateY(-30px);
}
ul li span {
display: block;
height: 30px;
line-height: 30px;
width: 100%;
}
ul li span:nth-child(1) {
background: #262626;
color: #fff;
}
.ul-dark {
position: static;
top: 20px;
right: 20px;
margin-top: 25px;
margin-left: 320px;
padding: 0;
width: 100px;
height: 30px;
border: 1px solid #000;
cursor: pointer;
overflow: hidden;
}
.dark-mode-text {
margin-left: 320px;
margin-top: -113px;
}
/* END DARK MODE */
I don't know if that is all you need but please ask me to send more code if you need more!
Thanks for your help.
Solninja A
give a position relative to body and your text parent
and z-index:10000;

Why don't my divs stack on browser resize?

I'm a newbie and trying to figure out how to stack these two boxes on top of each other when the browser gets resized. I don't want to use float, I'd rather stick to inline-block unless anyone else has strong suggestion against it. I was thinking I guess in using inline-block that the boxes would stack when the div got resized with the browser but it isn't happening. The boxes are just getting skinner and skinner and the text just wraps and exceeds the box. `
.cp2_maincontainer {
width: 100%;
height: 300px;
font-size: 0;
display: flex;
justify-content: space-between;
padding: 10px 50px 20px 50px;
}
.cp2_container {
width: 47%;
height: 100%;
background: no-repeat center;
display: inline-block;
position: relative;
}
.cp2_subcontainer {
background-color: rgba(211, 211, 211, .8);
height: 100%;
width: 100%;
padding: 10px 15px;
font-size: 16px;
font-family: playfair display;
position: absolute;
outline: solid 2px darkgrey;
outline-offset: -10px;
}
.cp2_subcontainer ul {
margin-left: 20px;
}
.cp2_subcontainer p {
margin: 10px;
}
.cp2_subcontainer h3 {
padding: 10px 0;
}
.cp2_container2 {
background-color: darkgrey;
background: no-repeat center;
width: 47%;
height: 100%;
display: inline-block;
position: relative;
}
.cp2_subcontainer2 {
background-color: rgba(211, 211, 211, 0.8);
height: 100%;
width: 100%;
padding: 10px 15px;
font-size: 16px;
font-family: playfair display;
position: absolute;
outline: solid 2px darkgrey;
outline-offset: -10px;
}
.cp2_subcontainer2 ul {
margin-left: 20px;
}
.cp2_subcontainer2 p {
margin: 10px;
}
.cp2_subcontainer2 h3 {
padding: 10px 0;
}
.addtextarea {
color: black;
padding: 10px;
width: 100%;
font-size: 16px;
text-align: justify;
}
<div class="cp2_maincontainer">
<div class="cp2_container" style="background-image:URL(<?php the_field('imageleft'); ?>)">
<div class="cp2_subcontainer">
<h3 style="text-align:center;">Title for Text Box 1</h3>
<p>Text in box # 1</p>
</div>
</div>
<div class="cp2_container2" style="background-image:URL(<?php the_field('imageright'); ?>)">
<div class="cp2_subcontainer2">
<h3 style="text-align:center;">Title for Text Box 2</h3>
<p>Text in box #2</p>
</div>
</div>
</div>
<div class="sectionbreak" align="center"></div>
You gave the divs a width in percentage. That means that as their container grows smaller, so do they, and they never have a reason to break. The obvious solution is to give them a fixed width (px, em).
If for some reason you need the percentages to work up to a certain point (for the purpose of bigger screens for example), two options come to mind:
Give the divs a min-width, so that once they hit that width the percentages will be ignored and the line will break.
Using media queries, define a different width for them based on screen size.
.cp2_maincontainer {
width:100%;
height:300px;
font-size: 0px;
display:flex;
justify-content: space-between;
padding: 10px 50px 20px 50px;
}
.cp2_container {
width:47%;
height:100%;
background: no-repeat center;
display:inline-block;
position: relative;
}
.cp2_subcontainer {
background-color: rgba(211, 211, 211, 0.8);
height:100%;
width:100%;
padding:10px 15px;
font-size:16px;
font-family: playfair display;
position: absolute;
outline:solid 2px darkgrey;
outline-offset: -10px;
}
.cp2_subcontainer ul{
margin-left:20px;
}
.cp2_subcontainer p{
margin:10px;
}
.cp2_subcontainer h3{
padding:10px 0px;
}
.cp2_container2 {
background-color: darkgrey;
background: no-repeat center;
width:47%;
display:inline-block;
position: relative;
min-width: 300px;
position: absolute;
right: 0;
height:300px;
}
.cp2_subcontainer2 {
background-color: rgba(211, 211, 211, 0.8);
height:100%;
width:100%;
padding:10px 15px;
font-size:16px;
font-family: playfair display;
position: absolute;
outline:solid 2px darkgrey;
outline-offset: -10px;
}
.cp2_subcontainer2 ul{
margin-left:20px;
}
.cp2_subcontainer2 p{
margin:10px;
}
.cp2_subcontainer2 h3{
padding:10px 0px;
}
.addtextarea {
color: black;
padding: 10px;
width: 100%;
font-size: 16px;
text-align: justify;
}
<div class="cp2_maincontainer">
<div class="cp2_container" style="background-image:URL(<?php the_field('imageleft'); ?>)">
<div class="cp2_subcontainer">
<h3 style="text-align:center;">Title for Text Box 1</h3>
<p>Text in box # 1</p>
</div>
</div>
<div class="cp2_container2" style="background-image:URL(<?php the_field('imageright'); ?>)">
<div class="cp2_subcontainer2">
<h3 style="text-align:center;">Title for Text Box 2</h3>
<p>Text in box #2</p>
</div>
</div>
</div>
<div class="sectionbreak" align="center">
</div>
I think this is what you are trying to accomplish.
I have added/edited the following on .cp2_container2
min-width: 300px;
position: absolute;
right: 0;
height:300px;
You need a min-width in order to have the 2 boxes overlap, otherwise they will always be half the width of the page and never overlap.
Positioning absolutely allows the div to freely pass over the statically positioned one.
Right just tells the div to position at the right edge of whatever it is relative to, in this case the body.
By positioning absolutely the height 100% becomes relative to the entire window, I have solved by using a pixel height, although you could also position the cp2_maincontainer relative and given it a height, making the height 100% of cp2_container2 relative the height of cp2_maincontainer.
Good luck.

how to make a fixed nav flush with the top of the window

I'm having some trouble with a fixed nav bar at the top of my page. It's supposed to be flush with the top of the page, but isn't. Here's my HTML:
<nav>
<a href="#">
<div id="logo">
lorem
</div></a>
</nav>
<ul>
*enough li's to go past the bottom of the screen*
</ul>
and my CSS:
body {
margin: 0px;
padding: 0px;
}
nav {
position: fixed;
display: block;
color: white;
margin: 0 auto;
padding: 0;
width: 100%;
height: 60px;
background-color: #4d4d4d;
}
#logo {
padding-left: 1%;
padding-right: 1%;
color: #75cc83;
width: 180px;
height: 100%;
background-color: #333333;
font-size: 3em;
font-family: candara, sans-serif;
}
It seems like there are only problems with the fixed nav once I put content in there (the list items, in this case)
Add top:0 to you nav's rules:
nav {
position: fixed;
display: block;
color: white;
margin: 0 auto;
padding: 0;
width: 100%;
height: 60px;
background-color: #4d4d4d;
top:0;
}
jsFiddle example

DIV not displaying at top of page

I've created a basic layout and on the page are 2 links, one register and one login button.
Take a look at my jsfiddle link to see how it looks. There's a black box which will be the logo and you will see the green and blue boxes which are my buttons.
I need them at the top of the page.
http://jsfiddle.net/4EZa5/
Not sure what I need to do to the CSS to make the links sit at the top of the very page?
HTML:
<div id="accountLinks">
<ul>
<li class="login">Log in</li>
<li class="register">Register</li>
</ul>
</div>
CSS:
#accountLinks{
float: right;
height:20px;
width: 170px;
margin: 0;
padding: 0;
}
#accountLinks ul{
list-style-type: none;
margin: 0;
padding: 0;
}
#accountLinks li{
float: left;
text-align: center;
}
#accountLinks .login{
background: url(../images/button_login.gif) no-repeat;
width: 70px;
height: 20px;
color: #FFF;
}
#accountLinks .register{
background: url(../images/button_register.gif) no-repeat;
width: 70px;
height: 20px;
color: #FFF;
}
Thanks
Your H1 tag is a block element and is pushing the rest down. Just add float: left; to h1 css
h1{
width: 351px;
height: 49px;
background: #000;
text-indent: -9999px;
float: left;
}
To style the link only in login:
#accountLinks .login a {
color: #FFF;
}
#accountLinks .login a:hover {
color: yellow;
}
They're being pushed down by the <h1>Salesboard</h1> - is it possible to move that to just after the accountLinks div, or does that need to stay before them in the HTML?
If so, then this should fix the accountLinks:
#accountLinks{
position: absolute;
top: 0px;
right: 0px;
height:20px;
width: 170px;
}
See this fiddle: http://jsfiddle.net/NZ2T5/
I added a style next to the id="accountLinks" this will be easier to position you div which contains the login etc..
<h1>Salesboard</h1>
<div id="accountLinks" style="margin-top:-45px;">
<ul>
<li class="login">Log in</li>
<li class="register">Register</li>
</ul>
</div>
Simply place h1 at the bottom of #header.
You couldn't see your links, because they were floating left! underneath your css-styled Salesboard
Additionally your text-intend (9999) is such that no text will be shown.
Solution
Newer browsers offer, the attribute fixed which will do exactly as it says.
Add this "position: fixed;"
#accountLinks{
position: fixed;
top: 0px;
right: 0px;
height:20px;
width: 170px;
}
#Container{
width:100%;
}

Lowering z-index causes descendant elements to become unclickable

I have a (CSS) stacking question.
The tab-boxes on my development site below have z-index set as -1 so that their border appears behind the tabs above them, so that the active tab's white bottom border covers it. But on all browsers but Opera this makes descendants of the tab-boxes (links, forms, etc.) unclickable. You can see this at:
http://od.philosofiles.com/
Can anyone help? Here's the bare bones of the HTML and CSS, though examining the link above with Firebug would probably be more illuminating:
<ul class="odtabs">
<li id="tab-Authors1" class="first active">Tab</li>
</ul>
<div id="tab_content-Authors1" class="odtab-content">
<p>Tab Box</p>
</div>
<style type="text/css">
<!--
.odtabs li {
float: left;
background-color: #ddd;
width: 80px;
height: 19px;
list-style-type: none;
}
.odtabs li.active {
background-color: white;
border-bottom-color: white;
}
.odtab-content {
border: 1px solid #babcbd;
margin-top: -1px;
clear: both;
position: relative;
top: -1px;
z-index: -1;
}
-->
</style>
Set z-index to -100.
.odtab-content {
border:1px solid #BABCBD;
clear:both;
font-size:0.9166em;
margin-top:-1px;
padding:0 1em;
position:relative;
top:-1px;
z-index:-100;
}
I finally fixed this myself, after a lot of experimentation with line-by-line reconstruction. I believe the problem was due to the z-index being negative; however, the only way to make it work with a positive z-index and a higher positive z-index was to set position: relative on the tabs, which required quite a different approach. (Apparently z-index only works on absolute, relative or fixed positioned elements.) Here, for those interested/with similar problems, is the full CSS I used:
ul.odtabs {
display: inline;
margin: 0;
padding: 0;
}
.odtabs li {
float: left;
background-color: #ddd;
border: 1px solid #babcbd;
width: 80px;
height: 19px;
margin-right: 2px;
text-align: center;
list-style-type: none;
position: relative;
z-index: 2;
}
.odtabs li.active {
background-color: white;
border-bottom-color: white;
}
.odtabs a {
color: #78797c;
font-size: 0.75em; /* 9px = 12*0.75 */
font-weight: bold;
margin-top: 0px;
padding-top: 0px;
}
.odtabs .last {
margin-right: 0px;
}
.odtab-content {
font-size: 0.9166em;
border: 1px solid #babcbd;
padding: 0px 1em; /* ie. 12px */
clear: both;
position: relative;
top: -1px;
z-index: 1;
}