Here's my JS fiddle: https://jsfiddle.net/aeh8hxys/
Can somebody please tell me why (and how to stop!) the pattern overlaps my button? Thanks!
CSS:
.pattern
{
width:500px;
height:300px;
background-color: #FF0000;
}
.pattern:after {
background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiAoV2luZG93cykiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6MkRGNDcyQ0Y4ODQ4MTFFNEFFRjVERDUwMjZBRDgzNUYiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6MkRGNDcyRDA4ODQ4MTFFNEFFRjVERDUwMjZBRDgzNUYiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDoyREY0NzJDRDg4NDgxMUU0QUVGNURENTAyNkFEODM1RiIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDoyREY0NzJDRTg4NDgxMUU0QUVGNURENTAyNkFEODM1RiIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PtWxVHsAAABESURBVHjahI9BDgAgCMO0///zjBcDZk6OpIF2Shpm9nLWBQFSAuulBpPeVZgANZgPdGCcuAvEibtAnLgL5FV5uy8BBgBvsBUQrZ/GBQAAAABJRU5ErkJggg==") repeat;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
content: "\0020";
opacity: .5;
z-index: 0;
}
and HTML:
<div class="pattern">
<button class="btn btn-info">This is a button</button>
</div>
Because the pattern is "positioned" (a position value other than static), and has a z-index, which means it will appear over the button, which is non-positioned and has no z-index.
To make the button appear over the pattern, give it a position other than static and a z-index higher than pattern.
https://jsfiddle.net/aeh8hxys/1/
.pattern
{
width:500px;
height:300px;
background-color: #FF0000;
}
.pattern:after {
background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiAoV2luZG93cykiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6MkRGNDcyQ0Y4ODQ4MTFFNEFFRjVERDUwMjZBRDgzNUYiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6MkRGNDcyRDA4ODQ4MTFFNEFFRjVERDUwMjZBRDgzNUYiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDoyREY0NzJDRDg4NDgxMUU0QUVGNURENTAyNkFEODM1RiIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDoyREY0NzJDRTg4NDgxMUU0QUVGNURENTAyNkFEODM1RiIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PtWxVHsAAABESURBVHjahI9BDgAgCMO0///zjBcDZk6OpIF2Shpm9nLWBQFSAuulBpPeVZgANZgPdGCcuAvEibtAnLgL5FV5uy8BBgBvsBUQrZ/GBQAAAABJRU5ErkJggg==") repeat;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
content: "\0020";
opacity: .5;
z-index: 0;
}
button {
position: relative;
z-index: 1;
}
<div class="pattern">
<button class="btn btn-info">This is a button</button>
</div>
Related
Trying to create an overlay effect on hover, using :after, but it's not taking the full height.
It will work if I give a:after a fixed height in pixels. But I was hoping not to set a static height so it can be applied to images of all sizes.
Thanks in advance!
* {
margin: 0;
padding: 0;
}
.container {
width: 500px;
height: 500px;
}
a {
position: relative;
height: 100%;
width: 100%;
}
a:after {
content: '';
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
background: rgba(0,0,0,0.4);
opacity: 0;
transition: all .4s;
-webkit-transition: all .4s;
}
a:hover:after {
opacity: 1;
}
<div class="container">
<a href="#">
<img src="https://vignette.wikia.nocookie.net/dragonballfanon/images/7/70/Random.png/revision/latest?cb=20161221030547">
</a>
</div>
I removed width: 100%; and height: 100% from a and added display: inline-block; By default a tags have a display value of inline which ignores width and height values so they weren't doing anything before anyway. display: inline-block; is probably what you wanted to go with from the beginning.
* {
margin: 0;
padding: 0;
}
.container {
width: 500px;
height: 500px;
}
a {
position: relative;
display: inline-block;
}
a::after {
content: '';
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
background: rgba(0,0,0,0.4);
opacity: 0;
transition: all .4s;
-webkit-transition: all .4s;
}
a:hover::after {
opacity: 1;
}
<div class="container">
<a href="#">
<img src="https://vignette.wikia.nocookie.net/dragonballfanon/images/7/70/Random.png/revision/latest?cb=20161221030547">
</a>
</div>
<a> tag default display is display: inline.
To achieve the desired result you should display your <a> as inline-block. See docs: https://www.w3schools.com/css/css_inline-block.asp
a {
position: relative;
display: inline-block;
}
* {
margin: 0;
padding: 0;
}
.container {
width: 500px;
height: 500px;
}
a {
position: relative;
display: inline-block;
}
a:after {
content: '';
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
background: rgba(0,0,0,0.4);
opacity: 0;
transition: all .4s;
-webkit-transition: all .4s;
}
a:hover:after {
opacity: 1;
}
<div class="container">
<a href="#">
<img src="https://vignette.wikia.nocookie.net/dragonballfanon/images/7/70/Random.png/revision/latest?cb=20161221030547">
</a>
</div>
Your <a> element is not getting the full height, because by default is displayed as inline.
You can set display:inline-block; to change the default render behavior... or you can play with the position property.
Setting the container to position:relative, and the a and the a:after to position:absolute, will let you force the a:after to adjust to top:0px; and bottom:0px; covering the full height.
With that changes, everything works as expected.
Check it.
.container {
width: 500px;
height: 500px;
position: relative;
}
a {
position: absolute;
}
a:after {
content: '';
position: absolute;
width: 100%;
top: 0;
bottom: 0px;
background: rgba(0,0,0,0.4);
transition: all .4s;
-webkit-transition: all .4s;
opacity:0.2;
}
a:hover:after {
opacity: 1;
}
<div class="container">
<a href="#">
<img src="https://vignette.wikia.nocookie.net/dragonballfanon/images/7/70/Random.png/revision/latest?cb=20161221030547">
</a>
</div>
add a display block:
a {
position: relative;
height: 100%;
width: 100%;
display:block;
}
Have you noticed facebook's profile picture has this change profile picture on hover at the lowest part of the image?
It's like this example but it has the user's name instead.
I have this but it looks pretty nasty.
HTML
<div class="image">
<img src="./data/picture_caption/{{picture_caption}}" alt="polaroid" />
<p class="label">This image looks super neat.</p>
</div>
CSS
.image {
position: relative;
height: 200px;
width: 257px;
}
.label {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
color: #fff;
visibility: hidden;
opacity: 0;
}
.image:hover .label {
visibility: visible;
opacity: 1;
}
How can I achieve this?
Here following is your edited code. It will display name from bottom on hover.
.image {
height: 100px;
overflow: hidden;
position: relative;
width: 100px;
}
img {
height: 100px;
width: 100px;
}
.label {
background: rgba(0, 0, 0, 0.5) none repeat scroll 0 0;
bottom: -20px;
color: #fff;
left: 0;
margin: 0;
position: absolute;
right: 0;
text-align: center;
transition:0.1s all;
}
.image:hover .label {
bottom: 0px;
}
<div class="image">
<img src="http://i.stack.imgur.com/gLiJy.png" alt="polaroid" />
<p class="label">Name</p>
</div>
Try this method, it's a bit rudimentary but it works.
http://codepen.io/anon/pen/bEmGJv
HTML:
<div class="img-container">
<img src="http://blog.ramboll.com/fehmarnbelt/wp-content/themes/ramboll2/images/profile-img.jpg" alt="Profile">
<span class="img-txt">User name</span>
</div>
CSS:
.img-container{
position:relative;
display: inline-block;
}
img-container img{
display:block;
}
.img-txt{
position:absolute;
bottom:0;
left:0;
width:100%;
height:30px;
line-height: 30px;
padding-left: 10px;
background: rgba(255,0,0,0.5);
display:none;
}
.img-container:hover .img-txt{
display:block;
}
I have a banner that ends with a triangle(arrow) that has to stay centered vertically overlapping the slideshow below it. The amount of text/content that it will accept can grow dynamically. Is there a way to style this so that as the text increases the arrow will stay centered as you see below. Below is the styling that I have to achieve the screenshot below.
.carousel {
position: relative;
margin-top:3.5em;
padding-bottom:5%;
.header {
position: absolute;
top:-2em;
left:0;
z-index: 1000;
background-color:#81C3C4;
color:white;
font-family:Lato;
}
.headerWithTag {
position: absolute;
top:-3.5em;
left:0;
z-index: 1000;
background-color:#81C3C4;
color:white;
font-family:Lato;
&:after {
content: "";
background: url(/img/styleguide/masterslider/h1_right_top.svg) no-repeat;
background-size: contain;
position: absolute;
top: 0;
left: 100%;
width: 100%;
height: 100%;
}
}
}
React Component HTML:
{headerClass} = either .header or .headerWithTag depending if there is a subtitle(h3 tag).
<div className="carousel">
<div className={headerClass}>
<h1>{headerText}</h1>
<h3>{this.props.subTitle}</h3>
</div>
<div className="slideShow">
<div>
<div ref="wrapper" className="master-slider ms-skin-default" data-qa={thisName + '_masterslider'}>
{slides}
</div>
</div>
</div>
</div>
So the solution is to use top:0; transform: translate(0, -50%) to shift the header up half its height from the top of the slide:
.header {
position: absolute;
top: 0;
transform: translate(0,-50%);
left:0;
z-index: 1000;
background-color:#81C3C4;
color:white;
font-family:Lato;
}
.headerWithTag {
position: absolute;
top: 0;
transform: translate(0,-50%);
left:0;
z-index: 1000;
background-color:#81C3C4;
color:white;
font-family:Lato;
&:after{
content: "";
background: url(/img/styleguide/masterslider/h1_right_top.svg) no-repeat;
background-size: contain;
position: absolute;
top: 0;
left: 100%;
width: 100%;
height: 100%;
}
}
Quick demo: http://jsfiddle.net/7ky4wvz6/1/
I am using bootstrap along with HTML5 to develop a website.
I have a website header.
I wish to have an image in the website header with some opacity value and also some text in it.
I have referred this link setting opacity for background image and tried implementing it. I have got the text but not the image.
Here is the code:
HTML:
<div class="page-header head">
<div class="hbg"></div>
Hi there
</div>
CSS:
.head{
position: relative;
z-index: 1;
margin-top:10px;
height: 170px;
}
.head .hbg
{
background: url('hbg.png');
background-size: 100% 100%;
opacity: 0.3;
z-index: -1;
}
What is the issue here?
.head .bg doesnt exist in the code above. Change to .hbg.
How about this instead?
<div class="page-header head">
Hi there
</div>
-
.head{
width: 300px;
height: 250px;
display: block;
position: relative;
}
.head::after {
content: "";
background: url(hbg.png);
opacity: 0.3;
top: 0;
left: 0;
bottom: 0;
right: 0;
position: absolute;
z-index: -1;
}
You need to add position: absolute; top: 0; left: 0; to .hbg and width and height of 100% so it spreads all over the parent container:)
.head {
position: relative;
z-index: 1;
margin-top: 10px;
height: 170px;
}
.head .hbg {
position: absolute;
top: 0px;
left: 0px;
background: url('http://gillespaquette.ca/images/stack-icon.png');
background-size: cover;
opacity: 0.3;
z-index: -1;
width: 100%;
height: 100%;
}
<div class="page-header head">
<div class="hbg"></div>
Hi there
</div>
How can I keep a close button contained inside an image even is I change the img size using jquery
#full_image {
width: 200px;
height: 200px;
left: 0px;
top:10px;
position: relative;
opacity: 1;
z-index: 9;
}
#full_image img {
left: 20px;
width: 339px;
height: 211px;
position: relative;
overflow: hidden;
}
#full_image .close{
background: url("http://www.sobral.ce.gov.br/saudedafamilia/close.jpg") no-repeat;
top: 5px;
right: 0px;
cursor: pointer;
height: 29px;
opacity: 1;
position: absolute;
width: 29px;
z-index: 999;
}
<div id="full_image"><img src="http://coe.berkeley.edu/forefront/fall2005/images/woz1.jpg" />
<span> </span>
</div>
JSFIDDLE
Use the following CSS:
#full_image {
position: relative;
}
#full_image span {
position: absolute;
top: 0;
right: 0;
}
This tells the span to be a positioned relatively to #full_image, and stick to top right of it.
Hope this helps :)
You don't specify what "close button contained inside an image" means. I would have tried to put my image and button like this:
HTML:
<div>
<img id="myImage"></img>
<button id="myButton" />
</div>
CSS:
#myImage {
position: relative;
}
#myButton {
position: absolute;
top: ???;
left: ???;
}
jQuery:
You have to calculate where to place your button (what you should give the CSS-attributes for f ex top: and left: )