What is the best way to position two elements inline?

I was trying to create a container named project-item that looks like the image linked below: https://i.stack.imgur.com/6XzZ9.png

My goal was to align the project logo and the title (h3) in one line, but I struggled to find a suitable solution.

This is what I ended up with: https://i.stack.imgur.com/Ak7ub.png

/* Updated Project Section Styles */
.project-section {
  border-radius: 5px;
  align-items: center;
  text-align: center;
}

.grid-project {
  display: grid;
  grid-gap: 1%;
  margin: 2%;
  align-items: center;
  text-align: left;
}

...
<div class="grid-project">
...
</div>

I attempted using display:flex, but it ended up displaying every element of the project in line, including descriptions and tags, which wasn't my intention.


https://i.stack.imgur.com/XXaup.png

Answer №1

To enhance the layout of your content, it is recommended to include two containers that wrap your image and other elements separately. These containers should have the parent element set to display: flex and flex-direction: row, with some added gap for spacing. Additionally, removing unnecessary a tags wrapping block elements can prevent unexpected behavior and ensure semantic correctness. For a better understanding, please refer to the full-page snippet provided below. Keep in mind that adjustments may be needed for smaller screens.

/* Updated Project Section Styles */

 .project-item {
  border-radius: 15px;
  transition: .5s ease;
  padding: 5%;
  height: auto;
  display: flex;
  flex-direction: row; /* Updated to display items in a row */
  gap: 20px;
  align-items: flex-start;
}

.project-item:hover {
  background: #6b6b6b3f;
}

.project-item .project-tag {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 2px;
}

.project-item .project-tag span {
  background: #fff;
  color: #000;
  border-radius: 25px;
  padding: 5px;
  white-space: nowrap;
}

.wrapper a {
  text-decoration: none;
  color: #fff;
}

.grid-project .project-item h3 {
  font-size: 24px;
  text-align: left;
  margin-bottom: 5px; /* Adjusted margin for spacing */
}

.grid-project .project-item p {
  font-size: 16px;
  line-height: 1.5;
}

.grid-project .project-item .project-logo {
  height: 70px;
  width: 70px;
  border-radius: 15px;
}
<div class="wrapper">
  <a href="https://dsc.gg/accumen" target="_blank">Click me</a>
    <div class="project-item">
      <div class="left-side">
        <img src="https://picsum.photos/50/50" class="project-logo">
      </div>
      <div class="right-side">
        <h3>Accumen</h3>
        <h4 class="project-info">
          <a href="https://github.com/infinotiver/accumen">View Github Repository </a>
        </h4>
        <div class="project-tag">
            <span>Python</span>
            <span>Discord Bot</span>
            <span>Education based</span>
            <span> AI </span>
        </div>
      </div>
    </div>
</div>

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

Ways to ensure the bootstrap table header width aligns perfectly with the body width

I am having an issue with my bootstrap table where the header width is smaller than the body width because I set the table width to auto. How can I align the header and body widths? Here is a link to a plunker showcasing the problem. https://plnkr.co/edit ...

Optimizing Three.js for better performance

Recently, I delved into working with three.js and webgl for a personal project. My goal was to develop a wardrobe model based on user input. You can check out the project at this link: Initially, the rendering speed was fast and smooth without Materials a ...

What is the best way to interpret numerous rows of Form elements simultaneously?

What is the most efficient way to name form elements across rows for easy conversion into JSON format? Considering HTML does not have built-in Array support, what alternative method should be used? In each row, there are 2 text fields and 1 select dropdow ...

Manipulate audio files by utilizing the web audio API and wavesurfer.js to cut and paste audio

I am currently working on developing a web-based editor that allows users to customize basic settings for their audio files. To achieve this, I have integrated wavesurfer.js as a plugin due to its efficient and cross-browser waveform solution. After prior ...

How can I show or hide all child elements of a DOM node using JavaScript?

Assume I have a situation where the HTML below is present and I aim to dynamically conceal all the descendants of the 'overlay' div <div id="overlay" class="foo"> <h2 class="title">title</h2> ...

