I am trying to add a border to an image on rollover. The border is not showing when I roll over the image. Here is my code:
<script>
$(document).ready(function() {
$("#imgBorder").hover(
function() { $(this).addClass("Hover"); },
function() { $(this).removeClass("Hover"); }
);
});
</script>
Hover { border: 1px solid #000; }
<div id="imgBorder">link...
Why isn't the border appearing on hover?
Also, is there any way to do this so that it does not re-size the image when adding the border?
You do not need to use javascript to add hover on image rollover. Just add it to the css class instead.
<style language="text/css">
.rollOver : hover
{
border: 1px solid #000;
}
</style>
<div class="rollOver" id="imgBorder">Test</div>
First, to affect the image, your jQuery should be:
$("#imgBorder img").hover(
function() { $(this).addClass("Hover"); },
function() { $(this).removeClass("Hover"); }
);
And your CSS should be:
.Hover { /* note the period preceding the 'Hover' class-name */
border: 1px solid #000;
}
JS Fiddle demo.
Note that:
.string selects element(s) by their class-name of string: <div class="string"></div>
#string selects an element by its id, which is equal to string <div id="string"></div>
string selects an element of string: <string></string>
But you don't need JavaScript, just use:
#imgBorder:hover img,
#imgBorder img:hover {
border: 1px solid #000;
}
JS Fiddle demo.
Something like this will work in CSS, link below
.rollover_img {
width: 280px;
height: 150px;
background-image: url(land.jpg);
background-position: top;
-moz-border-radius:10px;
-webkit-border-radius:10px;
border:10px solid #ccc;
font:13px normal Arial, Helvetica, sans-serif;
line-height:18px;
float:left;
margin:0 10px 10px 0;
}
I will direct you to the following link
http://aceinfowayindia.com/blog/2010/02/how-to-create-simple-css-image-rollover-effect/
In your selector below, you're targeting an element with the tagname "Hover". This does not exist.
Hover { border: 1px solid #000; }
What you wanted instead was:
.Hover { border: 1px solid #000 }
As others here have already pointed out, you don't need JavaScript for this as you can use the :hover pseudo-class:
img { border: 1px solid #FFF }
img:hover { border-color: #000; }
For further reading, see http://www.w3.org/TR/CSS2/selector.html#dynamic-pseudo-classes
Related
I have a font awesome icon like this on my page
<fa-icon class="file-excel-icon" title="Export to Excel" [icon]="['sil', 'file-excel']"></fa-icon>
which translates to this html
So the class file-excel-icon does get added to the element.
I am now trying to modify some css of SVG element but it is never getting applied. I have tried this
.file-excel-icon
{
border:1px solid red;
svg
{
vertical-align: -0.170em !important;
border:1px solid blue !important;
}
}
and this
.file-excel-icon
{
border:1px solid red;
.svg-inline--fa
{
vertical-align: -0.170em !important;
border:1px solid blue !important;
}
}
and this
.file-excel-icon .svg-inline--fa
{
vertical-align: -0.170em !important;
border:1px solid blue !important;
}
But nothing seems to work for svg, no style is applying to it, while the style does apply to fa-icon element
I'm trying (and have succeeded) in selecting a div, it's child, and it's pseudo before/after elements, using the following syntax, but I want to know if there is a simplified way of doing it?
After some research I found the following scss works for the html/scss (link to JSFiddle is below also):
HTML
Want to add a class all-borders-hidden to reveal-div element, which will then make the div itself, it's child/children, and both pseudo elements update to have no border:
<div class="reveal-div">
Parent Div
<div class="main-image-div">
Main Cild Div
</div>
</div>
scss
.reveal-div {
border: 2px solid black;
// I toggle the all-borders-hidden class on the parent/ancestor
// reveal-div class element
// The following works, but it's a bit verbose - can it be simplified
&.all-borders-hidden {
border: none;
}
&.all-borders-hidden *{
border: none;
}
&.all-borders-hidden::after{
border: none;
}
&.all-borders-hidden::before{
border: none;
}
}
I have the exmaple running in jsfiddle
You can use & again:
.reveal-div {
border: 2px solid black;
// I toggle the all-borders-hidden class on the parent/ancestor
// reveal-div class element
// The following works, but it's a bit verbose - can it be simplified
&.all-borders-hidden {
border: none;
* {
border: none;
}
&::after{
border: none;
}
&::before{
border: none;
}
}
}
and if they are sharing the border:none you can do this:
.reveal-div {
border: 2px solid black;
// I toggle the all-borders-hidden class on the parent/ancestor
// reveal-div class element
// The following works, but it's a bit verbose - can it be simplified
&.all-borders-hidden {
&,
*,
&::before,
&::after{
border: none;
}
}
}
How can I highlight all spans and divs in my html that have classes that are not styled? this is for debugging purposes, to remind me what I will still have to fix up.
Use border to highlight the span and div elements
Do either:
span, div{
border: 1px solid red;
background-color: yellow;
}
Or:
.unstyledClassOfDivAndSpan{
border: 1px solid red;
}
I would add an XXX class to all the elements, then use this definition:
.XXX {
border: 5em solid red;
background-color: green;
}
Make sure this is at the end of the stylesheet so it doesn't get overridden. Then as elements are done, remove the XXX class.
Please Use this Css Hover Style for highlight all spans and divs in your html
div, span{
border: 1px solid red;
background-color: Black;
}
div:hover, span:hover{
border: 1px solid Black;
background-color: red;
}
OR
*Please Use this Css and Jquery Hover Function for highlight all spans and divs in your html*
.hilight{
border: 1px solid red;
}
$(function(){
$("spna div").hover(function(){
$(this).toggleClass("hilight");
});
});
How do I prevent elements from shifting when I add a border to them?
example:
p:hover
{
border:1px solid red;
}
p
{
border:none;
}
But is not working
Always give them a border, just make it transparent when it's not hovered:
p {
border:1px solid transparent;
}
p:hover {
border:1px solid red;
}
JSFiddle
Of course it's one answer, your question can be answered a number of ways.
p {
border:1px solid transparent;
}
I tried the following code css3 style for 5 px wide horizontal line
<hr style=" border: solid 1px red;padding-top:10px; margin:25px auto 15px auto;clear:both" />
but I am getting 5px wide red rectangle.
Please advise me with a proper CSS3 style code.
As long as the element has the right width, a simple:
border-bottom:5px solid red;
Will do the trick.
You should use width and height properties instead of border:
width: 5px;
height: 1px;
color: red;
http://www.sovavsiti.cz/css/hr.html
Just use the "border-width" property and set it to 5px.
<hr style="border-width: 5px !important;">
Get rid of the top-padding, and use the border-bottom suggested above... http://jsfiddle.net/ZdLfJ/
My CSS for HR Line Styling;
.line_height { height:4px; }
.line_width { width:100%; }
.line_hcenter { margin-left: auto; margin-right: auto; }
.line_vcenter { margin-top: 10px; margin-bottom: 10px; }
.line_color { color:black; }
.line_bgcolor { background-color:black; }
.line_bordercolor { border-top: solid black; border-bottom: solid black; }
Add these classes to the hr tag.
All three color ( color , bgcolor, bordercolor ) classes are needed to get a solid colored line across.
Classes .color and .bgcolor needed for browser cross compatibility or else you just get double lines.
Dont use any other thing after border property just make 5px instead of 1 px in border.
I.e