I have a simple image that has a size attribute added using CSS.
I decided to make the image clickable by adding a <a>
tag hoping nothing will change. But the whole image has been reset and i cant change the size without removing the <a>
tag.
HTML
<a href="#"><header><img src="images/logo.png" alt=""></header></a>
CSS
header img {
width: 100%;
height: 50%;
}
Additionally, another React project is having the same issue:
// the css for "catImg"
const useStyles = makeStyles(theme => ({
catImg: {
"&:hover": {
boxShadow: "10px 5px 5px black;",
backgroundColor: "blue",
}
}
}))
.
.
.
<ImageListItem className={classes.catImg}>
{/* <a> */}
<img
src={url}
key={cat.token_id} />
{/* </a> */}
</ImageListItem>
EDIT:
Putting the a
tag outside the ImageListItem
makes it work correctly.
// the css for "catImg"
const useStyles = makeStyles(theme => ({
catImg: {
"&:hover": {
boxShadow: "10px 5px 5px black;",
backgroundColor: "blue",
}
}
}))
.
.
.
<a href="something">
<ImageListItem className={classes.catImg}>
<img
src={url}
key={cat.token_id} />
</ImageListItem>
<a/>
One of the simplest ways to resize an image in the HTML is using the height and width attributes on the img tag. These values specify the height and width of the image element. The values are set in px i.e. CSS pixels.
Sometimes, it is required to fit an image into a certain given dimension. We can resize the image by specifying the width and height of an image. A common solution is to use the max-width: 100%; and height: auto; so that large images do not exceed the width of their container.
How to Insert an Image in HTML. To insert an image in HTML, use the image tag and include a source and alt attribute. Like any other HTML element, you'll add images to the body section of your HTML file. The HTML image element is an “empty element,” meaning it does not have a closing tag.
The quick response is because yow styles said that them images inside yow header are going to have this styles
header img {
width: 100%;
height: 50%;
}
The problem is in your html. Html has rules AND one of them rules is that block tags should not be in side of inline tags
header
tag is a block tag a
is inline
If you want to override that rule in your css you need to specify that a
tags are block tags as well with
a {
display: block;
}
You have to reference the a
tag instead of the img
header a {
width: 100%;
height: 50%;
padding: 0;
margin: 0;
}
header a img {
width: 100%;
height: 100%;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With