JavaScript edit CSS style position value - position

EDIT: Basically working code
My goal is to have my logo above the navigation bar of my website but when I scroll down the logo should disappear and the nav bar should stay fixed at the top.
Example Website which has this: w3schools
I implemented a go back up button according to the tutorial here in order to see if js works and it does.
Here is my code: jsfiddle. I have modified the js from the go back up example but it doesn't work.
In this code snippet I get an error that I don't know but the same js works in the "go back up button" example.
var amountScrolled = 100;
var navbar = document.getElementById('navbar-eff');
$(window).scroll(function() {
if ( $(window).scrollTop() > amountScrolled ) {
navbar.style.position = "fixed";
} else {
navbar.style.position = "relative";
}
});
ul.navbar {
position: relative
z-index:99999;
top:0;
width: 100%;
list-style-type: none;
margin: 0;
overflow: hidden;
background-color: #333;
font-size: 100%;
padding: 0 0 0 0;
}
ul.navbar li {
float:left;
padding-left: 0.5em;
padding-right: 0.5em;
}
ul.navbar li a {
display: block;
color: white;
text-align: center;
padding: 0.25em 0.25em;
text-decoration: none;
border-bottom: none;
padding-left: 0;
}
<div id="wrapper">
<div id="logo">
<h1>
my logo
</h1>
</div>
<ul class="navbar" id="navbar-eff" style="">
<li> Home</li>
<li> Hello World</li>
<li> About Me</li>
</ul>
</div>
<header>
<p> Lorem <br>ipsum <br>dolor<br> sit<br> amet<br>, consectetur<br> adipiscing<br> elit,<br> sed<br> do<br> eiusmod <br>tempor<br> incididunt<br> ut<br> labore<br> et<br> dolore<br> magna<br> aliqua<br>. Ut<br> enim<br> ad<br> minim<br> veniam,<br> quis <br>nostrud<br> exercitation<br> ullamco<br> laboris<br> nisi<br> ut<br> aliquip<br> ex<br> ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. </p>
</header>

Related

position floating div under selection within viewport window

How do you position a floating div (i.e. position:absolute, e.g. dialog box) under text that has been selected while still showing the whole div within the viewport window even if the selection is at the edge?
This solution using jQuery works for me. Please see codePen or below:
Javascript:
const floater = $('<div class="floater"><div>^</div>You selected:<div class="selection">...</div></div>')
.appendTo('body').show();
$('#selectable').on('mouseup', function (e) {
const
selected = window.getSelection().toString(),
half_floater_width = floater.width()/2,
x = e.pageX;
if ( selected ) {
let win_w = document.documentElement.clientWidth
floater.find('.selection').html(selected)
if ( half_floater_width + x > win_w ) floater.css({left:'auto', right:0 , top:e.pageY + 8})
else if( x - half_floater_width < 0 ) floater.css({left:0 , right:'auto', top:e.pageY + 8})
else floater.css( {left: x - half_floater_width, right:'auto', top:e.pageY + 8})
}
})
Html:
<div id="selectable">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Dolores mollitia amet laboriosam impedit aliquam, veniam
officiis porro quibusdam, expedita eligendi incidunt, rerum praesentium provident minus laborum. Deserunt illum non
</div>
CSS:
.floater {
position: absolute;
top: 50px;
left: 50px;
width: 150px;
height: 150px;
background-color: #efefef;
border: 2px solid red;
z-index:1;
padding:20px;
font-size: 1.5em;
text-align: center;
resize: both;
overflow:auto;
}

Fluid 2-col layout issues. inline-block elements overhanging the edge of the container

