Steps to position two divs next to each other within a card:

Currently, I am working on creating a profile details card but I am facing some issues with the grid system. Any assistance or guidance would be highly appreciated.

Desired Output:

Expected Outcome:

Code Snippet:

Answer №1

Check out this technique using Grid:

The method is quite similar, with the key distinction being the grid-template-columns property. I suggest utilizing Flexbox for this particular 1-dimensional scenario, as it is specifically designed to address such issues. Combining Flex and Grid yields optimal results. 😄

.grid-container {
  display: grid;
  width: 300px;
  grid-template-columns: 1fr 3fr;
  column-gap: 25px;
  align-items: center;
  border: 1px solid #f4f4f4;
}

.icon img {
  height: 100px;
}

.info label {
  display: block;
}
<div class="grid-container">
  <div class="icon">
    <img src="https://www.pngall.com/wp-content/uploads/5/Profile-PNG-Clipart.png" />
  </div>
  <div class="info">
    <label>First Name</label>
    <label>Last Name</label>
    <label>Position</label>
    <label>Identification No.</label>
    <label>Email</label>
  </div>
</div>

Answer №2

If you want to enhance the layout, I suggest utilizing Display Flex in the parent container and also changing the labels to block elements so they appear on separate lines.

.flex-container {
  display: flex;
  gap: 30px;
  align-items: center;
  border: 1px solid #f4f4f4;
  width: 300px;
}

.icon img {
  height: 100px;
  
}
.info label {
  display: block;
}
<div class="flex-container">
  <div class="icon">
    <img src="https://www.pngall.com/wp-content/uploads/5/Profile-PNG-Clipart.png" />
  </div>
  <div class="info">
    <label>First Name</label>
    <label>Last Name</label>
    <label>Position</label>
    <label>Identification No.</label>
    <label>Email</label>
  </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

Stylish grey container with crisp white lettering

Just getting started with HTML and I've been working on a project for my class. Here's what I've come up with: <font style="background-color: grey; color: white; display: block">Black and white copies $.10 per page letter/legal size&l ...

The width of a CSS border determines its height, not its width

When I try to use border-width: 100px; to set the horizontal width to 100px, it ends up setting the height to 100px instead. Any help would be greatly appreciated. .border-top-green { border-top: 1px solid #4C9962; border-width: 100px; padding-t ...

Is there a specific HTML tag available to instruct the browser to cache my HTML and/or CSS files for future use?

Up to this point, my research has indicated that enabling JavaScript and CSS browser caching typically requires server side settings such as .htaccess. Is there any HTML tag or configuration within the HTML page or JavaScript that can instruct the browse ...

Obtain the bootstrap CSS file

In all my various projects, I have been utilizing Bootstrap 3 and now I am interested in incorporating Bootstrap 4 cards into my work. However, I am struggling to locate the cards in a css format rather than the scss format. I personally don't think ...

InnerHTML failing to append HTML content

Almost at the finish line with this code! I already have a footer in place, but when the button is clicked, it smoothly slides down along with its contents. Once it's done sliding, I utilize JavaScript to swap out that footer and its contents with a n ...

What is the most effective method to override parent styles while utilizing CSS Modules?

I'm currently using NextJS along with CSS Modules for styling purposes. One of my goals is to adjust the appearance of a component in different scenarios: When it's rendered normally on a page, utilizing props to specify className modifiers. W ...

Displaying left and right div elements alongside each other in HTML/CSS works in Chrome, but not in Safari or Firefox

I've encountered an issue with aligning divs side by side in Firefox and Safari, although it seems to be working perfectly in Chrome. It's a bit tricky to provide all the CSS code as I have different stylesheets for mobile, normal, and print vers ...

Shift the element upwards instead of scrolling down the page

I'm struggling with a design challenge on my website. Currently, the page layout consists of a navigation bar, a header section, and the main body content. I'm trying to achieve a scrolling effect where the body content moves up and over the head ...

Resizing images within a container using Bootstrap to fit the screen dimensions

I am having an issue with my bootstrap page where the tiles adjust position based on screen size. Everything works well except when I try to add images to the tiles along with other content. In the example below, you can see that the first tile has an imag ...

Toggle visibility with JQuery's onClick event

I am looking for a way to toggle the visibility of text that has display: none; in CSS when a button is clicked, as well as clear the input field on the onClick event. Currently, the text remains visible even after it has been displayed. Any assistance wou ...

CSS tricks: Make triangles stand out with unique hover effects

I find myself in a bit of a conundrum! I want to incorporate cursor: pointer into my CSS, but the issue is that it's for a triangle shape. If I were to use the following code: #triangleholder { width: 100px; height: 100px ...

Execute JavaScript code via URL injection

One interesting aspect of the HTML is that it has a feature where it opens a webpage. The specific webpage it opens is determined by the URL, for example: https://mywebsite.com/index.html&audio=disabled In addition to this, there is a useful JavaScri ...

Discover the art of concurrently listening to both an event and a timer in JavaScript

Upon loading the page, a timer with an unpredictable duration initiates. I aim to activate certain actions when the countdown ends and the user presses a button. Note: The action will only commence if both conditions are met simultaneously. Note 2: To cl ...

Extract the URL of the background image from a preexisting <div> element, or append a new attribute to the background-image property

I am facing a challenge in updating the existing background-image with a linear gradient. Currently, my CMS is generating a background-image, but I am unable to adjust the opacity using a linear gradient. My goal is to darken the background-image using CSS ...

Is it possible for browsers to provide autocomplete support for login forms that are loaded via ajax?

I'm having an issue with the autocomplete feature in browsers (IE & FF) not working for my login form. In my webapp using CakePHP and jQuery, I have a login form inside a div that is loaded via AJAX to allow visitors to login or register without relo ...

Unleashing the Power of Wildcards in HTML with XPath

When using XPath to extract values from DOM elements, I've encountered inconsistent XPaths. To select all DOM elements on the same level, I've resorted to some wildcard magic. For instance, in an HTML document, my XPaths may look like: //div[@i ...

What approach should I take to properly naming a navbar structure using BEM methodology?

Here is a snippet of SASS code that I need help transforming using the BEM methodology. How can I rewrite this block of code to follow the BEM naming conventions? .nav__primary ul { border-top: 2px solid $darkgreen; display:block; margin:10p ...

Safari 5.1.7 causing unusual behavior on the website

Despite running smoothly in most browsers, this website goes haywire and crashes on Safari when viewed on a Mac. I've attempted troubleshooting by removing the Google map, CSS transforms, and the Stellar jQuery plugin, but the issue persists. Does any ...

Ways to differentiate between buttons in a button cluster?

I have created a set of 3 buttons using the code from this resource. However, the buttons are currently positioned vertically close to each other as shown in the source code. I would like to adjust the spacing between them. Is there a way to achieve this ...

What is the best way to eliminate the border line from a table?

I'm in the process of creating a table and I would like to know how to remove the border line from it. Below is my code snippet: <div id="table"> <table class="table table-bordered"> <thead> <tr> & ...