Get button to hover over image - html

Hi guys i am trying to get my button in bootstrap 3 to overlap my image, i understand the use of z-index 1 but i cant seem to get it to work at all.
HTML:
.btn-warning {
color: #fff;
background-color: rgba(255, 198, 0, 0.9);
border: 0;
padding: 20px;
border-radius: 26px;
line-height: 0.428571;
}
.aboutpic {
margin-bottom: 19px;
}
<div class="aboutpic">
<img src="//via.placeholder.com/350x150" class="img-responsive">
<button type="button" class="btn btn-warning">Download CV</button>
</div>

Try this:
.btn-warning {
color: #fff;
background-color: rgba(255,198,0,0.9);
border: 0;
padding: 20px;
border-radius: 26px;
line-height: 0.428571;
position: absolute;
z-index: 1;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
You'll need to add a position: absolute; and a z-index: 1 to the button so that it can sit on top of the image.
codepen.io/lauraeddy/pen/KXEwOW

You can set the position of aboutpic to relative and the button to absolute, as in the following example.
UPDATE
Added style attributes to center the button over an arbitrarily sized image, using calc(50% - [button width or button height]).
.btn-warning {
color: #fff;
background-color: rgba(255, 198, 0, 0.9);
border: 0;
padding: 20px;
border-radius: 26px;
line-height: 0.428571;
width: 120px;
height: 50px;
}
.aboutpic button {
position: absolute;
top: calc(50% - 25px);
left: calc(50% - 60px);
}
.aboutpic {
margin-bottom: 19px;
position: relative;
width: 350px;
height: 150px;
}
<div class="aboutpic">
<img src="http://via.placeholder.com/350x150" class="img-responsive">
<button type="button" class="btn btn-warning">Download CV</button>
</div>

Please try the following,
.btn-warning {
color: #fff;
background-color: rgba(255,198,0,0.9);
border: 0;
padding: 20px;
border-radius: 26px;
line-height: 0.428571;
}
img{
height:200px;
width:200px;
}
.aboutpic{
position:relative;
}
.first{
position:absolute;
z-index:1;
}
.second{
position:absolute;
z-index:2;
left:20px;
top:50px;
}
<div class="aboutpic">
<div class="first">
<img src="https://static.pexels.com/photos/377911/pexels-photo-377911.jpeg" class="img-responsive">
</div>
<div class="second">
<button type="button" class="btn btn-warning">Download CV</button>
</div>
</div>
Hope this helps.

Related

Rotated text on left border of responsive div

I am facing issue making text around the borders of a div, with dynamic content/images.
Here is html code:
<div class="fp-wrapper">
<a href="/url1">
<img class="fp-image" src="image1.jpg">
</a>
<p class="fp-title1">Text on top border</p>
<p class="fp-title2">Text on left border</p>
</div>
css:
.fp-wrapper {
position: relative;
display: inline-block;
margin: auto;
}
.fp-image {
width: 80%;
float:left;
padding: 10px;
border: 1px solid #53565a;
z-index: 1;
}
.fp-title1, .fp-title2{
padding: 0 10px;
background: #fff;
position: absolute;
top: 0;
left: 30px;
color: #53565a;
text-transform: uppercase;
font-weight: 500;
}
.fp-title2 {
bottom: 50%;
top: unset !important;
transform: translate(-50%,-50%) rotate(-90deg);
}
Fiddle: https://jsfiddle.net/wutzbvef/
Now the problem is that the content is dynamic, so min-height/max-height or negative margins won't work (I think so). Also I need to make it responsive, covering the border. Is this approach correct or need to make it by some other approach. Please help.
Edit:
I may not explained better, but I basically want to vertical align top the -90deg rotated paragraph i.e. .fp-title2
Use transform-origin
.fp-wrapper {
position: relative;
display: inline-block;
margin-left: 50px;
}
.fp-image {
width: 100%;
padding: 10px;
border: 1px solid #53565a;
z-index: 1;
}
.fp-title1,
.fp-title2 {
padding: 0 10px;
background: #fff;
position: absolute;
top: 0;
left: 30px;
color: #53565a;
text-transform: uppercase;
font-weight: 500;
}
.fp-title2 {
transform: translate(-100%, 0%) rotate(-90deg);
transform-origin: right center;
}
.w2 .fp-image {
width: 80%;
}
.w3 .fp-image {
width: 60%;
}
<div class="fp-wrapper">
<a href="/url1">
<img class="fp-image" src="https://i.ibb.co/y6XYb0z/image1.jpg">
</a>
<p class="fp-title1">Text on top border</p>
<p class="fp-title2">Text on left border</p>
</div>
<div class="fp-wrapper w2">
<a href="/url1">
<img class="fp-image" src="https://i.ibb.co/y6XYb0z/image1.jpg">
</a>
<p class="fp-title1">Text on top border</p>
<p class="fp-title2">Text on left border</p>
</div>
<div class="fp-wrapper w3">
<a href="/url1">
<img class="fp-image" src="https://i.ibb.co/y6XYb0z/image1.jpg">
</a>
<p class="fp-title1">Text on top border</p>
<p class="fp-title2">Text on left border</p>
</div>
Try rotating first, then re-center the div. Otherwise it's ok.
transform: rotate(-90deg) translate(-50%, -50%);
You can also use a variable font-size for smaller images.
(I would also use an :after class for this btw), use the a tag, like this:
.fp-wrapper {
}
.fp-wrapper a {
width: 40%;
display:inline-block;
position: relative;
z-index:1;
float:left;
padding: 10px;
border: 1px solid #53565a;
}
.fp-image {
width: 100%;
}
.fp-wrapper a:before{
position: absolute;
content:'text top';
padding: 0 10px;
background: #fff;
display:inline-block;
top: 0px;
left: 50%;
transform: translateX(-50%);
color: #53565a;
text-transform: uppercase;
font-weight: 500;
z-index:20;
}
.fp-wrapper a:after {
position:absolute;
content:"left text";
display:inline-block;
text-transform: uppercase;
font-weight: 500;
padding: 0 10px;
top:50%;
transform: translateX(-50%) rotate(-90deg);
left:10px;
z-index:10;
background-color:#fff;
}
<div class="fp-wrapper">
<a href="/url1">
<img class="fp-image" src="https://i.ibb.co/y6XYb0z/image1.jpg">
</a>
</div>
<div class="fp-wrapper">
<a href="/url1" style="width:30%;">
<img class="fp-image" src="https://i.ibb.co/y6XYb0z/image1.jpg">
</a>
</div>

Best practice for an animated image gallery with CSS

I'm trying to do a photo gallery. I have this code:
<head>
<style>
.thumb {
max-height: 171px;
border: solid 6px rgba(5, 5, 5, 0.8);
}
.box {
position: fixed;
z-index: 999;
height: 0;
width: 0;
text-align: center;
top: 0;
left: 0;
background: rgba(0, 0, 0, 0.8);
opacity: 0;
}
.box img {
max-width: 90%;
max-height: 80%;
margin-top: 2%;
}
.box:target {
outline: none;
width: 100%;
height: 100%;
opacity: 1;
}
.box:target img {
border: solid 17px rgba(77, 77, 77, 0.8);
}
.light-btn {
color: #fafafa;
background-color: #333;
border: solid 3px #777;
padding: 5px 15px;
border-radius: 1px;
text-decoration: none;
cursor: pointer;
vertical-align: middle;
position: absolute;
top: 45%;
z-index: 99;
}
.light-btn:hover {
background-color: #111;
}
.btn-close {
position: absolute;
right: 2%;
top: 2%;
color: #fafafa;
background-color: #92001d;
padding: 10px 15px;
border-radius: 1px;
text-decoration: none;
}
.btn-close:hover {
background-color: #740404;
}
</style>
</head>
<body>
<img class="thumb" src="https://images.unsplash.com/photo-1556742521-9713bf272865?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80">
<img class="thumb" src="https://images.unsplash.com/photo-1562657548-fcab42b43035?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=332&q=80">
<img class="thumb" src="https://images.unsplash.com/photo-1564249332652-bf435bb2d21f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=353&q=80">
<div class="box" id="img1">
prev
X
<img src="https://images.unsplash.com/photo-1556742521-9713bf272865?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80">
next
</div>
<div class="box" id="img2">
prev
X
<img src="https://images.unsplash.com/photo-1562657548-fcab42b43035?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=332&q=80">
next
</div>
<div class="box" id="img3">
prev
X
<img src="https://images.unsplash.com/photo-1564249332652-bf435bb2d21f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=353&q=80">
next
</div>
</body>
But I want to add animation. I want the photos to come from the left when I click on "next" and from the right when I click on "prev", like a slider.
Is it possible to achieve it with CSS? For example with transform property? If not what script should I use?
You can do something like this with radio buttons. If you have a radio button at the top for each transition you want to make, you can use CSS to select on every radio button there is and add the CSS transitions as needed. Use <label>s instead of <a>s to check the radio buttons, and then make the actual radio buttons invisible. But this would take a lot of code and wouldn't scale very well. So if you plan on having more images, you have to add CSS for each on individually, which can be a lot of work.
Here is a quick example putting the images into a reel and sliding the whole thing side to side. It may not be exactly what you want, but it is much less code. It's at least a good starting place.
<head>
<style>
.thumb {
max-height: 171px;
border: solid 6px rgba(5, 5, 5, 0.8);
}
.reel-wrapper {
position: fixed;
z-index: 999;
height: 0;
width: 0;
text-align: center;
top: 0;
left: 0;
background: rgba(0, 0, 0, 0.8);
opacity: 0;
overflow: hidden;
}
.reel {
position: absolute;
width: auto;
height: auto;
display: flex;
transition: left 1s ease-in-out;
}
#radio-close:not(:checked) ~ .reel-wrapper {
outline: none;
width: 100%;
height: 100%;
opacity: 1;
}
.box {
position: relative;
width: 100vw;
height: 100vh;
}
.box img {
max-width: 90%;
max-height: 80%;
margin-top: 2%;
border: solid 17px rgba(77, 77, 77, 0.8);
}
input[type="radio"] {
display: none;
}
#radio-img1:checked ~ .reel-wrapper .reel {
left: 0;
}
#radio-img2:checked ~ .reel-wrapper .reel {
left: -100vw;
}
#radio-img3:checked ~ .reel-wrapper .reel {
left: -200vw;
}
.light-btn {
color: #fafafa;
background-color: #333;
border: solid 3px #777;
padding: 5px 15px;
border-radius: 1px;
text-decoration: none;
cursor: pointer;
vertical-align: middle;
position: absolute;
top: 45vh;
z-index: 99;
}
.light-btn:hover {
background-color: #111;
}
.btn-close {
position: absolute;
right: 2%;
top: 2%;
color: #fafafa;
background-color: #92001d;
padding: 10px 15px;
border-radius: 1px;
text-decoration: none;
}
.btn-close:hover {
background-color: #740404;
}
.btn-prev {
left: 5vw;
}
.btn-next {
right: 5vw;
}
</style>
</head>
<body>
<input id="radio-close" type="radio" name="gallery-nav" checked>
<input id="radio-img1" type="radio" name="gallery-nav">
<input id="radio-img2" type="radio" name="gallery-nav">
<input id="radio-img3" type="radio" name="gallery-nav">
<label for="radio-img1"><img class="thumb" src="https://images.unsplash.com/photo-1556742521-9713bf272865?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80"></label>
<label for="radio-img2"><img class="thumb" src="https://images.unsplash.com/photo-1562657548-fcab42b43035?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=332&q=80"></label>
<label for="radio-img3"><img class="thumb" src="https://images.unsplash.com/photo-1564249332652-bf435bb2d21f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=353&q=80"></label>
<div class="reel-wrapper">
<div class="reel">
<div class="box" id="img1">
<label for="radio-img3" class="light-btn btn-prev">prev</label>
<label for="radio-close" class="btn-close">X</label>
<img src="https://images.unsplash.com/photo-1556742521-9713bf272865?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80">
<label for="radio-img2" class="light-btn btn-next">next</label>
</div>
<div class="box" id="img2">
<label for="radio-img1" class="light-btn btn-prev">prev</label>
<label for="radio-close" class="btn-close">X</label>
<img src="https://images.unsplash.com/photo-1562657548-fcab42b43035?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=332&q=80">
<label for="radio-img3" class="light-btn btn-next">next</label>
</div>
<div class="box" id="img3">
<label for="radio-img2" class="light-btn btn-prev">prev</label>
<label for="radio-close" class="btn-close">X</label>
<img src="https://images.unsplash.com/photo-1564249332652-bf435bb2d21f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=353&q=80">
<label for="radio-img1" class="light-btn btn-next">next</label>
</div>
</div>
</div>
</body>
Typically this kind of thing would be easier to do with JavaScript. You could just keep track of which image you are looking at, and then on clicking a button toggle the right classes to make CSS do the actual animation. It is much easier to manage for scale. But pure CSS solutions are always more fun.

