How do I centre a div element? (2 Viewers)

Tony Stark

Well-Known Member
Joined
Jan 22, 2025
Messages
223
Location
https://maps.app.goo.gl/pDzZ5pcqruzP5YPS6
Gender
Male
HSC
2025
How do I centre a div element? Example shown:
HTML:
!DOCTYPE html
<head>
    <title>My Handsome Website</title>
</head>
<body>
    <h1>
        Mustache.
    </h1>
    <div>
        <img src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftse4.mm.bing.net%2Fth%2Fid%2FOIP.nr4nS649uiAABvB2BdeoeQHaEK%3Fpid%3DApi&f=1&ipt=1afd701d4c872d504ed2230c96ad3268690e19e1cf4add861ab0c771b7c45e4b&ipo=images">
    </div>
</body>
 

C2H6O

Well-Known Member
Joined
Oct 18, 2024
Messages
928
Gender
Male
HSC
2025
umm no? its been 2 years since i touched html but what is going on here? 😭
 

C2H6O

Well-Known Member
Joined
Oct 18, 2024
Messages
928
Gender
Male
HSC
2025
Ohh wait is it cause the website's handsome so it has a mustache?
 

mickeyd_357

New Member
Joined
Jul 21, 2025
Messages
13
Gender
Female
HSC
2026
Depends what you want to center
If it's the heading try this:
CSS:
.h1 {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
see if that works, you can adjust the translating
 

Users Who Are Viewing This Thread (Users: 0, Guests: 2)

Top