Combining an image and text within a single line in a div container

My goal is to have the envelope image in the same line as the text on the right side:

View my CodePen example here

.ico{
float:left;
margin-right: 5px;
vertical-align: middle;

I can't seem to get it right - what mistake am I making?

Answer №1

It's recommended to utilize the flex-basis property in flex containers to ensure consistent sizing.

Answer №2

Opt for using display: inline-block instead of floating the image.

.ico{
    display: inline-block;
    margin-right: 5px;
    vertical-align: middle;
}

Answer №3

Float and vertical-align are not compatible (refer to the rules for .ico{}).

display:block and vertical-align do not work together (see the rules for img{}).

To fix this, reset float and display for .ico.

You can adjust vertical-align by referring to the specification: (check here) :

img.ico {
  float: none;
  display: inline-block;
  margin-right: 5px;
  vertical-align: -0.6em;/* or middle but you can adjust this with any decimal value */
}

div {
  font-style: normal;
  font-family: sans-serif, Arial;
}

img {
  width: auto;
  max-width: 100%;
  height: auto;
  margin-left: auto;
  margin-right: auto;
  display: block;
}

#con {
  background-color: #00ff14;
  justify-content: center;
}

#logo {
  background-color: #ff8900;
}

#menu {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: space-around;
  margin: auto;
  border-color: red;
  border-width: 0px;
  margin-top: 10px;
}

#tresc {
  margin: 10px 10px 10px 10px;
  height: 100%;
  padding-bottom: 20px;
  text-align: justify;
  text-justify: inter-word;
  justify-content: center;
  border-color: red;
  border-width: 1px;
  border: solid;
}

#stopka {
  background-color: gainsboro;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: space-around;
}

#m1 {
  border-bottom: solid;
  border-top: solid;
  border-width: 2px;
  padding: 4px;
  border-color: greenyellow;
  -webkit-transition: border-color 1s;
}

#m1:hover {
  border-bottom: solid;
  border-top: solid;
  border-width: 2px;
  padding: 4px;
  border-color: red;
}

#tekst {
  line-height: 3px;
}
<div id="stopka">
  <div class="m3"><img src="https://sinshop.pl/upload/sinshop/allegro/envelope.png" class="ico"><span id="tekst">KONTAKT</span></div>
  <div class="m3"><img src="https://sinshop.pl/upload/sinshop/allegro/envelope.png" class="ico">WYSYŁKA</div>
  <div class="m3"><img src="https://sinshop.pl/upload/sinshop/allegro/envelope.png" class="ico">REGULAMIN</div>
  <div class="m3"><img src="https://sinshop.pl/upload/sinshop/allegro/envelope.png" class="ico">PŁATNOŚCI</div>
</div>

I have also changed <div id="m3"> to <div class="m3">.Id should be unique per page.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the reason for the malfunction of input :: - webkit-slider-thumb and input :: - moz-slider-thumb?