CSS increase opacity of nested span tag

I have some text within a div that I do not want the opacity to affect; I want the text to be 100% fully opaque but the background color to be 50% opaque.
So far I have been unsuccessful.
HTML:
<div class='photo'>
<div class='image'><a href='#'><img src='https://i.imgur.com/PC68FSTb.jpg' alt='profile picture' width='300' height='300'></a></div>
<div class='photo-name'><span>Name</span></div>
</div>
CSS:
.photo {
border-radius: 6px;
border: 1px solid #ccc;
width: 298px;
height: 298px;
margin-top: 10px;
margin-left: 10px;
float: left;
overflow: hidden;
position: relative;
}
.photo-name {
position: absolute;
bottom: 30px;
width: 100%;
padding: 0.5em;
text-align: center;
background-color: #666666;
color: #fff;
opacity: 0.5;
}
.photo-name > span {
opacity: 1;
}
Result: https://jsfiddle.net/w71677jm/
You can use RGBA color
.photo-name {
position: absolute;
bottom: 30px;
width: 100%;
padding: 0.5em;
text-align: center;
/*background-color: #666666;*/
background-color:rgba(102,102,102,0.5);
color: #fff;
/*opacity: 0.5;*/
}
Ok Robert. How's this.
The solution is
rgba(102,102,102, 0.5);
rgba = red,green,blue,alpa channel
(102,102,102) = #666666
0.5 = your 50% transparent
Check out the SO Snippet below or this forked fiddle JSFiddle
Hope this helps!
Best,
Tim
.photo-name {
position: absolute;
bottom: 175px;
width: 300px;
text-align: center;
background-color: rgba(102,102,102, 0.5);
color: #fff;
padding-top:.5em;
padding-bottom:.5em;
}
<div class='photo'>
<div class='image'>
<a href='#'>
<img src='https://i.imgur.com/PC68FSTb.jpg' alt='profile picture' width='300' height='300'>
</a>
</div>
<div class='photo-name'>
<span>Name</span>
</div>
</div>