I'm trying to use 2 column fluid layout in my footer.
The right side column in the footer has a list of inline-bock elements - social icons. This works well until you start to re-size the width of the browser. At one point the social icons start to overhang the background of the footer.
This is how it looks when viewport is of normal size:
Problem shows when viewport gets smaller:
I've tried to simplify this down as much as possible in this fiddle. Notice how those links start to overhang when viewport is re-sized.
I would like that background of the footer to contain those links entirely
http://jsfiddle.net/ambidexterous/xwugnyh1/1/
css:
.l-columns {
vertical-align: top;
}
.l-columns:before,
.l-columns:after {
content: " ";
display: table;
}
.l-columns:after {
clear: both;
}
.l-columns {
*zoom: 1;
}
.l-columns-85 {
width: 85%;
}
.l-columns-15 {
width: 15%;
}
.l-columns-left {
float: left;
}
.l-columns-right {
float: right;
}
footer {
background-color: #002A54;
}
.l-horizontal-inline-list li{
list-style-type: none;
display: inline-block;
}
.l-horizontal-inline-list li a{
margin: 5px;
}
html:
<header>
<h1>HEADER</h1>
<header>
<article>
luptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum qui
</article>
<footer>
<div class="l-columns">
<div class="l-columns-85 l-columns-left">
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
<div class="l-columns-15 l-columns-right">
<ul class="social l-horizontal-inline-list">
<li>
alfa
</li>
<li>
beta
</li>
<li>
gamma
</li>
<li>
charlie
</li>
</ul>
</div>
</div>
</footer>
The reason this is happening is that ul li lists always have left margin even if you set list-style-type: none;
you could restyle this adding
ul {
list-style-type: none;
padding: 0px;
margin: 0px;
}
ul li {
background-position: 0px center;
}
here's a fiddle
Interesting, I've never seen :before and :after used to insert a table pseudo-element.
Add display: table-cell; to these classes:
.l-columns-85 {
width: 85%;
display: table-cell;
}
.l-columns-15 {
width: 15%;
display: table-cell;
}
You can then remove this CSS:
.l-columns-left {
float: left;
}
.l-columns-right {
float: right;
}
Working Fiddle

Text disappear in gradient

I would like the text to disappear in a gradient, like in the image I link to below, and on hover the gradient would disappear.
What I want:
http://s7.postimg.org/59m1vxfwr/screen.png
The best thing would be if I could use the background gradient in CSS, but I have no idea have to get it 'above' the text.
Heres a jsfiddle to what I have right now, with a gradient (yellow for now, but I want white) thats under everything.
http://jsfiddle.net/RxLfV/1/
HTML:
<section class="thework">
<a href="<?php the_permalink(); ?>">
<div class="thetitle">
Test 1
</div>
<div class="thedescription">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
</div>
</a>
</section>
<section class="thework">
<a href="<?php the_permalink(); ?>">
<div class="thetitle">
Test 2
</div>
<div class="thedescription">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy.
</div>
</a>
</section>
<section class="thework">
<a href="<?php the_permalink(); ?>">
<div class="thetitle">
Test 3
</div>
<div class="thedescription">
Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
</div>
</a>
</section>
CSS:
.thework a {
width: 100%;
float: left;
display: block;
font-size: 1em;
font-family: sans-serif;
color: black;
background: -moz-linear-gradient(top, rgba(255,242,0,0) 0%, rgba(255,242,0,1) 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(255,242,0,0)), color-stop(100%,rgba(255,242,0,1)));
background: -webkit-linear-gradient(top, rgba(255,242,0,0) 0%,rgba(255,242,0,1) 100%);
background: -o-linear-gradient(top, rgba(255,242,0,0) 0%,rgba(255,242,0,1) 100%);
background: -ms-linear-gradient(top, rgba(255,242,0,0) 0%,rgba(255,242,0,1) 100%);
background: linear-gradient(to bottom, rgba(255,242,0,0) 0%,rgba(255,242,0,1) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00fff200', endColorstr='#fff200',GradientType=0 );
}
.thework a:hover {
background: none;
}
.thetitle {
width: 25%;
left: 25%;
margin-top: 2em;
margin-bottom: 2em;
float: left;
position: relative;
}
.thedescription {
width: 50%;
left: 25%;
margin-top: 2em;
margin-bottom: 2em;
float: left;
position: relative;
}
Does anybody know how to get it above?
A image would work also, as long as it align in the bottom – the text will be of different heights.
Thanks in advance!
You could overlay a div on top of your current div. The overlay div would contain the gradient background.
DEMO http://jsfiddle.net/kevinPHPkevin/6k3vV/54/
.fadeout {
position: absolute;
bottom: 0em;
width:100%;
height: 4em;
background: -webkit-linear-gradient(
rgba(255, 255, 255, 0) 0%,
rgba(255, 255, 255, 1) 100%
);
background-image: -moz-linear-gradient(
rgba(255, 255, 255, 0) 0%,
rgba(255, 255, 255, 1) 100%
);
background-image: -o-linear-gradient(
rgba(255, 255, 255, 0) 0%,
rgba(255, 255, 255, 1) 100%
);
background-image: linear-gradient(
rgba(255, 255, 255, 0) 0%,
rgba(255, 255, 255, 1) 100%
);
background-image: -ms-linear-gradient(
rgba(255, 255, 255, 0) 0%,
rgba(255, 255, 255, 1) 100%
);
}
section {position:relative}