Designing a compact slider for enhancing user experience not limited to webkit browsers requires utilizing a scss template such as input { width: 100%; -webkit-appearance: none; -moz-appearance: none; appearance: none; height: 1vm ...

Processing AJAX request without reloading the page using PHP

I need assistance with creating an image cropping tool that allows users to upload a picture, crop it, and display it on the page as an image.jpg rather than as base 64 (data:image). I have tried using HTML and JavaScript but it seems impossible, so now I ...

Calculating the median in JavaScript utilizing a for loop

Currently, I am in the process of learning JavaScript. My goal is to calculate the median of a set of numbers that I input through a prompt when I click the button labeled "find median". function CalculateMedia() { var n = prompt("Enter the number of e ...

Integrating image transitions into JavaScript

Could you provide guidance on how to create buttons from the three images within the "fadein" div in order to navigate directly to a specific jpeg? Currently, the three jpgs are displayed in a continuous loop. Thank you. ...

Toggle the operational status of the bootstrap switch

Does anyone have a solution for customizing the appearance of the Bootstrap switch button when it is disabled? I have successfully styled it for the enabled state, but it defaults to a dark appearance when disabled. I would like the disabled state to have ...

I am experiencing a CSS display issue on the mobile version of my map leaflet where only the header and footer are visible

I am experiencing a display issue on Android and iPhone due to conflicting css commands. Here's what's happening: I am using React + React Leaflet with a header, main, and footer all set to width 100% within a parent div with body set to width an ...

JavaScript Functions for Beginners

I'm currently facing some challenges with transferring the scripts and HTML content from the calendar on refdesk.com. My task involves moving the JavaScript to a separate stylesheet and utilizing those functions to replicate the calendar on an HTML pa ...

Tips for scrolling ion-items vertically to the bottom and top using arrow icons in Ionic 4

I'm developing an Ionic 4 app with Angular and looking to incorporate Up and Down Arrow buttons for vertical scrolling from top to bottom and vice versa. ...

Automatic Submission based on Checkbox Selection

Creating a user-friendly interface for project admins is my goal, but I am encountering difficulties in displaying all tasks. The data is retrieved from the database and put into a table, with each task having a status represented by a binary value - 1 f ...

What is the best way to expand a scrollbar's width with CSS?

Can the width of a scrollbar on a <div> element within the <body> be increased? I mean the scrollbar specifically on the inner <div> element, not the default browser scrollbar since this page is in full screen mode and does not display t ...

chooses to activate prefers-color-scheme regardless of whether dark mode is also activated

Currently, I have implemented the following CSS to invert an image when in dark mode on my website: @media (prefers-color-scheme: dark) { #main-logo img {filter: invert(1);} } While this does successfully invert the image in dark mode, it also trigg ...

Highlight all the written content within the text box

I'm struggling with a piece of code that is supposed to select all the text inside an input field: <input id="userName" class="form-control" type="text" name="enteredUserName" data-ng-show="vm.userNameDisplayed()" data-ng-model="vm.enteredUs ...

Boss declares, "Display the iFrame with no borders visible."

Good day to everyone, I am currently dealing with an issue on the page: It seems to be working perfectly in all of my browsers except for Internet Explorer. Since I don't have IE, I'm having trouble troubleshooting this. My boss mentioned somet ...

Incorporate personalized buttons into your Slick Carousel

Looking to add custom previous and next buttons to a slick carousel? I attempted using a background image on the .slick-prev and .slick-next CSS classes, as well as creating a new class following the documentation, but unfortunately, the arrows disappeared ...

Unveiling the secrets to retrieving JSON array objects in HTML with the help of Angular!

Looking to display a JSON file in HTML, but struggling with syntax for deeply nested objects. { "questions": [ { "question": "Qw1", "answers": [ { "answers": "An1", "value": 25 }, { ...

The execution of the function halts as soon as the player emerges victorious

In my attempt to create a basic game where players compete to click their designated button faster to reach 100%, I am in need of assistance with implementing a logic that determines the winner once one player reaches or exceeds 100. Essentially, I want ...

Combining two XPaths into a single XPath can be achieved by using various

HTML <li class="wdappchrome-ai" data-automation-id="searchInputAutoCompleteResult" tabindex="-2" aria-posinset="1" aria-setsize="3"> <span data-automation-id="searchInputAutoCompleteResultFullText"> <span style="font-weight:500"> ...

Transferring data from JavaScript to PHP for geolocation feature

Hello everyone, I'm looking to extract the longitude and latitude values from my JavaScript code and assign them to PHP variables $lat and $lng. This way, I can retrieve the city name and use it in my SQL query (query not provided). Below is the scrip ...

Automatically adjusting jQuery script now functions on all hyperlinks for seamless resizing

I am attempting to create a rollover script that will resize my social network links when hovered over. The desired effect is for the 32px square icon to expand and display the trailing address. For example, when hovering over the Facebook link, it should ...

Tips for saving a PHP variable in an HTML attribute

I am working on a page that allows users to select colors from a list using checkboxes. When the user submits their selections, I want all the chosen colors to be displayed with their corresponding color as their font color. Below is the code I have so fa ...