This question already has answers here:
How to affect other elements when one element is hovered
(9 answers)
Closed 4 years ago.
I know that questions like this had been asked before, but it's different, and I couldn't find an answer for it under other question. Note that I'm a beginner, so don't judge me for not knowing something
I'm sorry if there actually is a question like this with an answer,I couldn't find it, then I would appriciate if you linked it :)
So Here's this simple code
This is a div on the page
.XY{
display:block;
position:static;
background-image: url(XY.jpg);
background-repeat:repeat-x,;
}
In this div there is a table, with many cells, including these ones too
#XY,#XY,#XY,#XY{
display:table-cell;
height:40px;
width:200px;
margin:auto;
text-align:center;
}
So my question is: How could I achieve that when I hover on those cells, then the background-image of the entire div changes, not only the cell's?Can I do this in css only or it requires some script codes too?
Thanks for any helpful comments/answers in advance!
Those all cells are in a div on the page, and What I want is when I hover on the Assault cell, then the current background image changes to a different one
Try this.
.XY {
display: block;
position: static;
background-image: url(https://www.w3schools.com/howto/img_fjords.jpg);
background-repeat: no-repeat;
color: #fff;
background-size: cover;
}
.XY:hover {
background-image: url(https://www.w3schools.com/w3css/img_lights.jpg);
background-repeat: no-repeat;
background-size: cover;
}
#XY,
#XY,
#XY,
#XY {
display: table-cell;
height: 40px;
width: 200px;
margin: auto;
text-align: center;
color: #000;
font-weight: bold;
}
<div class="XY">
<table>
<tr>
<td id="XY">Table Cell</td>
<td id="XY">Table Cell</td>
</tr>
</table>
</div>
Try this
div:hover {
background-color: green;
}
If this isn't what you were looking for just let me know
You could try giving that cell a different div class than the others and then for exp:
.table.some_style td{
background-color: your color;
}
.table.some_style td:hover{
background-image: your image;
}
If you want to have many cells to have tthat effect you can just give them the same class.
You´ll have to try if it works for you.
Please let me know if it worked or not.
Related
I'm making an application using Dreamweaver for a school project, and have used a version of the code I found online and re-writing it to suit the assignment needs.
Problem I have my links as actual images created in Photoshop (which are working). These are on a .css file, each by their own separate li tag. (These don't need to be changed!)
Eg.
li.accom {
height:93px;
width:556px;
background-image:url(../images/accom.png);
}
Question
How do you center these images? I've tried text-align=centre; and that hasn't worked.
Try this https://jsfiddle.net/2Lzo9vfc/64/
CSS
li {
width: 150px;
height: 50px;
margin: 10px;
list-style-type: none;
border: 1px solid black;
text-align: center;
background: url('http://placehold.it/70x50');
background-repeat: no-repeat;
background-position: center;
}
For backgrounds you have These CSS rules.
For your image, you will need of background-position attribute with value: center and, if you don't want it to be repeated, background-repeat attribute with value no-repeat.
Trying to get a background image to display in a single table cell element in Chrome...and it will, but only when I hover over that cell. If I remove the :hover, it just doesn't display no matter what I do.
I'm asking this question now in the hope that Google has fixed this issue and I haven't seen the answer after searching, or someone has figured it out. The other reason is that there are search results from 2010 and they mostly talk about table row elements instead of single cells.
This fails to give me my image in a table cell:
#matrix td.level {
position: relative;
vertical-align: top;
height: 200px;
width: 150px;
background: transparent url("/images/th-bg-level.png") no-repeat 0px bottom;
}
But I can hover just fine:
#matrix td.level:hover {
background: transparent url(/images/th-bg-level.png) no-repeat -157px bottom;
border: none;
}
It also will show the image if I change to a <th> element, but I don't really want to do that...bad coding practice and all...
Is there a solution to this issue?
Using backgrounds on <td> elements works fine, the issue must be somewhere else.
td {
padding: 30px;
}
td.target {
background: transparent url("http://i.imgur.com/cAN2O2J.jpg") no-repeat 0px bottom;
color: white;
}
<table>
<tr>
<td>John</td>
<td class="target">Doe</td>
</tr>
</table>
The hover state and the non-hover state in your code address completely different folders (/images/ vs ../images/), isn't the problem there?
I cannot figure out how to center this image on my mobile website.
Here is the code I am using, I am a beginner in CSS so I'm sure this is an easy fix. Just need some help. Thanks
#emotion-header-img {
display:none;
}
#emotion-header {
height:100px !important;
background-image:url("http://u.jimdo.com/www36/o/se9b04d2fd0388f99/emotion/orig/header.png") !important;
background-repeat:no-repeat !important;
background-size:contain !important;
}
Assuming you want the element to be centered horizontally and vertically as well:
/* generated from howtocenterincss.com, personally tried and tested! */
#emotion-header {
display:flex;
justify-content:center;
align-items:center;
/* height:100px !important; no need for this if you don't want to limit size*/
background-repeat:no-repeat !important;
background-size:contain !important;
}
#emotion-header-img {
height: 100px;
}
<div id="emotion-header">
<img id="emotion-header-img" src="http://u.jimdo.com/www36/o/se9b04d2fd0388f99/emotion/orig/header.png" alt="image header" \>
</div>
Of course there are many many other possibilities, and things get complicated when you want to add support for old browsers like IE7 or IE8. On anything before IE11 you would need to use a table cell. The above code snippet works for IE11 and mordern browsers.
A relevant and good resource I've found when trying to center things in CSS is howtocenterincss.com, which generates the right CSS for you based on your settings and choices. In fact, contrary to the name of the web app, it handles all sorts of alignments too. Just note that the generated code is to be embedded inside HTML elements with the <style> tag, which you can just extract whatever is inside those style tags and move to a CSS file for use.
So you mean want to align the background-image? If right, you can use background-position. Example:
#emotion-header {
width: 200px;
height: 200px;
border: 1px solid #ddd;
background-image: url("http://u.jimdo.com/www36/o/se9b04d2fd0388f99/emotion/orig/header.png");
background-size: 100px;
background-repeat: no-repeat;
background-position: center;
}
<div id="emotion-header"></div>
I have being wondering thinking what do one achieve this type of background in css for quite a while now. It's an image background, yet the image does not seem to be there. You cant download the image and cant drag it along. Please see the Pink stylish image background here . How can I achieve that? Or can some one help me with the feature name? Or perhaps a good link where I can learn or see the example on that? I just try googling but don't know what it's call. Another example is the chinese new year background Here.
Its a background-image:
New year:
.homepage-background-cny {
background: url("../../img/cny.jpg") no-repeat scroll right top transparent;
}
Etsy:
#seasonal-hero {
background: url("//img0.etsystatic.com/site-assets/homepage-carousel/valentine-gift-hero-v3.jpg") repeat scroll center center #FEEEEF;
width: 100%;
height: 400px;
min-width: 1030px;
cursor: pointer;
position: relative;
}
Background images usually cannot be dragged, the source of the elements background can be found with the inspector:
JSFiddle Demo
div{
height:300px;
background: url('http://lorempizza.com/1000/500');
}
<div>Background-Image</div>
They're just CSS background images:
Demo
HTML
<div id="container">
This is the content.
</div>
CSS
#container {
padding: 10px;
min-height: 600px;
width: 100%;
background: url(//img0.etsystatic.com/site-assets/homepage-carousel/valentine-gift-hero-v3.jpg) repeat-x;
}
In CSS you use the background-image rule:
background-image: url("//img0.etsystatic.com/site-assets/homepage-carousel/valentine-gift-hero-v3.jpg");
this is the one on the page you link uses.
Best,
Michael
I have an image like such:
and would like to when i hover, to get another Transparent image on TOP of it.
this is the css:
#imagebox {
Width:338px;
margin-left:10px;
background-color:#12100e;
height:221px;
float:left;
margin-bottom: 10px;
border: 1px solid #232323;
}
#imagebox:hover {
background: url("upplyst-platta.png") no-repeat 0 0;
}
But it is behind the picture, any way to solve this in css? or i have to fix it with javascript?
The image on bottom is generated from db(later on) and cannot be set in css
EDIT:
I saw this solution:
http://jsfiddle.net/bazmegakapa/Zf5am/
but cannot get it to work. even though i copy the whole code, what can be the problem?
Use the z-index to state which order the elements are drawn in.
You can find more information here: http://www.w3schools.com/css/pr_pos_z-index.asp
A few other things as well, you might want to add relative image placement based on the parents position and where you say Width in the first style, it should be all lowercase width :-P
Hope this is what you are looking for.
#imagebox {
Width:338px;
margin-left:10px;
background-color:#12100e;
height:221px;
float:left;
margin-bottom: 10px;
border: 1px solid #232323;
background: url("upplyst-platta.png") no-repeat 0 0;
}
#imagebox img{
display: none;
}
#imagebox:hover img{
display: block;
}
and the html structure should be:
<div id="imagebox"> <img src="iWantToShowThisImage.jpg" /></div>
Hope this works for you or provides some inspiration: jsfiddle example #1
Update based on first comment:
Do you mean like this? jsfiddle example #2
2nd update based on edit in question:
Well, the reason for not working is that the hoverimage isn't just transparent: it's a modification of the original.
But it clarifies your wish. I really think my first example is the solution you're looking for. Just replace the url in the style sheet with your transparent png file name.