bubble text not coming with on mouseover in anchor tag

I was trying to popup the bubble text, for that I have codded below, the code when the mouse over the help anchor tag that bubble text should be popup, but it is not working for me please help me on the same.
Here is my code snippet.
**HTML Code:**
<div class="divbubble"> <div class="tooltip">
Help
<div>
<div class="top"></div>
<div>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
</div>
<div class="bottom"></div>
</div>
</div></div>
**CSS code:**
.divbubble .tooltip {
width: 18px;
height: 18px;
position: relative;
margin-left: 15px;
float: left;
}
.divbubble .tooltip a {
display: block;
float: left;
width: 18px;
height: 18px;
background: url(images/icoQuestion.png) no-repeat;
font: 0/0 serif;
text-shadow: none;
color: transparent;
-webkit-transition: none;
-moz-transition: none;
-ms-transition: none;
-o-transition: none;
transition: none;
}
.divbubble .tooltip a:hover {
background-position: 0 -18px;
}
.divbubble .tooltip > div {
display: none;
position: absolute;
float: left;
width: 220px;
bottom: 22px;
left: -101px;
font-size: 12px;
line-height: 18px;
color: #fff;
z-index: 20;
}
.divbubble .tooltip > div .top {
background: url(images/tooltipTop.png) no-repeat;
width: 220px;
height: 10px;
}
.divbubble .tooltip > div div {
display: block;
background: #4599c3;
width: 200px;
padding: 0 10px;
}
.divbubble .tooltip > div .bottom {
background: url(images/tooltipBottom.png) no-repeat;
width: 220px;
height: 21px;
}

CSS MultiLined Gradient Text. -webkit-background-clip

I am using CSS to generate a gradient on my text... The problem is my text is multi-lined so the gradient doesn't reset on each line... the whole paragraph becomes 1 huge gradient! Can I get an individual gradient effect for each line of text in my divider? Here is my code:
<html>
<head>
<style type='text/css'>p.p1 {
margin: 0.0px 0.0px 0.0px 50.0px;
font: 50.0px Helvitica;
font-family: 'HelveticaNeue-Light', 'Helvetica Neue Light', 'Helvetica Neue', 'Helvetica, Arial', 'Lucida Grande', 'sans-serif';
background: -webkit-gradient(linear, left top, left bottom, from(#eee), to(#333));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
</style>
</head>
<body bgcolor='#FFFFFF'>
<div style='word-wrap: break-word;'>
<p class='p1'>
<font face='helvetica' color='#000000'>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi id vestibulum lectus. Maecenas facilisis orci vitae urna pulvinar cursus. Etiam id laoreet metus. Cras vitae elit ipsum. Donec a sagittis nisi. Sed nec nisi nibh, fringilla fermentum quam. Vestibulum lorem felis, gravida et faucibus ac, ultrices nec lectus.
</font>
</p>
</div>
</body>
</html>
I got rid of the deprecated tags and cleaned the code up for you..
p.p1 {
margin: 0 0 0 50px;
font-size: 50px;
font-family: 'HelveticaNeue-Light', 'Helvetica Neue Light', 'Helvetica Neue', 'Helvetica, Arial', 'Lucida Grande', 'sans-serif';
background: -webkit-repeating-linear-gradient(top, red 0px, blue 60px);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
Demo

Resources