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;
}
I'm trying to put overlay on top of showcase image and putting back texts on image on top of overlay using z-index, but z-index: 1 is not working. Position absolute is added and then z-index:1 to create overlay effect but nothing is happening. Can someone check, what's going on here?
I have set position absolute and given its top ,left position for overlay
<!DOCTYPE html>
<html>
<head>
<title>My website2</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<header>
<div class="container">
<h2 > <span class="coral">Acme</span> Web Design</h2>
<nav>
<ul class="my-list">
<li >
<a class="coral" href="#"> HOME</a>
</li>
<li>
ABOUT
</li>
<li>
SERVICES
</li>
</ul>
</nav>
</div>
</header>
<section id="showcase">
<div class="container">
<h2>Lorem ipsum dolor sit amet consectetur
</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing
</p>
</div>
</section>
</body>
</html>
.container{
width:80%;
margin: auto;
overflow: hidden;
}
header{
background-color: #35424a;
color: #fff;
min-height: 45px;
padding-top: 20px;
border-bottom: 3px solid coral;
}
header ul{
margin:0;
padding:0;
}
header li{
display: inline;
list-style: none;
padding:0 15px 0 15px ;
}
header h2{
float: left;
}
header nav{
float:right;
}
header h2{
margin: 0;
}
.coral{
color:coral;
}
#showcase{
background-image: url("images/showcase2.jpg");
background-position: center right;
min-height: 300px;
text-align: center;
color: #fff;
}
#showcase::after {
content: "";
position: absolute;
top:68px;
left:0;
width: 100%;
min-height:300px;
background-color: rgba(78, 89, 107, 0.6);
}
#showcase {
z-index:1;
}
It got solved now. Z-index need to be added on container class which contains h2 and p tags.
#showcase{
position: relative;
background-image:url("images/showcase.jpg") ;
background-size:cover;
background-repeat: no-repeat;
background-position: center right;
min-height: 300px;
text-align: center;
color: #fff;
font-weight: bold;
display: flex;
align-items: center;
justify-content: center;
}
#showcase::after {
content: "";
position: absolute;
top:0;
left:0;
width: 100%;
min-height:300px;
background-color: rgba(78, 89, 107, 0.8);
}
.container{
z-index: 10;
}
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>
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}
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;
}