href For Image Goes Beyond Image In HTML website with CSS - html

I am making an html website and trying to make the website so when you click the image it takes you to another website. This is the code I have in index.html
<a href="https://www.youtube.com/">
<div class="metFinLogo"></div>
</a>
and in css
.metFinLogo{
background-image: url('./images/metFinLogoImg.png');
background-size:contain;
width: 250px;
height:200px;
margin: 5%;
background-repeat: no-repeat;
}
When I open index.html the image can still be selected even outside image. I need help to make it so that only clicking where there is image sends to link.

The <div> tag is a block level element. It will work if you add display: inline-block to .metFinLogo
.metFinLogo{
background-image: url('./images/metFinLogoImg.png');
background-size:contain;
width: 250px;
height:200px;
margin: 5%;
background-repeat: no-repeat;
display: inline-block;
}

inline-block It’s formatted just like the inline element, where it doesn’t start on a new line. BUT, you can set width and height values.
.metFinLogo{
display:inline-block;
}
.metFinLogo{
background-image: url('https://static.remove.bg/remove-bg-web/6cc620ebfb5922c21227f533a09d892abd65defa/assets/start_remove-c851bdf8d3127a24e2d137a55b1b427378cd17385b01aec6e59d5d4b5f39d2ec.png');
background-size:contain;
width: 250px;
height:200px;
margin: 5%;
background-repeat: no-repeat;
display: inline-block;
}
<a href="https://www.youtube.com/">
<div class="metFinLogo"></div>
</a>

Related

how to put in a div 2 images in the css background-image: url(.....)

How I can put in the same div in the background two images with css?
<div class="testimonial carousel-item active">
<img class="img-testimonial" src="assets/image-tanya.jpg" alt="">
<div class="text-testimonial">
<p>"I've been interested in coding for a while but never taken the jump, until now. I couldn't recommend this course enough. I'm now in the job of my dreams and so excited about the future."</p>
<p class="small">Tanya Sinclair <span class="grey">UX Engineer</span></p>
</div>
</div>
in .testimonial I have in the background an svg image
.testimonial {
background-image: url(../pattern-bg.svg);
background-repeat: no-repeat;
background-position: right top;
width: 1000px;
height: 800px;
position: relative;
display: inline-block;
}
CSS Multiple Backgrounds
CSS allows you to add multiple background images for an element, through the background-image property.
The different background images are separated by commas, and the images are stacked on top of each other, where the first image is closest to the viewer.
div{
background-image: url("https://whyy.org/wp-content/uploads/2017/07/LOGO_First_overwhite-1-copy-1024x444.png"), url("https://cdn.iconscout.com/icon/premium/png-256-thumb/2nd-place-594924.png");
background-repeat: no-repeat;
background-position: left top;
width: 1000px;
height: 800px;
position: relative;
display: inline-block;
}
<div></div>

using span to hold image, not showing up unless its display is absolute

I'm having a problem, I'm getting HTML Delivered from an API, and this is the HTML I receive:
<div class="card-summary__container">
<div class="card-summary__img"></div>
<h1 class="card-summary__title">#title</h1>
<h1 class="card-summary__alert">#number</h1>
<div class="card-summary__info">
<p>TRENDING<p><span class="info-arrow-up"></span><span class="info-icon-up"></span>
</div>
The CSS I have applied is this:
.info-icon-up {
background: url('../../../assets/img/svg/summary/trend-tick.svg') 50% no-repeat;
background-size: cover;
width: 20px;
height: 20px;
background-size: cover;
margin-left: 4px;
margin-top: -4px;
}
.info-arrow-up {
background: url('../../../assets/img/svg/summary/trend-arrow-up.svg') 50% no-repeat;
background-size: cover;
width: 20px;
height: 20px;
background-size: cover;
margin-left: 4px;
margin-top: -4px;
}
And this is what I want to do:
So the two icons should be inline with the text, but unless I put there position as absolute the img doesn't show up, but if I do set the position as absolute then they won't position properly.
Is there something I'm doing wrong or something else I can do to get the desired result?
Any help would be appreciated!
Thanks
add display:inline-block to your span. Because span is inline element so it don't take height and width
HI first of all i can see there is a mistake in your html.
<p>TRENDING<p><span class="info-arrow-up"></span><span class="info-icon-up"</span>
the last span must be closed like this
<span class="info-icon-up"></span>
And you can add display:inline-block;to you span so they will come inline.or you can put all the text and icons in span tag and inline them with display:inline-block; property.

<p> tag always under background in <div>

