I am wanting to use an image sprite for a hover action, but I've been working on it for an hour and can't get it right. The span element video-play-q-right has the sprite as its background.
Here is my sprite:
Here is a screenshot of the divs:
Here is the html:
<div class="video-box">
<div class="video-img">
<a href="#" onclick="window.open('http://url.html','photoessay','scrollbars=no,resizable=yes,width=800,height=600')">
<img src="resources-na/images/video.jpg" width="200" height="155" border="1">
<span class="video-play-q-right">play</span></a>
</div>
<div class="video-text">
<p><strong> of Water</strong>.<br /> water's properties. (05:43 min)
... View</p>
</div>
</div>
Here is the CSS:
.video-box{
padding-right: 20px;
float: left;
width: 200px;
}
.video-img {
background-color: #EEEEEE;
border: 1px solid #DDDDDD;
margin-bottom: 0 !important;
padding: 4px;
width: 200px;
height: 155px;
}
.video-play-q-right {
background: url("../images/video-play-q-big.png") no-repeat scroll 0 0 transparent;
background-position: center top;
height: 50px;
position: absolute;
text-indent: -9999em;
width: 50px;
left: 321px;
top: 127px;
}
a.video-play-q-right:hover span{
background-position: center bottom;
}
Why a.video-play-q-right:hover span ?
There's no link with video-play-q-right class. Try to replace it with a:hover .video-play-q-right
a.my-class:hover span means " a link (a element) with class my-class which contain a span ".
So it will target this:
<span>Some text</span>
But not this:
<span class="my-class">Some text</span>
Related
I've been trying to make a square image that is layered behind a <div>. For my website, I'm trying to make it look similar to an album with a CD popping out from the slip, but every attempt I've done to make the image square, layered behind and the same size as the <div> seems to not work. It's either on top, or it's overflowing to the bottom of the page.
Here's the HTML I did:
<div class="container">
<div id="navbar">
<div id="nav">
<div>
<i class="fa fa-home" aria-hidden="true"></i>Home
</div>
<div>
<i class="fa fa-address-book" aria-hidden="true"></i>About
</div>
<div>
<i class="fa fa-book" aria-hidden="true"></i>Work
</div>
<div>
<i class="fa fa-question-circle" aria-hidden="true"></i>Extras
</div>
</div>
</div>
<iframe src="home.html" title="Webpage" id="content" name="content"></iframe>
</div>
</div>
<div class="disk">
<img src="/images/cd.svg">
</div>
And the CSS:
:root { /* to get the color just type var(--color) */
--color1:#150F0F; /*DARKEST*/
--color2:#221918;
--color3:#2C221F;
--color4:#423229;
--color5:#58493D;
--color6:#8D7357;
--color7:#BCAA9B;
--color8:#BCAA9B;
--color9:#F5DEAD;
--color10:#FFF9BC; /*BRIGHTEST*/
--border-size:3px;
}
.container {
min-height: 50vh;
width: 70%;
margin: auto;
margin-left:10%;
display: grid;
grid-template-columns: minmax(2vw, 260px) auto;
background-color: var(--color9);
border: 0px;
border-style: solid;
border-top-width: var(--border-size);
border-bottom-width: var(--border-size);
border-color: var(--color10);
z-index: 69;
}
#navbar {
height: auto;
width: auto;
padding: 10%;
float: left;
background-color: var(--color7);
font-family: PopMagic;
font-size: clamp(15px, 4vw, 30px);
}
#content {
height: 100%;
width: 100%;
border:none;
}
.disk {
min-height: 50vh;
max-width: 85%;
margin: auto;
margin-left:10%;
margin-top: -50vh;
position:relative;
overflow:hidden;
padding-bottom:100%;
}
.disk img {
min-height: 50vh;
position: absolute;
}
The site I'm using this on can be found here.
As you may expect there are as many approaches as developers.
You should consider how your layout is constructed at the moment because there is simply not enough space for your disc element.
If I were you I would get rid the following div
<div class="disk">
<img src="/images/cd.svg">
</div>
and try to use ::after psuedo-element instead.
...
.container {
border: none;
position: relative;
padding: 0 160px 0 0;
background-color: #0000;
::after {
right: 0;
content: '';
width: 160px;
height: 100%;
position: absolute;
background-size: cover;
background-position: right;
background-repeat: no-repeat;
background-image: url(/images/cd.svg);
}
}
...
Please don't expect the final solution here but take above code as a bunch of clues which may help to solve your problem.
How do I place an image on top of a button with html and css?
<div>
<img src="photo.jpg">
<button>Text</button>
</div>
I guess it should be something like
div {
position: relative;
}
img {
position: absolute;
top: 10px;
}
but it acts a bit weird.
Is it possible to just have a normal div and then set the img to float on top of everything else in the div element?
I don't know what's your purpose exactly, if you want the image to take the whole line, make the button lay beneath, why don't set the CSS display attribute of the image to display:block;?
hello see the below one its simple with a few line code
<div style="position:relative;" >
<img src="http://www.industrydynamics.ca/images/skype_icon.png" width="100" height="100" >
<input type="button" name="" value="Button" style="position:absolute;width:80px;left:10px;top:120px;" >
</div>
You can use position: absolute with transform: translate() on img.
This calc(-100% - 1px) means
-100% or - height of element (img in this case) that you are performing transform on, so it will translate for its own height up on Y axis
-1px is for top border on div element.
div {
position: relative;
display: inline-block;
border: 1px solid black;
margin-top: 100px;
}
img {
position: absolute;
top: 0;
transform: translateY(calc(-100% - 1px));
}
<div>
<img src="http://placehold.it/50x50">
<button>Text</button>
</div>
Just to demonstrate if you have border of 5px then you should use -5px in calc.
div {
position: relative;
display: inline-block;
border: 5px solid black;
margin-top: 100px;
}
img {
position: absolute;
top: 0;
transform: translateY(calc(-100% - 5px));
}
<div>
<img src="http://placehold.it/50x50">
<button>Text</button>
</div>
#bottom{
background-repeat: repeat-x;
height:121px;
width: 984px;
margin-left: 20px;
margin-top: 13px;
}
#bottom .content{
width: 182px; /*328 co je 1/3 - 20margin left*/
height: 121px;
line-height: 20px;
margin-top: 0px;
margin-left: 9px;
margin-right:0px;
display:inline-block;
position:relative;
}
<div id="bottom">
<div class="content">
<img src="http://placehold.it/182x121"/>
<button>Text</button>
</div>
</div>
May be you are trying to achieve something like this.
.userIcon {
background: url('https://cdn1.iconfinder.com/data/icons/user-pictures/100/male3-128.png') no-repeat;
height:20px;
width:20px;
background-size:20px;
top: 8px;
}
.left {
float:left;
}
.right {
float:right;
}
.clear{
clear:both;
}
.button{
padding:10px;
color: #FFF;
background-color: #0095ff;
border:1px solid #07c;
box-shadow: inset 0 1px 0 #66bfff;
}
.btnText{
margin:2px 0px 0px 10px;
}
<div>
<button class="button">
<span class="left userIcon"></span>
<span class="right btnText">Create user account</span>
<span class="clear"></span>
</button>
</div>
If you just want to make the image to come over the button, you can make the display as block
check the following snippet
div img{
display:block;
}
button{
text-align:center;
margin:40px;
padding:10px;
}
<div>
<img src="https://cdn1.iconfinder.com/data/icons/user-pictures/100/male3-128.png">
<button>Text</button>
</div>
Hope this helps
i have been trying to place the grandient on top of the image and behind the text but everything i tried from what i could find out in web didnt worked.
i would need to have the source of the image in the div cause if its in the css code it will apply the same image to all other templates i create.
thanks :)
<div class="titles">
<div class="thumb">
<img class="img overlay"
height=260px
width=240px
alt="Shokugeki no Souma: Ni no Sara"
src="https://img7.anidb.net/pics/anime/184719.jpg" />
<div class="titulo">Shokugeki no Souma: Ni no Sara</div>
<div class="epis">Epis. 12</div>
</div>
.titles .thumb {
position: relative;
float: left;
height: 260px;
width: 245px;
max-height: 260px;
max-width: 260px;
margin: 0 auto;
padding: 5px;
}
.thumb .titulo {
position: absolute;
bottom: 0;
left: 0;
padding: 8px;
margin: 5px;
font-size: 15px;
font-weight: bold;
color: white;
}
.thumb .epis {
position: absolute;
top: 0;
right: 0;
padding: 8px;
margin: 10px;
font-size: 15px;
font-weight: bold;
color: white;
}
.titles .thumb .img:hover {
max-height: 260px;
max-width: 260px;
height: 260px;
width: 240px;
opacity: 0.8;
}
.img.overlay {
background: linear-gradient(
to bottom,
black,
rgba(64,64,64,1),
rgba(64,64,64,1),
rgba(64,64,64,1),
rgba(64,64,64,1),
rgba(64,64,64,1),
rgba(64,64,64,1),
black);
}
Do you mind explaining a bit more about what is going wrong when you try to implement this?
My suggestion would be to put the overlay in its own separate div instead of inside the image tag. Then close the overlay div before you start your caption div. Then you can set your "thumb" class to have a certain width and height in your css, and style the overlay div to have height:100% width:100%so that it completely covers your thumbnail image. If you absolutely position the caption text, you can place it on top of the gradient. For example
<div class="titles">
<div class="thumb">
<img alt="Shokugeki no Souma: Ni no Sara" src="https://img7.anidb.net/pics/anime/184719.jpg" />
<div class="overlay"></div>
<div class="titulo">Shokugeki no Souma: Ni no Sara</div>
<div class="epis">Epis. 12</div>
</div>
</div>
I have two images that I want to place side by side with hover effects. I've managed to get them side by side...but I'd like the images centered under the logo image.
CSS:
a.btn1 {
display: inline-block;
float: left;
width: 332px;
height: 85px;
cursor: pointer;
background-image: url(images/bttn_model.png);
text-indent: -9999em;
margin:
}
a.btn1:hover {
background-image: url(images/bttn_model_over.png);
}
a.btn2{
display: inline-block;
width: 332px;
height: 85px;
cursor: pointer;
background-image: url(images/bttn_photographers.png);
text-indent: -9999em;
}
a.btn2:hover {
background-image: url(images/bttn_photographers_over.png);
}
}
HTML:
<body>
<div align="center">
<p> </p>
<p><img src="images/logo.gif" width="618" height="85" /></p>
</div>
<p> </p>
<div align="center">Models
<div align="center">Photographers
</div>
</div>
<p> </p>
</body>
</html>
You should wrap the 2 images in one div, so you can center that div with the following class
.centerDiv
{
width: 50%;
margin: 0 auto;
}
One possible way to do what you want is following.
HTML
<div class="logo">
<img src="images/logo.gif" width="618" height="85" />
</div>
<div class="pictures">
Models
Photographers
</div>
CSS
.logo {
text-align: center;
}
.pictures {
text-align: center;
}
.pictures a {
cursor: pointer;
display: inline-block;
width: 332px;
height: 85px;
text-indent: -9999em;
}
.btn1 {
background-image: url('images/bttn_model.png');
}
.btn1:hover {
background-image: url('images/bttn_model_over.png');
}
.btn2{
background-image: url('images/bttn_photographers.png');
/* next margin-left is to fix the space between */
/* images that because of the inline-block */
/* margin-left: -4px; */
}
.btn2:hover {
background-image: url('images/bttn_photographers_over.png');
}
Using attributes like align is not nice practise nowdays. For this things there is solution in CSS.
Using display: inline-block and float: left is not needed in this case, while it is in one line already with display.
If you wanted to use <p> </p> instead of margin & padding, that put them back, but better practise is to stick with margin & padding
Using nested divs, each div has a background image, I want the images side-by-side
I am trying to put stars side-by-side.
here is my html & css code
<body>
<div class="rate-stars">
<div class"star" id="s5"><pre> </pre>
<div class"star" id="s4"><pre> </pre>
<div class"star" id="s3"><pre> </pre>
<div class"star" id="s2"><pre> </pre>
<div class"star" id="s1"><pre> </pre>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
My CSS:
.star
{
background-image: url("star-off.png");
float: left;
border: 0px;
width: 20px;
height: 20px;
margin: 0px;
padding: 20px;
}
Demo
Your first problem is you're missing the = in all of your class assignments:
<div class"star"
^ missing =
With those fixed, this CSS will do it:
.star
{
background-image: url("star-off.png");
background-repeat:no-repeat;
width: 20px;
height: 20px;
margin-left:25px;
}
You can do the following :
HTML can written as :
<div id="rate-stars">
<img id="star1" src="img/star1.png">
<img id="star2" src="img/star2.png">
</div>
Css :
#star1 {
left: 20px;
position: absolute;
top: 100px;
}
#star2 {
left: 60px;
position: absolute;
top: 100px;
}
Try this css
.star
{
background-image: url("star-off.png") no-repeat top left;
border: 0px;
padding-left: 20px;
height: 20px;
margin: 0px;
}