Skip to content Skip to sidebar Skip to footer

How To Place Image Next To Text Css

I would like to place an image to the left of the text and keep it like that depending on the resolution of the window. Here's what it looks like without an image: http://prntscr.c

Solution 1:

If you're going to use floats and widths for the logo, use that for the menu also.

.xd {
  float: left;
  width: 90%;
  font-size: 20px;
  list-style: none;
  margin: 0;
  padding: 0;
  text-align: center;
}

.xdli {
  display: inline;
}

.xda {
  display: inline-block;
  padding: 5px;
  color: #080808;
}

.logo {
  width: 10%;
  height: auto;
  float: left;
}
<divclass="container"><divid="container-fluid"><imgclass="logo"src="http://placehold.it/50x50"><ulclass="xd"><li><ahref="index.html">Home</a></li><li><ahref="about.html">About Us</a></li><li><ahref="news.html">News</a></li><li><ahref="gallery.html">Gallery</a></li><li><ahref="map.html">Map</a></li><li><ahref="contact.html">Contact Us</a></li></ul></div>

You could also use flexbox. Perhaps something like this:

header,
ul {
  display: flex;
}

headerimg {
  display: block;
  max-width: 100%;
  height: auto;
}

headerul {
  flex-grow: 1;
  justify-content: center;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 20px;
}

headera {
  padding: 5px;
  color: #080808;
}
<header><div><imgsrc="http://placehold.it/50x50"></div><ul><li><ahref="index.html">Home</a></li><li><ahref="about.html">About Us</a></li><li><ahref="news.html">News</a></li><li><ahref="gallery.html">Gallery</a></li><li><ahref="map.html">Map</a></li><li><ahref="contact.html">Contact Us</a></li></ul></header>

Solution 2:

You can use position: absolute; and the default settings on the image as shown below. (You can use top and left settings to move it away from the border/corner if you want)

This keeps the menu items centered in relation to the container.

.xd {
  font-size: 20px;
  list-style: none;
  margin: 0;
  padding: 0;
  text-align: center;
}

.xdli {
  display: inline;
}

.xda {
  display: inline-block;
  padding: 5px;
  color: #080808;
}

.logo {
  width: 10%;
  height: auto;
  float: left;
}
#image1 {
position: absolute;
}
<divclass="container"><imgsrc="http://placehold.it/80x50/fb4"id="image1"><divid="container-fluid"><ulclass="xd"><li><ahref="index.html">Home</a></li><li><ahref="about.html">About Us</a></li><li><ahref="news.html">News</a></li><li><ahref="gallery.html">Gallery</a></li><li><ahref="map.html">Map</a></li><li><ahref="contact.html">Contact Us</a></li></ul></div>

Post a Comment for "How To Place Image Next To Text Css"