Limit image size to div

Viewed 78

I've tried several methods but can't seem to get my LinkedIn logo to fit. I've tried to inherit as well as setting max height and width to 100% to limit. But it just keeps going full size.

Do I need to use some other form of container?

body {
  background-color: #2e2e2e;
  margin: 0px;
}

a {
  color: rgb(0, 255, 234);
  text-decoration: none;
  font-family: FoundrySterlingOT3W03-Bold, FoundrySterlingOT3W10- Bold, Arial, Helvetica, sans- serif;
  font-weight: 900;
  right: 0px;
}

a:hover {
  color: white;
}

.linkedin {
  height: inherit;
  width: inherit;
}

.nav-custom {
  padding-top: 1px;
  height: 50px;
  position: relative;
  text-align: center;
}

.nav-custom>a {
  padding-left: 30px;
  padding-right: 30px;
}

.header {
  background: rgba(0, 0, 0, 0.2);
  position: fixed;
  z-index: -1;
  width: 100%;
  margin-top: -20px;
  max-height: 100px;
}
<div class="header">
  <img class="linkedin" src="linkedin logo.png">
  <nav position: fixed; class="nav-custom" ;>
    <a href=#home>Home</a>
    <a href=#skills>Skills</a>
    <a href=#about>About</a>
    <a href=#contact>Contact</a>
  </nav>
</div>
<link rel="stylesheet" href="Portfolio.css">>

2 Answers

See if this fit your demand

I put the logo in the nav section and make it a fit height width in px

.linkedin {
  height: 40px;
  width: 40px; 
}

also using flex to align to it's other element in nav

.nav-custom {
  padding-top: 1px;
  height: 50px;
  position: relative;
  text-align: center;
  display: flex;
  align-items: center;
}

  body {
    background-color: #2e2e2e;
    margin: 0px;
}

a {
    color:rgb(0, 255, 234);
    text-decoration: none;
    font-family: FoundrySterlingOT3W03-Bold,FoundrySterlingOT3W10- 
Bold,Arial,Helvetica,sans- 
serif;
    font-weight: 900;
    right: 0px;
}

a:hover {
    color: white;
}

.linkedin {
    height: 40px;
    width: 40px; 
}
.nav-custom {
    padding-top: 1px;
    height: 50px;
    position: relative;
    text-align: center;
    display: flex;
    align-items: center;
}

.nav-custom > a{
    padding-left: 30px;
    padding-right: 30px;
}

.header {
    background: rgba(0, 0, 0, 0.2);
    position: fixed;
    z-index: -1;
    width: 100%;
    max-height: 100px;

}   
<div class="header">
    <nav style="position: fixed;" class="nav-custom";>
      <a><img class="linkedin" src="https://cdn-icons-png.flaticon.com/512/174/174857.png"></a>
      <a href=#home>Home</a>
      <a href=#skills>Skills</a>
      <a href=#about>About</a>
      <a href=#contact>Contact</a>
    </nav></div>
<link rel="stylesheet" href="Portfolio.css">

 

width="value" height="value" needs to be added so <img class="linkedin" src="linkedin logo.png"> needs to be <img class="linkedin" src="linkedin logo.png" width="value" height="value"> so all together it would be

 <img class="linkedin" src="linkedin logo.png" width="value" height="value">
    <nav position: fixed; class="nav-custom";>
      <a href=#home>Home</a>
      <a href=#skills>Skills</a>
      <a href=#about>About</a>
      <a href=#contact>Contact</a>
    </nav></div>
<link rel="stylesheet" href="Portfolio.css">>  

   body {
    background-color: #2e2e2e;
    margin: 0px;
}

a {
    color:rgb(0, 255, 234);
    text-decoration: none;
    font-family: FoundrySterlingOT3W03-Bold,FoundrySterlingOT3W10- 
Bold,Arial,Helvetica,sans- 
serif;
    font-weight: 900;
    right: 0px;
}

a:hover {
    color: white;
}

.linkedin {
    height: inherit;
    width: inherit; 
}
.nav-custom {
    padding-top: 1px;
    height: 50px;
    position: relative;
    text-align: center;
}

.nav-custom > a{
    padding-left: 30px;
    padding-right: 30px;
}

.header {
    background: rgba(0, 0, 0, 0.2);
    position: fixed;
    z-index: -1;
    width: 100%;
    margin-top: -20px;
    max-height: 100px;

}

Related