Reputation: 51
I've got a problem while adding an image to my project site.
So, when I use the element tag name only like 'img' then there is no horizontal scroll but when i use that image using a class selector like '.class img', then the horizontal scroll appears. Please help me I have never see a problem like this...
html,body {
height: 100%;
margin: 0;
}
nav {
display: flex;
background-color: #ffffff;
padding: 10px;
}
nav a {
text-decoration-line: none;
color: black;
font-size: 20px;
padding-right: 25px;
}
.about {
margin-left: auto;
}
.home {
padding-left: 20px;
padding-right: 0;
}
.first-img{
width: auto;
height: auto;
}
<html>
<head>
<link rel="stylesheet" href="style.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<nav>
<a class="home" href="#">Home</a>
<a class="about" href="#">About</a>
<a class="menu" href="#">Menu</a>
<a class="contact" href="#">Contact</a>
</nav>
<div class="first-img">
<img class="first" src="hamburger.jpg" />
</div>
<script type="text/javascript" src="script.js"></script>
</body>
</html>
Upvotes: 2
Views: 58
Reputation: 405
You are facing this problem because width of the image will be greater than the viewport width to fix the horizontal scroll do the following:
.first {
max-width: 100%;
height: auto
}
Upvotes: 4
Reputation: 9
You Dont Need to add class for just width of image Simply Do this !
<img src="hamburger.jpg" width="100%" />
Upvotes: 0
Reputation: 56
Try adding this to your class, also, I believe your HTML class needs to be first-img, not just "first"
.first-img{
width: auto;
height: auto;
overflow-x:hidden;
overflow-y:hidden;
}
"overflow-x" hides the horizontal, "overflow-y" hides the vertical
Upvotes: 0