corner ribbon for resposive image

I am trying to make a corner ribbon to sit over an image, on a responsive design site. I have set up a fiddle page with the code I've got so far. As you can see there, it seems to insert a top margin (the corner of the ribbon is not disappearing) and the overflow is not hidden. Any ideas why?
JSfiddle
.ribbon-holder {
overflow: hidden;
}
.ribbon {
position: relative;
background: yellow;
color: black;
transform: rotate(-45deg);
text-align: center;
top: 52px;
left: -32px;
width: 145px;
}
<div class="ribbon-holder">
<div class="ribbon ribbon-holder">Free Shipping!</div>
<a href="http://www.somesite.com">
<img src="http://www.adventurouskate.com/wp-content/uploads/2016/01/planes-black-shower-curtain.jpg" alt="Shower Curtin" />
</a>
</div>
use position:relative in the parent (.ribbon-holder) and absolute in the child (.ribbon)
.ribbon-holder {
overflow: hidden;
position: relative
}
.ribbon {
position: absolute;
background: yellow;
color: black;
transform: rotate(-45deg);
text-align: center;
top: 32px;
left: -32px;
width: 145px;
}
<div class="ribbon-holder">
<div class="ribbon ribbon-holder">Free Shipping!</div>
<a href="http://www.somesite.com">
<img src="http://www.adventurouskate.com/wp-content/uploads/2016/01/planes-black-shower-curtain.jpg" alt="Shower Curtin" />
</a>
</div>
How about this:
html:
<div class="ribbon-holder" >
<a href="http://www.somesite.com" ><img itemprop="image" class="imageSize" src="http://www.adventurouskate.com/wp-content/uploads/2016/01/planes-black-shower-curtain.jpg" alt="Shower Curtin" /></a>
</div>
<div class="ribbon ribbon-holder">
Free Shipping!
</div>
css:
.ribbon-holder{
overflow: hidden;
}
.ribbon{
position: absolute;
background: yellow;
color: black;
transform: rotate(-45deg);
text-align: center;
top: 30px;
left: -32px;
width:145px;
}
https://jsfiddle.net/L4kojc4k/2/
Here are the changes i made :
.ribbon-holder{
overflow: hidden;
position: relative;// added by DamienBannerot
}
.ribbon{
position: absolute;// added by DamienBannerot
background: yellow;
color: black;
transform: rotate(-45deg);
text-align: center;
top: 32px;// added by DamienBannerot
left: -32px;// added by DamienBannerot
width:145px;
}
fiddle here : https://jsfiddle.net/L4kojc4k/4/

