How can I use an entirely separate CSS file to change/override only the URL for the image IMAGE.png?
<div id="id1" class="class1">
<div id="id2" class="class2">
<div class="class3">
<div id="id3">
<a class="logo" href="http://domain.com" tabindex="-1">
<img src="https://IMAGE.png"></img>
</a>
</div>
</div>
</div>
</div>
Thanks so much!
If you wants to achieve it with css, do it like this (Recommended).
.btn {
display: block;
width: 80px;
height: 80px;
background: url(http://mygimptutorial.com/images/button-with-metal-ring/13.jpg) no-repeat;
background-size: contain;
text-align: center;
color: #fff;
text-decoration: none;
}
.btn:hover {
background: url(http://mygimptutorial.com/images/button-with-metal-ring/8.jpg) no-repeat;
background-size: contain;
}
<div id="id1" class="class1">
<div id="id2" class="class2">
<div class="class3">
<div id="id3">
<a class="btn" href="http://domain.com" tabindex="-1"></a>
</div>
</div>
</div>
</div>
And with js do following.
$('.logo img').hover(function(){
$(this).attr('src','http://mygimptutorial.com/images/button-with-metal-ring/8.jpg');
},function(){
$(this).attr('src','http://mygimptutorial.com/images/button-with-metal-ring/13.jpg');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="id1" class="class1">
<div id="id2" class="class2">
<div class="class3">
<div id="id3">
<a class="logo" href="http://domain.com" tabindex="-1">
<img src="http://mygimptutorial.com/images/button-with-metal-ring/13.jpg"></img></a>
</div>
</div>
</div>
</div>
use content in your dark-mode class
darl
content:url(image.jpg);
You can't change it with CSS, you need Javascript for that.
But if you are trying to change the image on for example hover, you could remove the img-tags and use a div instead on which you set a background-image.
In your CSS you can then create a block where you change the image on hover.
Related
how do i add a link to a Div like below and make it clickable? I am using an image for the background of the Div and i want to make the whole image clickable.
<div class="grid__item-wrap">
<div class="grid__item" style="background-image: url(img/5.jpg)">
</div>
</div>
I have tried below two methods but none of them worked out for me.
Method 1:
<div class="grid__item-wrap">
<div class="grid__item" style="background-image: url(img/1.jpg)">
<div class="frame__links">
<a style="pointer-events: auto" class="frame__links" href="https://www.google.com/"></a>
</div>
</div>
</div>
Method 2:
<div class="grid__item-wrap">
<div class="grid__item" href="https://www.google.com/" style="background-image: url(img/4.jpg); pointer-events: auto;">
</div>
</div>
You need to put the div you wanted clickable inside <a> tag.
<a href="https://www.google.com/">
<div class="grid__item-wrap">
<div class="grid__item" style="background-image: url(img/5.jpg)">
</div>
</div>
</a>
.frame__links {
display:block;
height:100px;
}
.grid__item {
background-image: url(https://www.w3schools.com/w3css/img_forest.jpg);
background-repeat: no-repeat;
background-size: auto;
text-align: center;
color: white;
padding: 50px;
}
<a href="https://www.facebook.com/">
<div class="grid__item-wrap">
<div class="grid__item">
click here
</div>
</div>
</a>
Put the div element that you want to inside the a tag.
Wrapping the div inside an <a> tag should work. And style it in CSS with the cursor property to show that it is clickable.
You can do that by using onclick="window.location.href as you wanna redirect when you click on div
<div style="cursor:pointer;background-image: url(img/4.jpg)" onclick="window.location.href = 'https://www.w3schools.com';">Hello</div>
Method-2: You can wrap your div inside a tag and give background-image for the div and href path to a tag.
I have a HTML div like,
<div id="tab2" class="tab">
<div class="alarm" id="alarm">
<img src="src/alarm.jpg" style="width: 100%; height: 100%; background-size: contain;">
</div>
</div>
So I want to open this div when a button click. I tried to add a link to the button like this way,
Get Start
But this is not working. How can I do this. Please help me !
HTML Code:
<div id="tab2" class="tab" style="display:none;">
<div class="alarm" id="alarm">
<img src="src/alarm.jpg" style="width: 100%; height: 100%; background-size: contain;">
</div>
</div>
Get Start
Javascript:
function showDiv() {
document.getElementById('tab2').style.display = "block";
}
Try like this with javascript
<div id="tab2" class="tab" style="display: none;">
<div class="alarm" id="alarm">
<img src="src/alarm.jpg" style="width: 100%; height: 100%; background-size: contain;">
</div>
</div>
Get Start
<script>
document.getElementById("button1").addEventListener("click", function() {
document.getElementById("tab2").style.display = "block"
});
</script>
Add this css and try :
#tab2{
display:none;
}
#tab2:target{
display:block;
}
I have the following piece of code where an icon and text are displayed
<div class="group-block last">
<a class="w-inline-block" href="news.html" data-load="1">
<div class="group-image bg3"><img src="images/coffee.png" align="middle"></div>
<div class="group-title">
<div class="title-text">Relaxar-te</div>
</div>
</a>
</div>
I want to change the color of the text "Relaxar-te" after visiting this section. That means, once I returned to this page, the color of the text changed. The CSS of "title-text" is
.title-text {
line-height: 68px;
}
If tried to insert
.title-text:visited {
color: blue;
}
Unfortunately, this doesn't work. I saw many forums where they are using this way, however, it doesn't work for me or I'm missing something.
:visited only works for links. So what you need is
.title-text {
line-height: 68px;
}
a.w-inline-block:visited .title-text {
color: blue;
}
<div class="group-block last">
<a class="w-inline-block" href="news.html" data-load="1">
<div class="group-image bg3"><img src="images/coffee.png" align="middle"></div>
<div class="group-title">
<div class="title-text">Relaxar-te</div>
</div>
</a>
</div>
You can target the text in this manner:
a:visited .title-text{
color: pink;
}
<div class="group-block last">
<a class="w-inline-block" href="news.html" data-load="1">
<div class="group-image bg3"><img src="images/coffee.png" align="middle"></div>
<div class="group-title">
<div class="title-text">Relaxar-te</div>
</div>
</a>
</div>
:visisted only works on the a tag. .title-text is pointed to a div
you could change your code like this to fix it:
.custom-link:visited {
color:blue;
}
<div class="group-block last">
<a class="w-inline-block custom-link" href="news.html" data-load="1">
<div class="group-image bg3"><img src="images/coffee.png" align="middle"></div>
<div class="group-title">
<div class="title-text">Relaxar-te</div>
</div>
</a>
</div>
I want to adjust the size of the image to cover up the entire div. It would be very helpful if you guys can suggest anything in CSS rather than using javascript for it.
Here is a sample of what i have right now
.third{
width:30%;
float:left;
margin:8px;
}
.second{
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-flow: row wrap;
-ms-flex-flow: row wrap;
flex-flow: row wrap;
}
img{
width:100%;
object-fit:fill;
}
<div class="first">
<div class="second">
<div class="third">
<img src="https://i.ytimg.com/vi/nT8pKpXQSJY/maxresdefault.jpg">
</div>
<div class="third">
<img src="http://i1.wp.com/proyectart.es/wp-content/uploads/2015/10/One-Punch-Man.jpg">
</div>
<div class="third">
<img src="https://i.ytimg.com/vi/nT8pKpXQSJY/maxresdefault.jpg">
</div>
<div class="third">
<img src="https://i.ytimg.com/vi/nT8pKpXQSJY/maxresdefault.jpg">
</div>
<div class="third">
<img src="http://i1.wp.com/proyectart.es/wp-content/uploads/2015/10/One-Punch-Man.jpg">
</div>
<div class="third">
<img src="http://i1.wp.com/proyectart.es/wp-content/uploads/2015/10/One-Punch-Man.jpg">
</div>
</div>
</div>
Here is the link to the codepen for more details: http://codepen.io/gruler05/pen/vGyObo
The first, third and the fourth images are smaller than the rest. Can anyone please tell me how can I stretch those image to the size of their container div so that it looks like all the images are of the same size. Thank you in advance. P.S: I tried object-fit but it didn't work.
Using background-size:cover; in your CSS rules for the element is probably the easiest way to get full image coverage. This might cut off some of the content, though, depending on if you center the background image in the div or how you resize it.
background-size:contain; might be more useful, but I'm a huge fan of the cover size property.
Update
If you want to avoid background-image then you could try an img tag set to 100% width and/or height, but this will warp your image and cause other issues, and you'd potentially have to perform some JS calculations to prevent this.
Why the aversion to using a background image?
Here is a few ways, depending on if you want stretch or clipped images.
In sample 1 and 2, the trick I used is to keep the img as visibility: hidden to not have to set a fixed height on the third div.
Also, using the inline style for the image url, you can easily make that work with angular without messing with the external CSS.
Sample 1 - stretched
.third {
flex: 1 0 calc(33% - 16px);
margin: 8px;
position: relative;
background-size: 100% 100%;
}
.second{
display: flex;
flex-flow: row wrap;
}
img {
visibility: hidden;
width: 100%;
height: auto;
}
<div class="first">
<div class="second">
<div class="third" style="background-image: url( https://i.ytimg.com/vi/nT8pKpXQSJY/maxresdefault.jpg)">
<img src="https://i.ytimg.com/vi/nT8pKpXQSJY/maxresdefault.jpg">
</div>
<div class="third" style="background-image: url(http://i1.wp.com/proyectart.es/wp-content/uploads/2015/10/One-Punch-Man.jpg)">
<img src="http://i1.wp.com/proyectart.es/wp-content/uploads/2015/10/One-Punch-Man.jpg">
</div>
<div class="third" style="background-image: url( https://i.ytimg.com/vi/nT8pKpXQSJY/maxresdefault.jpg)">
<img src="https://i.ytimg.com/vi/nT8pKpXQSJY/maxresdefault.jpg">
</div>
<div class="third" style="background-image: url( https://i.ytimg.com/vi/nT8pKpXQSJY/maxresdefault.jpg)">
<img src="https://i.ytimg.com/vi/nT8pKpXQSJY/maxresdefault.jpg">
</div>
<div class="third" style="background-image: url(http://i1.wp.com/proyectart.es/wp-content/uploads/2015/10/One-Punch-Man.jpg)">
<img src="http://i1.wp.com/proyectart.es/wp-content/uploads/2015/10/One-Punch-Man.jpg">
</div>
<div class="third" style="background-image: url(http://i1.wp.com/proyectart.es/wp-content/uploads/2015/10/One-Punch-Man.jpg)">
<img src="http://i1.wp.com/proyectart.es/wp-content/uploads/2015/10/One-Punch-Man.jpg">
</div>
</div>
</div>
Sample 2 - clipped, center aligned
.third {
flex: 1 0 calc(33% - 16px);
margin: 8px;
position: relative;
background-size: cover;
background-position: center;
}
.second{
display: flex;
flex-flow: row wrap;
}
img {
visibility: hidden;
width: 100%;
height: auto;
}
<div class="first">
<div class="second">
<div class="third" style="background-image: url( https://i.ytimg.com/vi/nT8pKpXQSJY/maxresdefault.jpg)">
<img src="https://i.ytimg.com/vi/nT8pKpXQSJY/maxresdefault.jpg">
</div>
<div class="third" style="background-image: url(http://i1.wp.com/proyectart.es/wp-content/uploads/2015/10/One-Punch-Man.jpg)">
<img src="http://i1.wp.com/proyectart.es/wp-content/uploads/2015/10/One-Punch-Man.jpg">
</div>
<div class="third" style="background-image: url( https://i.ytimg.com/vi/nT8pKpXQSJY/maxresdefault.jpg)">
<img src="https://i.ytimg.com/vi/nT8pKpXQSJY/maxresdefault.jpg">
</div>
<div class="third" style="background-image: url( https://i.ytimg.com/vi/nT8pKpXQSJY/maxresdefault.jpg)">
<img src="https://i.ytimg.com/vi/nT8pKpXQSJY/maxresdefault.jpg">
</div>
<div class="third" style="background-image: url(http://i1.wp.com/proyectart.es/wp-content/uploads/2015/10/One-Punch-Man.jpg)">
<img src="http://i1.wp.com/proyectart.es/wp-content/uploads/2015/10/One-Punch-Man.jpg">
</div>
<div class="third" style="background-image: url(http://i1.wp.com/proyectart.es/wp-content/uploads/2015/10/One-Punch-Man.jpg)">
<img src="http://i1.wp.com/proyectart.es/wp-content/uploads/2015/10/One-Punch-Man.jpg">
</div>
</div>
</div>
Sample 3 - clipped, center aligned, fixed height (removed the img as well)
.third {
flex: 1 0 calc(33% - 16px);
margin: 8px;
position: relative;
background-size: cover;
background-position: center;
height: 150px;
}
.second{
display: flex;
flex-flow: row wrap;
}
img {
visibility: hidden;
width: 100%;
height: auto;
}
<div class="first">
<div class="second">
<div class="third" style="background-image: url( https://i.ytimg.com/vi/nT8pKpXQSJY/maxresdefault.jpg)">
</div>
<div class="third" style="background-image: url(http://i1.wp.com/proyectart.es/wp-content/uploads/2015/10/One-Punch-Man.jpg)">
</div>
<div class="third" style="background-image: url( https://i.ytimg.com/vi/nT8pKpXQSJY/maxresdefault.jpg)">
</div>
<div class="third" style="background-image: url( https://i.ytimg.com/vi/nT8pKpXQSJY/maxresdefault.jpg)">
</div>
<div class="third" style="background-image: url(http://i1.wp.com/proyectart.es/wp-content/uploads/2015/10/One-Punch-Man.jpg)">
</div>
<div class="third" style="background-image: url(http://i1.wp.com/proyectart.es/wp-content/uploads/2015/10/One-Punch-Man.jpg)">
</div>
</div>
</div>
Try adjusting your .third, it has a default padding that you can remove by adding the below CSS. You can adjust the height to however much you need. This way you can avoid background-image, but background-image would still be most efficient.
.third {
width: 33.33%;
height: 100px;
float: left;
margin:0;
padding:0;
}
You can do this, but it will lose the image's aspect ratio.
HTML: Add a div with class="row" and put 3 images inside each
<div class="first">
<div class="second">
<div class="row">
<div class="third">
<img src="https://i.ytimg.com/vi/nT8pKpXQSJY/maxresdefault.jpg">
</div>
<div class="third">
<img src="http://i1.wp.com/proyectart.es/wp-content/uploads/2015/10/One-Punch-Man.jpg">
</div>
<div class="third">
<img src="https://i.ytimg.com/vi/nT8pKpXQSJY/maxresdefault.jpg">
</div>
</div>
<div class="row">
<div class="third">
<img src="https://i.ytimg.com/vi/nT8pKpXQSJY/maxresdefault.jpg">
</div>
<div class="third">
<img src="http://i1.wp.com/proyectart.es/wp-content/uploads/2015/10/One-Punch-Man.jpg">
</div>
<div class="third">
<img src="http://i1.wp.com/proyectart.es/wp-content/uploads/2015/10/One-Punch-Man.jpg">
</div>
</div>
</div>
</div>
CSS: add the following code to give the .row a fixed height and set the image height to 95%
.row{
height:150px; //whatever height you want
}
.third img{
height:95%;
}
First delete all the <img> tags
then use this css
.third{
width:290px;
height:180px;
float:left;
margin:8px;
background-image:url("https://i.ytimg.com/vi/nT8pKpXQSJY/maxresdefault.jpg");
background-size:cover;
}
Although flexbox is a great approach, The most easiest approach to do it by using tables, and inserting the images as data.
Here is the code
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Images</title>
</head>
<body>
<table>
<tr>
<td> <img src="https://i.ytimg.com/vi/nT8pKpXQSJY/maxresdefault.jpg" width="200" height="200"></td>
<td> <img src="http://i1.wp.com/proyectart.es/wp-content/uploads/2015/10/One-Punch-Man.jpg" width="200" height="200"> </td>
<td> <img src="https://i.ytimg.com/vi/nT8pKpXQSJY/maxresdefault.jpg" width="200" height="200"> </td>
</tr>
<tr>
<td> <img src="https://i.ytimg.com/vi/nT8pKpXQSJY/maxresdefault.jpg" width="200" height="200"> </td>
<td> <img src="http://i1.wp.com/proyectart.es/wp-content/uploads/2015/10/One-Punch-Man.jpg" width="200" height="200"> </td>
<td> <img src="http://i1.wp.com/proyectart.es/wp-content/uploads/2015/10/One-Punch-Man.jpg" width="200" height="200"> </td>
</tr>
</table>
</body>
</html>
I am new here and just learning to code a website, so far I had hit a snag. When I try to use my background: url(../images/sprite.png) it does not seem to work, I got it to work on my navigation bar, but when I try to do it on my billboard section area it does not want to work with me at all. Here is my HTML
<div id="container_header">
<div id="container_header2">
<div id="ram_logo">
<a href="#">
<img src="images/ram_logo.png" border="0" alt="logo" />
</a>
</div>
<div id="menu">
<ul>
<li id="features"><span>Features & Specs</span></li>
<li id="photos"><span>Photo Gallery</span></li>
<li id="brochure"><span>Brochure</span></li>
<li id="getaquote"><span>Get A Quote</span></li>
</ul>
</div>
<div class="clear">
</div>
</div>
</div>
<div id="container_billboard">
<div id="truck_home">
</div>
<div id="billboard_title">
<p id="title_allnew">THE ALL NEW</p>
<p id="title_ram">2013 Ram 1500</p>
<p id="title_laramie">Laramie Longhorn </p>
<p id="title_starting">Starting at</p>
<p id="title_price">$20,500</p>
<div class="clear"></div>
<div id="title_getaquote">
<a href="#">
</a>
</div>
</div>
<div class="clear">
</div>
</div>
now the elements I am wanting to target are: <div id="truck_home"> and <div id="title_getaquote">
<a href="#">
</a>
</div>
here is my css:
#truck_home {
background-image: url(/images/sprite.png) no-repeat 0px -69px;
margin-top: -20px;
margin-right: -150px;
float: right;
height: 293px;
width: 655px;
}
#title_getaquote {
background-image: url(/images/sprite.png) no-repeat -163px -365px;
text-align: left;
margin-top: 20px;
margin-left: 165px;
}
so I am not sure what I am doing wrong here, I tried doing background-position: 0 0
please if anyone can help it would be really appreciated. I have been trying to figure this out for a few hours now...
In your CSS, use background: ... instead of background-image: ....
Demo
http://jsfiddle.net/raunakkathuria/MA8pN/
If you are using background-image don't include no-repeat -163px -365px in it, because background-image is for specifying url only, in this case you have to individually specify
background-repeat: no-repeat
background-position:-163px -365px;
or just update background-image as said by DXL also