I would like to display text when the user mouseovers the image.
How can I do this in HTML/JS?
You can use title attribute.
<img src="smiley.gif" title="Smiley face"/>
You can change the source of image as you want.
And as #Gray commented:
You can also use the title on other things like <a ... anchors, <p>, <div>, <input>, etc.
See: this
You can use CSS hover:
div {
display: none;
border: 1px solid #000;
height: 30px;
width: 290px;
margin-left: 10px;
}
a:hover+div {
display: block;
}
<a><img src='https://placekitten.com/100/100'></a>
<div>text</div>
You can do like this also:
HTML:
<a><img src='https://encrypted-tbn2.google.com/images?q=tbn:ANd9GcQB3a3aouZcIPEF0di4r9uK4c0r9FlFnCasg_P8ISk8tZytippZRQ' onmouseover="somefunction();"></a>
In javascript:
function somefunction()
{
//Do somethisg.
}
You can use CSS hover in combination with an image background.
.image {
background: url(https://placekitten.com/100/100);
height: 100px;
width: 100px;
display: block;
float: left;
}
.image a {
display: none;
}
.image a:hover {
display: block;
}
<div class="image">Text you want on mouseover</div>
Related
I have a text inside the div with class message, and I want to move the div to vertical center with respect to parent div with class banner.
Please refer the JsFiddle here - https://jsfiddle.net/1rbhuwfs/
Whenever I try to set margin-bottom, it goes increasing beyond the parent div indefinitely, which I don't understand why. The parent div has display: block on it.
I prefer not to have any position: absolute in my code.
Thanks in advance.
Check below snippet, I have added
.banner > div {
vertical-align:middle;
}
and removed margin-bottom: 40px; form .message.
.banner {
height: 100px;
background-color:#4d1242;
margin: 0 1px;
display: block;
}
.banner > div {
vertical-align:middle;
}
.img-1-holder {
display: inline-block;
margin-left: 15px;
}
.img1 {
height: 70px;
margin-bottom: 15px;
}
.img-2-holder {
display: inline-block;
}
.img2 {
height: 100px;
}
.message {
display: inline-block;
}
<div class="banner">
<div class="img-1-holder">
<img class="img1" src="http://free-smiley-faces.de/images/free-animated-angry-smiley-animiert-wuetend_02_70x70.gif">
</div>
<div class="message">
Some random text here
</div>
<div class="img-2-holder">
<img class="img2" src="http://www.free-smiley-faces.de/Smiley-Faces/www.free-smiley-faces.de_smiley-face_03_100x100.gif">
</div>
</div>
Check jsfiddle, put parent to display:table and child to display: table-cell and vertical-align: middle.
https://jsfiddle.net/ggq39acr/
You can refer this too. https://www.w3.org/Style/Examples/007/center.en.html
The solutions suggest in this link works in general ! :D
One way to vertically center without position: absolute or using tables - and respecting your margin-bottom on image and text-div - is to use flexbox:
Add/change this:
.banner {
display: flex;
align-items: center;
}
https://jsfiddle.net/5496yk1k/
you can use flexbox fiddle
.banner {
height: 100px;
background-color:#4d1242;
margin: 0 1px;
display: flex;
justify-content: center;
align-items: center;
}
In this case you can remove the margins on
.img1 {
height: 70px;
}
.message {
display: inline-block;
}
You can try to include a common class suppose img-inline with inline css properties and manage other css properties in your classes .img-1-holder, .img-2-holder and .message
Here is a sample code for you. You can try it in your jsfiddle. Sorry I am not posting fiddle link here.
HTML CODE
<div class="banner">
<div class="img-inline img-1-holder">
<img class="img1" src="http://free-smiley-faces.de/images/free-animated-angry-smiley-animiert-wuetend_02_70x70.gif">
</div>
<div class="img-inline message">
Some random text here
</div>
<div class="img-inline img-2-holder">
<img class="img2" src="http://www.free-smiley-faces.de/Smiley-Faces/www.free-smiley-faces.de_smiley-face_03_100x100.gif">
</div>
</div>
CSS CODE:
.banner {
height: 100px;
background-color:#4d1242;
margin: 0 1px;
display: block;
}
.img-1-holder {
margin-left: 15px;
}
.img1 {
height: 70px;
margin-bottom: 15px;
}
.img-2-holder {
margin-left: 15px;
}
.img2 {
height: 100px;
}
.img-inline {
display: inline-block;
vertical-align: middle;
}
Hope this helps :)
Here’s a tricky one…
I have a div, the contents of which should change on hove over on any part of it.
Here’s a pic detailing both wanted states:
And here is best effort, so far:
codepen
..it needs a bit of work.
Any help much appreciated!
Here's the HTML so far:
<div class="item green">
<a href="#">
<h4>Welcome</h4>
<p>Click here to find out more</p>
<img src="http://www.veropixel.com/res01-170w115h.jpg"/>
</a>
</div> <!-- /item -->
So there's my solution http://codepen.io/anon/pen/mIrvA :
$resinGreen: #00a14a;
.green { background: $resinGreen; }
.item {
width: 300px;
margin-bottom: 5px;
a {
display: block;
height: 98px;
overflow: hidden; /* cancels img float */
text-decoration: none;
h4, p {
height: 98px;
line-height: 98px; /* Two lines added to center
vertically text of course you can use display:inline-block
with vertical-align:middle */
padding-left: 15px;
margin:0;
}
img {
float: right;
height: 98px;
}
p {
display: none;
}
&:hover {
h4, img { display: none; }
p { display: block; }
}
}
}
Your problem was that your link haven't a height so it's why it was blinking, i also moved img to the first place for floating
If using just images within the div this bit of jquery will do it:
$('#applyimg').hover(function(){
$(this).attr('src','/design/sendcv_over.png');
},function(){
$(this).attr('src','/design/sendcv.png');
});
HTML
<img id='applyimg' src='/design/sendcv.png'>
Mouseover the image will swop it's source
I'm trying to create the look of a recipe card online:
As such, I am trying to have the underline go the full width of the paragraph, even if the text does not. Right now, I am trying to use text-decoration: underline, but it only extends as long as the text:
HTML:
<div>
<p>Lorem ipsum...</p>
</div>
CSS:
p {
border-bottom: 1px solid #000;
display: inline;
width: 200px;
}
div {
width: 400px;
}
JSFIDDLE: http://jsfiddle.net/FYNAM/1/
Any suggestions?
Stupid solution, but if your line height is the same across all <p> (no nested elements with different line-height) you can use background image.
.rtv {
position: relative;
}
.abs {
position: absolute;
}
.full-underline {
width: 100%;
}
.full-underline span {
display: block;
width: 100%;
height: 20px;
border-bottom: 0.8px solid black;
}
<div class="content tl m20 rtv">
<div class="full-underline abs">
<span></span>
<span></span>
<span></span>
<span></span>
</div>
<h3>NAMA PEKERJAAN :</h3>
<h1>PEKERJAAN EMERGENCY PEMBERSIHAN BENDA ASING DI TOWER 07 SECTION NGENA-TUBAN</h1>
</div>
enter image description here
You can adjust the span height with the size of the text
You can solve this by modifying what happens after your p tag as follows
p:after {
content: " ______________________________________________";
}
This was a quick down and dirty solution, but I think you'll be smart enough to take it from here ;)
Good luck.. and great question! You had my vote
DEMO
add following to your css:
div { display: block; width: 100%; }
div > p { display: block; width: 100%; }
or, you could also try:
div { width: 100%; }
div > p { display: block; }
*remove width from 'p'
It should solve your issue.
I want to show second div (in HTML) with class dikha on cursor hover over anchor tag.
HTML CODE:
<a>Hover over me!</a>
<div class="faraz"> sdjfg </div>
<div class="dikha">Stuff shown on hover</div>
STYLE
div {
display: none;
}
a:hover > div:nth-child(2) {
display: block;
background-color: RED;
height: 250px;
width: 960px;
}
Write like this:
a:hover ~ .dikha {
display: block;
background-color: RED;
height: 250px;
width: 960px;
}
You need to use the adjacent siblings selector ~. Also, the div you want to show is the third child, not the second (because the <a> is the first).
div {
display: none;
}
a:hover ~ div:nth-child(3) {
display: block;
background-color: RED;
height: 250px;
width: 960px;
}
Demo: http://jsfiddle.net/3eFhf/
you can use javascript function here.
< onmouseover="document.getElementById('myid').style.display='block'">
< id="myid" class="dikha">
Your dikha class should be hidden by default
.dikha { display:none; }
you can also use jquery slidetoggle method to achieve this
I have this code :
.myDiv
{
background-color: blue;
}
.myLink
{
background-color: red;
margin-top: 20px;
}
<div class="myDiv">
<a class="myLink" href="javascript:void(0)">Ciao</a>
</div>
if I increase the margin-top I'd aspect that the div becomes more hight (and the go to the bottom of the div), but in fact this doesnt happens! The same with padding-top (it go out of the div...). It doesnt listen the container!
Why? And how can I fix this trouble?
EDIT
in fact what Id like to do is align an input box and a image, you can see the example here :
<div>
<input type="text" />
<a style="margin-top:10px; margin-left:5px;" href="#">
<img alt="Cerca" src="/private_images/home_button_right.png">
</a>
</div>
Change to:
.myLink
{
background-color: red;
padding-top: 100px;
display: inline-block;
}
or
div {
padding-top: 100px;
}
depending on what you want to achieve.
Based on your update of the question:
Updated Demo fiddle.
CSS:
input,
img {
vertical-align: middle;
}
Or use vertical-align: top; to align the tops.
Do the opposite thing:
.myDiv
{
background-color: blue;
padding-bottom: 20px;
}
.myLink
{
background-color: red;
}
Add display: block; or maybe even better: display: inline-block;. Block elements can have height. Inline elements not.
You might also consider to give the anchor a larger line-height (e.g. line-height: 2em;), but that only works for single-line text.
.myDiv
{
background-color: blue;
}
.myLink
{
background-color: red;
display:list-item;
}
You can use display:list-item; to solve this problem