How to center a button right in the middle of two divs, but a z-index order higher?

I'm having issues implementing the following design:
My specific problem is the blue button in the center, and subsequently the arrow in the middle of it.
I currently have two elements:
<div id="hero">
<!-- this is where the black background is -->
</div>
<div id="content">
<!-- This is the white background -->
</div>
Now somehow, I have to put that blue button right in the middle of the hero and the rest of the content, and on top of that, there has to be an arrow in the middle of that button and the button.
I don't know where to start doing this. I'm assuming the button needs to have a z-index higher than the hero and the content, and the arrow has to have a z-index higher than the blue button.
But in what part of the HTML document do I write the tags in? For example:
<div id="hero">
<!-- This is the black background -->
</div>
<button type="button" class="cta">Button Tex bla bla</button>
<button type="button" class="arrow"><img src="..."></button>
<div id="content">
<!-- This is the white background -->
</div>
I'm using Bootstrap for the grid.
With the combination of position and margin you can position the elements the way you want:
#container{
position: relative;
border: 1px solid black;
}
#hero{
height: 150px;
background-color: black;
color: white;
text-align: center;
padding-top: 30px;
}
#hero span{
max-width: 300px;
display: block;
margin: 0 auto;
font-size: 30px;
}
#content{
height: 200px;
background-color: white;
color: black;
text-align: center;
font-size: 15px;
padding-top: 80px;
}
#content span{
max-width: 300px;
display: block;
margin: 0 auto;
font-size: 25px;
}
.cta{
position: absolute;
width: 200px;
height: 50px;
left: 50%;
margin-left: -100px;
margin-top: -25px;
background-color: #2196F3;
border: none;
color: white;
}
.arrow{
position: absolute;
border: none;
left: 50%;
width: 30px;
height: 30px;
margin-left: -15px;
margin-top: 10px;
background-color: black;
color: white;
border-radius: 50%;
}
<div id="container">
<div id="hero">
<span>hero headline so cool buy now</span>
</div>
<button type="button" class="cta">Button Tex bla bla</button>
<button type="button" class="arrow">V</button>
<div id="content">
<span>give me more money</span>
</div>
</div>
I would use style tag relative position and offset the top by half of the buttons length. And yes use the z-index to place it on top.
<div id="hero">
<!-- This is the black background -->
</div>
<button type="button" class="cta" style="position:relative; top: -20px;">Button Tex bla bla</button>
<button type="button" class="arrow" style="position:relative; top: -20px;"><img src="..."></button>
<div id="content">
<!-- This is the white background -->
</div>
here you can do
.cta{
position:relative;
background: #3498db;
background-image: -webkit-linear-gradient(top, #3498db, #2980b9);
background-image: -moz-linear-gradient(top, #3498db, #2980b9);
background-image: -ms-linear-gradient(top, #3498db, #2980b9);
background-image: -o-linear-gradient(top, #3498db, #2980b9);
background-image: linear-gradient(to bottom, #3498db, #2980b9);
-webkit-border-radius: 0;
-moz-border-radius: 0;
border-radius: 0px;
font-family: Arial;
color: #ffffff;
font-size: 24px;
padding: 10px 40px 10px 40px;
text-decoration: none;
}
.arrow{
position: absolute;
left: 110px;
top: 20px;
}
<div id="hero">
<!-- This is the black background -->
</div>
<button type="button" class="cta">
Button Tex bla bla
<a href="#" class="arrow">
<img src="http://files.softicons.com/download/toolbar-icons/super-mono-sticker-icons-by-double-j-design/png/64/arrow-down.png">
</a>
</button>
<div id="content">
<!-- This is the white background -->
</div>
use position:relative; on parent element and position:absolute; on child element
Here is my try :) - JSFiddle
I am basically wrapping the buttons in an absolute div button-wrapper ( absolute to the Hero ) then I just center its content using text-align:center
<div id="hero">
<h1>My Title</h1>
<div class="button-wrapper">
<button type="button" class="blue cta">Button Tex bla bla</button>
<button type="button" class="arrow"><span>↓</span>
</button>
</div>
</div>
<div id="content">
<!-- This is the white background -->
</div>
#hero {
background:#000;
height: 300px;
text-align:center;
}
h1 {
color:white;
padding: 50px;
}
button {
display: block;
position: relative;
margin: 0 auto;
}
.button-wrapper {
position: absolute;
bottom: 0;
right: 0;
left: 0;
margin: auto;
text-align: center;
}
#content {
background-color:yellow;
height:500px;
z-index:10;
}
.blue {
background: #0185CB;
color:#fff;
}
.cta {
border: 0;
font-size: 25px;
padding: 15px;
-webkit-transform: rotate(-358deg) scale(1) skew(0deg) translate(0px);
-moz-transform: rotate(-358deg) scale(1) skew(0deg) translate(0px);
-o-transform: rotate(-358deg) scale(1) skew(0deg) translate(0px);
-ms-transform: rotate(-358deg) scale(1) skew(0deg) translate(0px);
}
.arrow {
background: #000;
border-radius: 50%;
width: 50px;
height: 50px;
border-color: transparent;
color: #fff;
font-weight: bold;
font-size: 25px;
line-height: 25px;
text-align: center;
margin-top: -20px;
}
.arrow > span {
position: absolute;
left: 0;
right: 0;
top: 50%;
transform: translateY(-50%);
}
Are the two buttons doing the same thing? If yes, you should use only one button.
You can try this since you are using bootstrap:
HTML
<div id="content">
//container fluid will always have full width of its parent
<div class="container-fluid" id="my-button-wrapper">
//you create a row in order to manage the div inside
<div class="row">
//create a column as wide as you want and push it to center it
<div class="col-sm-8 col-sm-push-2">
//then you add the button
<button type="button" class="my-button-class">Button text</button>
</div>
</div>
</div>
</div>
CSS
#my-button-wrapper {
margin-top: -20px;
}
//give the position relative in order to position the arrow at its center
.my-button-class {
background: #000;
position: relative;
}
//this will add an element after the button content
.my-button-class:after {
position: absolute;
width: 30px;
height: 30px;
bottom: -15px;
left: 50%;
margin-left: -15px;
background-image: url('your-image-url');
content: "";
}
Of course width and height of my element are just for example, you should use your own sizes or bootstrap's ones.