So basically I want my p tag to always be displayed under my background image. If I make my window smaller, the p tag should not overlap the background-image.
I know adding it in the source code as a img in a separate div would help a lot, but an answer for this would be nice.
HTML:
<div class="champ-link img-background">
<a>
<p>browse the selection</p>
</a>
</div>
CSS:
.img-background {
background-image: url(test.jpg);
background-repeat: no-repeat;
background-size: 50px 63px;
}
.img-background {
background-image: url(test.jpg);
background-repeat: no-repeat;
background-size: 50px 63px;
padding-top: 63px;
}
or
p {
margin-top: 63px;
}
Just took the p tag out of the div to allow the p tag positioning.
<div class="champ-link img-background">
</div>
<a><p>browse the selection</p></a>
css:
img-background {
background-image: url(test.jpg);
background-repeat: no-repeat;
height: 10%;
background-position: center;
}
never overlaps the div.
Here is an alternative approach negating the need for padding or margin to "make space" for the image size, for instance if you want to scale your image size to your screen size
<div class="champ-link">
<div class='img-background'>
</div>
<a><p>browse the selection</p></a>
</div>
CSS
.img-background {
background-image: url(test.jpg);
background-repeat: no-repeat;
background-size: 100%; /* or cover or contain etc. */
display: block;
margin:auto; /* can add optional margin for top bottom too
so image doesn't "touch" anchor below it */
width: 50px; /* or whatever you want/need */
height: 63px; /* or whatever you want/need */
}

Image stretching or squeezing ,when I start to change browser size

I have a 2000x350 image and I want to fill that in every display for 350px height. With my code ,what is below, image starts to stretching or squeezing ,when I start to change browser or view size. I want to get that image is in center and fill my fixed height.
There is codes
HTML Code:
<div class="content">
<img src="image.png" class="image">
</div>
CSS
Code:
.content{
display:block;
}
.image{
width:100%;
height: 350px;
background-position:center;
background-size: cover;
-o-background-size: cover;
}
There is fiddle ,with my example
Thanks for help!
Sorry for my english ,thats not my native language :)
use CSS3 Flexbox Layout mode:
remove width: 100% from .image
describe .content as:
.content{
display: flex;
justify-content: center;
width: inherit;
overflow: hidden;
}
here's a fiddle:
https://jsfiddle.net/warkentien2/s1sfL2au/3/
Maybe you can try using background-image from css:
.content{
display:block;
background-image: url('http://www.toddsucherman.com/wp-content/uploads/2013/08/ToddSucherman-2000x350-01.jpg');
background-position: top, center;
backgorund-height: 350px;
background-repeat: no-repeat;
}
See the result: https://jsfiddle.net/51ouqj54/
You should the background image, now you are using img tag in html use this code.
Html Code
<div class="content"></div>
CSS Code
.content{background:url(http://www.toddsucherman.com/wp-ontent/uploads/2013/08/ToddSucherman-2000x350-01.jpg) no-repeat center center;
background-size:cover;
}

Background image of li element not showing in firefox

I have an html portion of code in my page that goes something like this:
<section class ="sidebar">
<ul>
<li class="facebook">Facebook</li>
<li class="linkedin">LinkedIn</li>
<li class="twitter">Twitter</li>
<li class="google-plus">Google+</li>
</ul>
</section>
And the css goes like this:
.sidebar ul {
float: left;
}
.sidebar ul li{
display: block;
width:35px;
text-indent: -9999px;
margin: 3px;
}
li.facebook{
height: 35px;
background: url(img/icon_face.png) center center no-repeat;
background-size: contain;
}
li.twitter{
height: 35px;
background: url(img/icon_twitter.png) center center no-repeat;
background-size: contain;
}
li.google-plus{
height: 35px;
background: url(img/icon_g+.png) center center no-repeat;
background-size: contain;
}
li.linkedin{
height: 35px;
background: url(img/icon_in.png) center center no-repeat;
background-size: contain;
}
What happens here is that I have 2 strange issues:
First the element li.google-plus does not show in any of the browsers. The browsers just ignore it. Here is what firebug shows:
The second is that the only image that shows in firefox is the twitter one. In chrome and opera all the other ones show correctly. As they are showing correctly in other browsers I assume the problem is not the path in the background property.
Any idea on what the problem may be?
EDIT:
Check what firebug says about the background image path:
It says that it couldn't load the given url.
Both in .sidebar ul li and in li.facebook,li.twitter etc. You should write width: and height: properties which You didn't set.
Ok, so it turns out that the problem was my AdBlock extension. After disabling it, it started working normally.
Figured it out through this answer: https://stackoverflow.com/a/466020/1235708