The :not() exclusion in CSS property fails to exclude the class

I'm attempting to style all the links on my webpage in a particular way, except for those in the navigation bar. Despite trying to exclude the navbar links using a:not(.navbar), it seems that the styling still applies to all links, including Link 1 in ...

The modal window pops up immediately upon the first click

Experience a dynamic modal element that springs to life with just the click of a button or an image. The magic lies in the combination of HTML, CSS, and jQuery code: <div id="modal-1" class="modal"> <div class="button modal-button" data-butto ...

Discovering the process of extracting a date from the Date Picker component and displaying it in a table using Material-UI in ReactJS

I am using the Date Picker component from Material-UI for React JS to display selected dates in a table. However, I am encountering an error when trying to show the date object in a table row. Can anyone provide guidance on how to achieve this? import ...

css - aligning text below another text in the center

Looking to style a text in a specific color with a message about another text below it? Want the text centered but not sure how to position it correctly? margin: 0px auto; If this code isn't delivering the desired result and is positioning your text ...

Is there a way to handle the 'No tables found' error when using pd.read_html?

The issue I am facing a challenge while creating multiple URLs from an API request and then using them in a loop to extract data from the FT website. The problem arises when some of these URLs do not feature an HTML table, resulting in a No tables found er ...

"Troubleshooting: Fixing the issue with jQuery datepicker not

After implementing the jQuery Datepicker on a field, I noticed that even though assigning a value to the field shows in Chrome's developer tools... Unfortunately, the assigned value does not show on the front end. I am aware that we can set a defaul ...

Tips for swapping out a div tag with another div tag in the same spot without needing to redirect to a different page by utilizing bootstrap

Currently, I am developing a JSP project that utilizes Bootstrap for the frontend. I have come across a question regarding HTML design. Is there a way to replace one div tag with another div on the same page without navigating to a new URL using Bootstrap ...

Determine the vertical dimension of a child division once it has been integrated into an HTML document

My goal is to create a website with multiple pages without having to recreate the toolbar for each page. To achieve this, I have created a separate HTML file and CSS file specifically for the toolbar. On each page, I simply import the toolbar using the fo ...

Making a div element shift position in response to the user resizing the window

Unique Content: <!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> <title></title> <link href="style.css" rel="stylesheet" type="text/css"> <script src="http://code.jquery.com/jquery-1.6.4.min ...

Using knockoutjs to call a component on the home page

I am currently facing some challenges with knockoutjs components, as I am following the guidance provided in the official knockout component documentation. Could someone please advise me on how to correctly invoke my widget component on the main page? It ...

What are the benefits of keeping JavaScript and HTML separate in web development?

Recently, I came across the concept of Unobtrusive JavaScript while researching best practices in the realm of JavaScript. One particular point that grabbed my attention was the idea of separating functionality (the "behavior layer") from a web page's ...

Please rewrite the following sentence: "I am going to the store to buy some groceries."

As I navigate through my styled HTML page, an interesting sequence of events unfolds. When the Create New List button is clicked, a pink div emerges, contrasting with the orange hue of the All Lists div. At this moment, a new user has joined but hasn' ...

Struggling with aligning content within a div using CSS grid techniques

I am experimenting with CSS Grid and running into issues with overlaying content. The structure consists of a top-level container defined as a CSS grid (class="container"), followed by a content grid (class="content") that divides into 3 rows (header, labe ...

Pedestrian crossing Cordova experiences delayed response despite ontouchstart attempts to fix it

I have been experiencing a delay issue when using a CSS button with the ":active" pseudo-class on my phone. Every time I click the buttons, there is a noticeable delay before entering the active phase. Here is my CSS code: .btn {...} .btn:active{...} To ...

Modify the date format inside the content of an HTML element or its descendants (excluding their attributes)

I have been trying to reformat some dates using JavaScript. My initial approach was: var regex = /(\d{4})-(\d{2})-(\d{2})/g; $('.container td').each(function() { $(this).html($(this).html().replace(regex, '$3-$2-$1')); ...