I would like to have a social bar on the right, and scrolling with the page. This is ok, but I would like to add some behaviors: If you hover the facebook logo, the logo moves to the left, and shows the like button. And same behavior for twitter. I already made a jsfiddle, so here's the link: Demo here.
In the fiddle, at the moment my whole bar moves to the left, but I want the social buttons moving individually.
I am fine with JavaScript/jQuery, if necessary.
Here's my CSS and HTML code:
.off-canvas-buttons{
background-color:rgba(0,0,0,0.5);
top:10%;
height:auto;
right:55px;
width:100px;
text-align:center;
position:fixed;
line-height:50px;
transition:transform 1s ease;
}
.off-canvas-buttons > *, .off-canvas-buttons > * > *{
height:50px;
border:1px dashed red
}
.off-canvas-buttons:hover{
transform:translate(-55px);
}
.backtotop{
width:45px;
}
.facebook-logo, .twitter-logo{
background-color:rgba(200,0,0,0.5);
width:45px;
float:left;
}
<div class="off-canvas-buttons">
<div class="facebook">
<div class="facebook-logo">FB</div>
<div class="facebook-like">Like</div>
</div>
<div class="twitter">
<div class="twitter-logo">Twi</div>
<div class="twitter-follow">Follow</div>
</div>
<div class="backtotop">▲</div>
</div>
I've found what I wanted to (it was a CSS rule problem). Here is the updated fiddle: updated fiddle
Here is the code:
.cover {
right: 0;
height: 100%;
width: 110px;
background: red;
position: fixed;
}
.off-canvas-buttons {
top: 10%;
height: auto;
right: 55px;
width: 100px;
text-align: center;
position: fixed;
line-height: 50px;
}
.off-canvas-buttons > * {
height: 50px;
background-color: rgba(0, 0, 0, 0.4);
}
.social {
transition: transform 2s ease;
}
.off-canvas-buttons > .social:hover {
transform: translate(-55px);
}
.off-canvas-buttons > .social:hover >:first-child {} .backtotop {
width: 45px;
}
.facebook-logo,
.twitter-logo {
width: 45px;
float: left;
}
<div class="cover">
<div>
<div class="off-canvas-buttons">
<div class="facebook social">
<div class="facebook-logo logo">F</div>
<div class="facebook-like action">L</div>
</div>
<div class="twitter social">
<div class="twitter-logo logo">T</div>
<div class="twitter-follow action">S</div>
</div>
<div class="backtotop">▲</div>
</div>
Related
I have blog posts each with a cover image. I want to use these images in my post listing page as an experiment to see if it will liven up the page a little bit.
The images are too bright. I either want the opacity lowered or an overlay must be added.
Changing the opacity will change the opacity of the text. Adding an overlay has positioned itself on top of the anchors rendering them useless.
I am using the Gatsby Casper Starter Kit in the event that you are interested.
PostListing.jsx
...
<PostFormatting className={className} key={title} cover={cover}>
<PostHeader>
<h2 className="post-title">
<Link to={path}>{title}</Link>
</h2>
...
PostFormatting.jsx
...
const style = cover ? { backgroundImage: `url(${cover})` } : {};
return <article className={className} style={style}>{children}</article>;
...
Generated HTML
<article class="post" style="background-image: url("https://picsum.photos/1280/500/?image=800");">
<header class="post-header">
<h2 class="post-title">
Test Post
</h2>
</header>
<section class="post-meta">
<span>
<span class="tag">Mindset</span>
<span class="tag">Productivity</span>
</span>
<time class="post-date" datetime="2017-06-27">27 June 2017</time>
</section>
<section class="post-excerpt"><p>...</p></section>
</article>
CSS
All the styles I have for the post element.
<element.style> {
background-image: url(https://picsum.photos/1280/500/?image=800);
}
.home-template .content .post,
.tag-template .content .post {
background-color: rgba(0, 0, 0, .1);
padding: 30px 50px 50px 50px;
}
.post {
position: relative;
width: 80%;
max-width: 710px;
margin: 4rem auto 0em auto;
padding-bottom: 4rem;
border-bottom: #1a232c 3px solid;
word-wrap: break-word;
}
I know about this method but I don't know how to get the image into the after pseudo element.
div {
width: 200px;
height: 200px;
display: block;
position: relative;
}
div::after {
content: "";
background: url(image.jpg);
opacity: 0.5;
top: 0;
left: 0;
bottom: 0;
right: 0;
position: absolute;
z-index: -1;
}
Note: Try Radium for pseudo classes
U will have to put the overlay as a sibling of the content, and make it absolute.And also u will have to increase the z-index of the the content, so that it can be interactive.
In your case, all the elements inside the article should be grouped and put inside the content class.
Try this
.parent{
height:300px;
padding:50px;
position:relative;
}
.overlay{
position:absolute;
top:0;right:0;left:0;bottom:0;
background-color:rgba(0,0,0,0.5);
z-index:0;
}
.content{
position:relative;
z-index:1;
font-size:25px;
color:white;
}
<div class="parent" style="background-image:url(http://via.placeholder.com/350x150)">
<div class="overlay"></div>
<div class="content">Test Test</div>
</div>
I have a sidebar with a user profile picture (pink color). When the viewer hover on the image, a div (blue color) appears and it contains user details. Basically, I want an absolute positioned div appear next to its sibling.
It is functionally a popover, but I want to do it with pure CSS, is it possible?
I am using boostrap 4, it will be nice if the suggestion can co-exists with Bootstrap CSS. It will be awesome if the div can have an arrow associate with it.
My code is:
<div>
<div><figure class="figure"><img ... /></figure></div>
//css-popover
<div class="css-popover">User detail: ... bla bla bla ...</div>
</div>
I tried to search in Stackoverflow, most of the question is related to float div and makes it beside, but I want something absolute positioned, and display on top of the body.
Update:
Most of the suggestions provided fulfill part of the requests. The suggested .css-popover width and height are bounded by the parents, but I wish the popover dimension be independent from the parent, i.e. just "popup" and it doesn't "change" the layout beneath.
And when the popup appear, it doesn't change the parent height too. I wish the sidebar "icon" (light pink icons) stay in place whenever a popup appear.
If it is not possible with CSS, then I just go for JS solution...
You can try your luck here. https://jsfiddle.net/byanjiong/nohno2bd/13/
(Note: the user content is long, so it height usually will exceed the profile image's height)
Update 2:
Thanks to #Gezzasa, his solution is working. ^_^
Guy, this is the working example of pure CSS popover! Amazing!
https://jsfiddle.net/byanjiong/nohno2bd/15/
Thanks, guy...
https://jsfiddle.net/dqwtvf1g/3/
hover set on the parent and set the child to display: block;
You'll need to add the absolute position etc but this is how I've done it before.
.figure {background-color: #fff; width: 100px; height: 100px;}
.css-popover {display: none; width: 50px; height: 50px; background-color: #fff;}
.parent:hover .css-popover{display: block;}
UPDATE: Made the parent display: inline-block but you can always just add a width.
UPDATE2: I've added some css animation for you as well.
UPDATE3: Edited your fiddle https://jsfiddle.net/byanjiong/nohno2bd/15/
hi you can try something like this
html
<div class="container">
<div class="img-con">
<img src="https://images.google.com/images/branding/googleg/1x/googleg_standard_color_128dp.png" alt="" />
<div class="info-con">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ullam modi, distinctio nostrum reprehenderit explicabo amet exped
</div>
</div>
</div>
css
.img-con
{
height:150px;
width:150px;
position: relative;
}
.info-con
{
position: absolute;
top:0;
right:0;
background-color: #5C6BC0;
bottom:0;
left:0;
height:100%;
width:100%;
margin:auto;
transition:all ease 0.4s;
padding:3px;
opacity:0;
}
.info-con::after
{
content:"";
position: absolute;
left:-40px;
top:0;
bottom:0;
margin:auto;
height:0;
border:20px solid transparent;
border-right-color:#5C6BC0;
}
.img-con:hover .info-con
{
right:-110%;
left:auto;
opacity:1;
}
link for reference
This is one pure CSS solution.. But i recomend using JS
body {
margin: 0px;
}
.figure {
height: 20px;
width: 100px;
background: pink;
float: left;
margin: 0px;
}
.figure+.css-popover {
height: 50px;
width: 0px;
background: lightblue;
transition: all 0.3s ease;
float: left;
position: relative;
visibility: hidden;
left: 5px;
overflow: hidden;
padding: 10px;
}
.figure+.css-popover::before {
content: '';
display: inline-block;
height: 0px;
width: 0px;
border: 5px solid transparent;
border-right: 5px solid lightblue;
position: absolute;
top: 5px;
left: -10px;
}
.figure:hover+.css-popover,
.css-popover:hover {
width: 100px;
visibility: visible;
overflow: visible;
}
.clearfic,
.clearfix:after,
.clearfix:before {
content: "";
clear: both;
display: table;
}
<div class="clearfix">
<figure class="figure"></figure>
<div class="css-popover">User detail: ... bla bla bla ...</div>
</div>
<div>Some content</div>
EDIT : Added arrow
Change dimensions as per your need
.popover-container{
position: relative;
}
.css-popover{
position: absolute;
}
.css-popover {
background: #88b7d5;
border: 4px solid #c2e1f5;
}
.css-popover:after, .css-popover:before {
right: 100%;
top: 50%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
.css-popover:after {
border-color: rgba(136, 183, 213, 0);
border-right-color: #88b7d5;
border-width: 30px;
margin-top: -30px;
}
.css-popover:before {
border-color: rgba(194, 225, 245, 0);
border-right-color: #c2e1f5;
border-width: 36px;
margin-top: -36px;
}
<div>
<div class = "popover-container" ><figure class="figure"><img ... /></figure><div class="css-popover">User detail: ... bla bla bla ...</div></div>
</div>
1) With Pure css.
.wrap {
position: relative;;
}
.im {
width: 200px;
}
img {
width: 100%;
}
.css-popover{
display: none;
}
.im:hover + .css-popover {
display: block;
}
figure {
margin: 0;
}
<div class="wrap">
<div class="im">
<figure class="figure"><img src="http://www.mrwallpaper.com/wallpapers/cute-bunny-1600x900.jpg" /></figure>
</div>
<div class="css-popover">User detail: ... bla bla bla ...</div>
</div>
2) With Jquery
$(document).ready(function(){
$('.figure img').hover(function(){
$('.css-popover').css('display','block');
},function(){
$('.css-popover').css('display','none');
})
})
.css-popover {
display: none;
}
img {
width: 100px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div>
<div>
<figure class="figure"><img src="http://www.mrwallpaper.com/wallpapers/cute-bunny-1600x900.jpg" /></figure>
</div>
<div class="css-popover">User detail: ... bla bla bla ...</div>
</div>
I want to achieve this positioning using CSS :
But the best I obtain after days of tries is this :
Can you help me to achieve that positioning, taking into account :
the red comments in the "try" picture (see JSFiddle below) indicating some major constraints
that the positioning should work on IE8+, FF10+, Chrome, Opera, Safari (using CSSPie and selectivizr for IE8 compatibility)
Here is the JSFiddle and the code :
HTML
<body>body (all divs may have some padding, some margin and some border. All divs adjust their height to their content.)
<div id="globalcontainer"><span class="important">#globalcontainer (fixed width, not really centered into body : see center)</span>
<div id="header">#header (100%)</div>
<div id="middle">#middle (100%)
<div id="left">
<span class="important">#left (on the left of content, with a fixed min-width.<br>
<br>
Width adjusted to content if content > min-width. <br>
<br>
If left+right+center min-width > global container width, then still adjusts its size to its content and goes outside globalcontainer limits.<br>
<br>
Inner divs have variable (and unknown) width, sticked to the right)</span>
<br>
<DIV class="bloc" style="width:300px;">bloc</div>
<DIV class="bloc" style="width:50px;">bloc</div>
<DIV class="bloc" style="width:500px;">bloc</div>
</div>
<div id="center"><span class="important">#center (width adjusted to globalcontainer size - left size - right size, with a fixed min-width.<br>
<br>
Stays centered on the screen whatever the left or right size are<br>
--> if left or right divs are not present in the HTML (or present with display:none), center div stays on the center of the screen)</span>
<div id="center-middlerow">#center-middlerow (100%)
<div id="pageReceiver">#pageReceiver (100%)
<div id="page">#page (100%)<br>
<div id="pageHeader">#pageHeader (100%)</div>
<div id="pageContent">#pageContent (100%)</div>
</div>
<div id="tip" style="display: block;">#tip (under page)</div>
</div>
<div style="text-align:center" id="center-bottomrow">#center-bottomrow (100%)</div>
</div>
<div id="right"><span class="important">#right (on the right of content, with a fixed min-width.<br>
<br>
Width adjusted to content if content > min-width. <br>
<br>
If left+right+center min-width > global container width, then still adjusts its size to its content and goes outside globalcontainer limits.<br>
<br>
Inner divs have variable (and unknown) width, sticked to the right )</span>
<br>
<DIV class="bloc" style="width:30px;">bloc</div>
<DIV class="bloc" style="width:60px;">bloc</div>
<DIV class="bloc" style="width:90px;">bloc</div>
</div>
</div>
</div>
<div id="footer">#footer (100%)</div>
</div>
</body>
CSS
* {
font-family:Arial;
font-size:11px;
border:1px solid black;
padding:10px;
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
background-color:rgba(125,125,125,0.1);
}
span {
border:0px;
padding:0px;
background-color:transparent;
}
span.important {
color:red;
font-weight:bold;
}
html {
border:0px;
padding:0px;
background-color:white;
}
/* Real CSS starting here */
BODY {
padding:20px;
padding-bottom:0px;
}
#globalcontainer, #left, #center, #right , #header, #footer {
margin:auto;
background-color:transparent;
display:table;
}
/* ====================================================== */
#globalcontainer {
min-width:1130px;
max-width:1130px;
width:100%;
vertical-align:top;
}
#header {
margin-bottom:10px;
vertical-align:top;
width:100%;
}
#middle {
display: table;
vertical-align:top;
}
#footer {
margin-top:10px;
vertical-align:top;
text-align:center;
width:100%;
}
/* ====================================================== */
#left {
vertical-align:top;
float:left;
padding-right:20px;
}
#center {
vertical-align:top;
display: table-cell;
width:100%;
}
#center-toprow {
padding:10px;
padding-top:0px;
}
#center-middlerow {
}
#center-bottomrow {
padding:5px;
margin-top:30px;
}
#right {
vertical-align:top;
float:right;
padding-left:20px;
}
#left DIV.bloc {
float:right;
white-space:nowrap;
}
#right DIV.bloc {
float:left;
white-space:nowrap;
}
/* ====================================================== */
#pageReceiver {
margin:auto;
width:100%;
}
#page {
cursor:default;
background-color:#F8F8F8;
border:1px solid black;
padding:20px;
width:100%;
position:relative;
min-height:591px;
}
#pageHeader {
margin:auto;
margin-bottom:15px;
display: -moz-inline-stack;
display: inline-block;
*display: inline;
}
#tip {
margin-top:5px;
margin-left:20px;
margin-right:20px;
padding:5px;
background-color:transparent;
-webkit-border-radius: 0px;
-moz-border-radius: 0px;
border-radius: 0px;
}
Going with the border-box box model is the right way to go.
Here is a structure I often use : demo
It uses some wrapper divs with position: relative; and custom padding, containing absolutely positioned elements with height: 100%; and overflow :auto;.
It needs tweaking but you'll get the gist.
HTML
<div id="globalcontainer">
<div id="global-wrapper">
<div id="header"></div>
<div id="middle">
<div id="middle-wrapper">
<div id="left">
<div class="bloc"></div>
<div class="bloc"></div>
<div class="bloc"></div>
</div>
<div id="center-wrapper">
<div id="center">
<div id="center-middlerow"></div>
<div id="center-bottomrow"></div>
</div>
</div>
<div id="right">
<div class="bloc"></div>
<div class="bloc"></div>
<div class="bloc"></div>
</div>
</div>
</div>
<div id="footer"></div>
</div>
</div>
CSS
*,
*:before,
*:after{
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
}
div{
border: 1px solid black;
padding: 10px;
}
html,
body{
height: 100%;
}
#globalcontainer{
height: 100%;
}
#global-wrapper{
padding: 100px 10px;
position: relative;
border: none;
height: 100%;
}
#header,
#footer{
position: absolute;
width: 100%;
height: 100px;
left: 0;
}
#header{
top: 0;
}
#middle{
height: 100%;
}
#middle-wrapper{
position: relative;
padding: 0px 200px;
border: none;
height: 100%;
}
#left,
#right{
position: absolute;
width: 200px;
height: 100%;
top: 0;
background:#F0F0F0;
overflow: auto;
}
#left{
left: 0;
}
#right{
right: 0;
}
#center{
height: 100%;
}
#center-wrapper{
border: none;
padding: 0px 10px;
height: 100%;
}
.block{
background: #fff;
}
For such a complex layout, along with border-box you also will need to carefully tweak the dimensions for the desired look.
Check this fiddle: http://jsfiddle.net/SXJuT/ (hope it looks like your screenshot)
Full screen: http://jsfiddle.net/SXJuT/embedded/result/
CSS:
html, body { margin:0; padding: 0; height: 100%; width: 100%; overflow: hidden; font-size: 9px; }
div { border: 1px solid blue; box-sizing: border-box; padding: 2px; margin: 4px; }
#globalcontainer { width: 99%; height: 98%; background-color: #deebf7; }
#header { height: 5%; background-color: #d1e4f3; }
#middle { height: 86%; background-color: #d1e4f3; display: table; border-spacing: 4px; width: 99%; }
#footer { height: 5%; background-color: #d1e4f3; }
#left, #center, #right { display: table-cell; background-color: #c4ddf1; }
#left { width: 14%; }
#center { width: 68%; }
#right { width: 14%; }
#center-middlerow { height: 80%; background-color: #bad5eb; }
#center-bottomrow { height: 20%; background-color: #bad5eb; }
#pageReceiver { height: 78%; background-color: #b1d0ec; }
#tip { height: 16%; background-color: #b1d0ec; }
#page { height: 95%; background-color: #a7cbe9; }
#pageHeader { height: 14%; background-color: #2e75b5; }
#pageContent { height: 62%; background-color: #2e75b5; }
#pageFooter { height: 14%; background-color: #2e75b5; }
.bloc { height: 20%; background-color: #2e75b5; }
#left > .bloc:nth-child(1), #right > .bloc:nth-child(1) { width: 50%; }
#left > .bloc:nth-child(2), #right > .bloc:nth-child(2) { width: 70%; }
I´ve got a problem with position:absolute in FF. I´ve got a bar with a width of 100% and two bars with a static width on the left and right side.
I need to do set the inner Bar to 100% to make it responsive. It looks bad when I give percentage-values to the borders.
In Chrome and even IE!!! it´s working fine but Firefox adds both short bars to the right side (like on the picture).
HTML:
<div id="wrapper">
<div class="row-fluid">
<div class="span12">
<div id="slider">
<button class="scrllbtn">〈</button>
<div id="sliderFrame">
<div id="innerSlider">
<button class="videoButton">▶</button>
<button class="videoButton">▶</button>
<button class="videoButton">▶</button>
<button class="videoButton">▶</button>
</div>
</div>
<button class="scrllbtn">〉</button>
</div>
<div id="videos"></div>
</div>
</div>
</div>
Styles:
#wrapper
{
width: 960px;
margin: 0 auto;
border: solid 1px red;
}
#slider {
padding-top: 0.4em;
clear:left;
width:100%;
height: 160px;
display:block;
}
#sliderFrame {
width:100%;
height:160px;
overflow-x: hidden;
overflow-y:hidden;
float:left;
border-top: solid 1px #043860;
border-bottom: solid 1px #043860;
}
#innerSlider {
width:950px;
height:200px;
clear:none;
}
.scrllbtn {
position: absolute;
height:162px;
width: 20px;
}
.scrllbtn:first-child {
clear:left !important;
}
.scrllbtn:last-child {
margin-left: -20px;
float:right;
}
.scrllbtn:focus {
outline: none;
}
.videoButton {
float:left;
width:200px;
height:160px;
}
Fiddle
Any suggestetions how I could solve that problem?
somthing like this :)
demo
<div class="main">
<div class="left"></div>
<div class="right"></div>
</div>
.main {
position: absolute;
width: 100%;
height: 500px;
background: red;
}
.right {
position: absolute;
top: 0;
right: 0;
background: orange;
width: 100px;
height: 500px;
}
.left {
position: absolute;
top: 0;
left: 0;
background: gray;
width: 100px;
height: 500px;
}
Adding the following rule makes it work in my copy of Firefox:
.scrllbtn:first-child {
left: 0;
}
Fiddle
fix problem in your example :)
demo
<button class="scrllbtn scrllbtnleft">〈</button>
<button class="scrllbtn scrllbtnright">〉</button>
.scrllbtnleft {
left: 0;
}
.scrllbtnright {
right: 0;
}
Why adding of left rule changes behavior so drastically? Is it possible to position relative to default position?
http://jsfiddle.net/suzancioc/drDn3/6/
HTML:
<div class='level0'>
<div class='level1'>
Hello
</div>
<div class='level1'>
Hello
<div id='inner2'>inner2</div>
</div>
<div class='level1'>
Hello
<div id='inner3'>inner3</div>
</div>
</div>
CSS:
.level0 {
height:40px;
width: 500px;
background:red;
}
.level1 {
float:left;
margin:2px;
border-style: solid;
background: cyan;
}
#inner1 {
position: absolute;
background: green;
}
#inner2 {
position: absolute;
background: green;
left:0px;
}
#inner3 {
position: absolute;
background: green;
}
In order to position absolute something you need to assign that div(in your case) to a relative positioned parent
.level1 {
float:left;
margin:2px;
border-style: solid;
background: cyan;
position:relative;
}
Adding position:relative makes .level1 a sort of coordinate system for all elements inside of it.
Take a look at this JSFIDDLE