What is the best way to position an element in the center of the screen

What is the best way to vertically center a button within a div? Click here for an image of the issue
I recently started learning HTML & CSS and I am struggling to align a button in the vertical center of a div. Text-align:center doesn't seem to be working for me.
Another question: How can I ensure that the outer div is the same height as the middle-div?

p {
  font-family: Roboto, Arial;
  margin-top: 0;
  margin-bottom: 0;
}

.user {
  font-weight: 500;
}

.photo {
  width: 46px;
  border-radius: 28px;
}

.user-name,
.user-description,
.status {
  width: 150px;
}

.avatar,
.middle-div,
.follow {
  display: inline-block;
}
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
<div>
  <div class="avatar">
    <img class="photo" src="av1.jpg">
  </div>
  <div class="middle-div">
    <div>
      <div class="user-name">
        <p class="user">
          oliver
        </p>
      </div>
      <div class="user-description">
        <p class="user-desc">
          the cat
        </p>
      </div>
      <div class="status">
        <p class="status-desc">
          Popular
        </p>
      </div>
    </div>
  </div>
  <div class="follow">
    <button class="follow-button">Follow</button>
  </div>
</div>

Answer №1

After reviewing your code, I have made some modifications. I included the card class on the card and converted it into a flexbox by incorporating display: flex; along with align-items: center;.

p {
  font-family: Roboto, Arial;
  margin-top: 0;
  margin-bottom: 0;
}

.username {
  font-size: 16px;
}

.photo {
  width: 46px;
  border-radius: 28px;
}

.user-name,
.user-description,
.status {
  width: 150px;
}
.card {
  display: flex;
  align-items: center;
}
<div class="card">
  <div class="avatar">
    <img class="photo" src="av1.jpg">
  </div>
  <div class="middle-div">
    <div>
      <div class="username">
        <p class="user">
          Oliver
        </p>
      </div>
      <div class="user-description">
        <p class="user-desc">
          The cat lover
        </p>
      </div>
      <div class="status">
        <p class="status-desc">
          Influencer
        </p>
      </div>
    </div>
  </div>
  <div class="follow">
    <button class="follow-button">Follow</button>
  </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

Display only the initial word in a hidden input value of an HTML document using NodeJS Express

I have a Node.js application that utilizes EJS as its template engine. On multiple pages, I incorporate hidden inputs and retrieve their values using req.body. Although my body parser in Express is configured correctly, I've noticed an issue where hid ...

Tips for adjusting the color of multiple <a> tags?

One issue I am facing is the color of the .row a element impacting my contact link, making it white. Despite attempting to change it to red, the color remains unchanged, but upon hovering it turns green. .row a { color: white; text-decoration: non ...

Tips for replacing spaces with &nbsp; in a string using ReactJS and displaying it in HTML

<div className="mt-2 font-sidebar capitalize"> {item.title} </div> item.title can vary and be any string retrieved from the backend, such as "all products", "most liked", "featured items", etc. I am looking for a solution to subst ...

Is it possible to alter the css twice through the action of clicking on two individual buttons

One feature I have in my interface allows users to click on the edit button to bring up borders and change the background color of other divs. Once the edit button is pressed, it is replaced by cancel and save buttons. The goal is for the borders and backg ...

Mediawiki functionality experiencing issues within iframe display

Currently, I am working with MediaWiki built in PHP. Due to certain reasons, I have to embed this application within an iframe. All functionalities are running smoothly except for the Edit link for pages. The issue arises when I try to access the second li ...

Having difficulty getting the HTML table formatting and colors to display properly

Explore the custom netting options for baseball and softball batting cages here. It seems like there might be an issue with displaying tables and background colors in the description field. We'll look into it! ...

What is the reason for background images not loading when using `display: none`?

I'm really struggling to understand this puzzle: When the page loads, will mypic.jpg be downloaded by the browser? #test1 { display: none; } #test2 { background-image: url('http://www.dumpaday.com/wp-content/uploads/2017/01/random-pic ...

What is the best way to constrain the ratio of a full-width image display?

I am in need of a solution for displaying an image at full width inside a frame with a 16:9 aspect ratio. The image needs to be centered within the frame and adjust responsively when resizing the screen. My preference is to achieve this using just CSS. ...

How to truncate lengthy text in a table on mobile screens using Bootstrap 4

I am currently working on a responsive table that needs to display correctly on both desktop and mobile devices. However, I have run into an issue where long text in the table gets truncated on mobile devices, compromising the responsiveness of the design. ...

Clickable PDF Button for Quick Website Access

Is there a way to create a button on an HTML page that remains functional when the page is saved as a PDF? I want the button to link to a webpage so that users can click on it in the PDF and be redirected to the link. ...

Ways to modify the height of a button without impacting other buttons?

My goal is to create a calculator that looks like the image attached below: However, I'm having trouble aligning the equal button properly. How can I adjust it to match the equal button in the image? Here's the code snippet I'm currently w ...

Transform the styles from a React component into Cascading Style Sheets

I have been tasked with transitioning all the styles from the JavaScript file to the CSS file while ensuring the design remains intact. I am facing an issue where using the CSS styles breaks the search field design. The original design can be seen here: S ...

Enhance your Magento store with a personalized layout update

Is there a way to call a stylesheet from my skin folder instead of pointing to my base path? Right now I have <reference name="head"> <action method="addCss"> <stylesheet>yourtheme/css/red.css</stylesheet> < ...

Creating a full-width tab card with Bootstrap-Vue: A step-by-step guide

I stumbled upon something similar in the documentation for bootstrap-vue: A card with tabs: Now, how can I style the tabs to look like this: This is my current code: <b-card no-body> <b-tabs card> <b-tab title="Tab 1" active& ...

Enabling users to create custom layouts by writing CSS that is stored in the database

I am currently in the process of developing a web application using Ruby on Rails that allows users to customize their personal blog pages. I am seeking advice on the most effective ways to achieve this. While I believe Liquid for templating is a good opt ...

Steps for splitting a numbered list and adding an image above each item:

I have a challenge I'm trying to tackle with my list: My goal is to create a long, numbered list that is divided into different sections I also want to include an image within each list item and have it display above the numbered title of the sectio ...

Website experiencing issues with moderating Facebook comments

I recently added a Facebook comments box to my website in the footer. Although it is visible, I am unable to moderate it. Furthermore, the comments are not showing up in the comments queue panel at https://developers.facebook.com/tools/comments. I am us ...

Discovering the presence of line breaks

I have searched extensively on Google, but I am struggling to find a definitive answer. My goal is to create an email simulation where users can input text into a textarea and save it to the database. They should then be able to return to the page later a ...

Adjust the GTK3 tooltip color exclusively for Eclipse when it is operating on Ubuntu

I am using Eclipse Mars on Ubuntu 15.04 and looking to customize the GTK3 tooltip fg/bg color specifically for Eclipse without impacting other applications. I have come across instructions for changing this color system-wide, but I need guidance on how t ...

Is there a way to create a multi-page website simulation using jQuery?

My current project involves creating a single page website, but I am looking to give the illusion of a multi-page site by using CSS/jQuery to hide and reveal different sections when specific links in the navigation menu are clicked. Here is the code snipp ...