Copy link to clipboard
Copied
Brand new to DW. Having performed due dilligence first and searched previous discussions for a useful answer, I must submit that this thread:
Solved: Re: Centering an image in Dreamweaver - Page 2 - Adobe Community - 2489936
is outdated, because none of the suggestions therein seem to work with CC 21.4.
Let's fast-forward to 2024, shall we? I have been all over the web looking for the inexplicably hidden secret as to how to center a simple image.
I have tried internal, extermal, and inline CSS containing .center .
I have tried adding the attribute class="center" to the img tag.
I suppose the next thing I'll have to do is reach for my VISA and pay somebody off, because I don't know what else to do.
Here is what I have:
Funny...in HTML5 all you had to do was add align=center to the img tag. Guess it wasn't cryptic enough.
Just to tick it off the list, the following didn't work either:
.container {
display: grid;
place-content: center;
}Assuming, of course, that this was intended to be placed into a CSS (correct term, usage?) style that defined img. Precise placement was not specified.
By @WHough
No you don't attached the css to the image, you attach it to the parent container the image is located in:
<div class="centerContent">
<img src="myImage.jpg" alt="" width="400" height="200">
</div>
.centerContent {
display: grid;
...Copy link to clipboard
Copied
Well it looks like you are using Bootstrap and setting the column to 50% of the browser window width by using col-md-6 so your image won't be horizontally centered on the screen if that is what you require.
The class of text-center set on the div which contains the image should be sufficient to center the image on screen IF the div which the image is located within is set to the full width of the screen and not 50% of it.
Follow the advised Bootstrap set up which requires you to enclose your div in a 'container' or 'container-fluid' div and 'row' div:
<div class='container'>
<div class='row'>
Your content should be inserted here.
</div>
</div>
Copy link to clipboard
Copied
Just so that you are correctly informed about Bootstrap, this is how it works:
In other words, an image needs to be contained within a Column.
To centre an image, the image needs to be transformed from an inline-block level to a block level. This can be done using the Bootstrap d-block class. Then, the image needs to have a left margin set to auto. This will push the image to the right. Adding a right margin to auto, will push the image to the center.
The HTML will look like
<div class="container">
<div class="row">
<div class="col">
<img class="d-block mx-auto" src="/images/myImage.webp" width="200" height="100" alt="My Image">
</div>
</div>
Copy link to clipboard
Copied
To centre an image, the image needs to be transformed from an inline-block level to a block level. This can be done using the Bootstrap d-block class. Then, the image needs to have a left margin set to auto. This will push the image to the right. Adding a right margin to auto, will push the image to the center.
By @BenPleysier
This will do it without the necessity to use d-block/mx-auto on the img tag
<div class="container">
<div class="row">
<div class="col text-center">
<img src="yourImage.jpg" alt="" width="200" height="100">
</div>
</div>
</div>
OR better still, without Bootstrap:
.container {
display: grid;
place-content: center;
}
<div class="container">
<img src="yourImage.jpg" alt="" width="200" height="100">
</div>
Copy link to clipboard
Copied
Wish I knew what bootstrap was. Brand new, remember (see original post).
Copy link to clipboard
Copied
Wish I knew what bootstrap was. Brand new, remember (see original post).
By @WHough
You're using Bootstrap css classes in your code - col-md-6, text-center, so we are assuming you are using Bootstrap to construct your html.
Bootstrap is a css, javacript front end library for creating, building responsive web applications.
Copy link to clipboard
Copied
I appreciate all the suggestions; unfortunately, none of them worked. I have included a screenshot to prove it.
As you can see, the image did not horizontally center.
I guess I need to be more specific regarding my experience with DW: None. Zero. Nada. Perhaps a few hours at best. So much for terms such as "bootstrap", "block-level", and so forth. The last time I attempted any kind of web coding was HTML5 and that was nearly a decade ago.
Look upon my attempt and see if you can tell me what I left out. Perhaps a default setting in DW that I need to turn off? I'm starting to wonder if I'm going to have to go questing for a plug-in next.
Copy link to clipboard
Copied
Just to tick it off the list, the following didn't work either:
.container {
display: grid;
place-content: center;
}
Assuming, of course, that this was intended to be placed into a CSS (correct term, usage?) style that defined img. Precise placement was not specified.
Copy link to clipboard
Copied
Just to tick it off the list, the following didn't work either:
.container {
display: grid;
place-content: center;
}Assuming, of course, that this was intended to be placed into a CSS (correct term, usage?) style that defined img. Precise placement was not specified.
By @WHough
No you don't attached the css to the image, you attach it to the parent container the image is located in:
<div class="centerContent">
<img src="myImage.jpg" alt="" width="400" height="200">
</div>
.centerContent {
display: grid;
place-content: center;
}
Copy link to clipboard
Copied
Good to know; but here the point is, had they stated that to begin with...
- WH
Copy link to clipboard
Copied
Look, people.
Consider: I am a neophyte DW user, trying to extropolate from the Adobe Community a method for centering an image on a webpage. I see very little mystery or hidden meaning in that.
Yet, for all the very appreciated time and effort that went into the varying suggestions, none of them has worked. We are talking about centering a simple PNG on a basic webpage. So I just pray that someone -- anyone -- can understand why it has been a challenge for me to keep my frustration in check, and another prayer that someone -- anyone -- will amble along and provide me with the correct fix.
- WH
Copy link to clipboard
Copied
We can't see what else you have going on. So I won't waste your time or mine playing 20 questions.
To horizontally center an element, you need just 3 things:
1. A valid document type.
2. A stated container width.
3. Auto margins.
Working demo with 2 examples. Example 1 has limited image width; example 2 has unlimited image width.
HTML & CSS Code: Copy & paste into a new, blank document.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Horizontal Centering Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--DEMO STLYES-->
<style>
body {
background:antiquewhite;
color:darkcyan;
font-family:Gotham, "Helvetica Neue", Helvetica, Arial, "sans-serif";
font-size: 1.5rem;
}
.container {
width: 75%;
margin: 0 auto;
padding:2%;
border: 3px solid silver;
background-color:honeydew;
}
.example1 img {max-width:100%;}
.example2 img {width:100%;}
</style>
</head>
<body>
<div class="container example1">
<h3>Example 1:</h3>
<img src="https://dummyimage.com/900x400" alt="placeholder">
</div>
<div class="container example2">
<h3>Example 2:</h3>
<img src="https://dummyimage.com/900x400" alt="placeholder">
</div>
</body>
</html>
Copy link to clipboard
Copied
"We can't see what else you have going on. So I won't waste your time or mine playing 20 questions."
Unsure what this means, since in both cases that I've included an image, it showed the entirety of my DW workspace, including a split screen with the current content. Nothing else outside that.
And, not to put too fine a point on it , I daresay there is nothing in the above example that demonstrates how to center an image.
Therefore, I can only assume:
1) You all know a simple answer, and won't reveal it to me, for whatever reasons your propensity for mind games dictates,
2) None of you know the answer, because few if any of you are the experts you claim to be, or
3) There really isn't an answer; DW or CSS or the new HTML or whatever simply exluded the functionality for centering an image.
This place is unbelievable. It's like asking a hunk of plastic to perform a simple calculation. Truth be told, I suspected all along that I wasn't going to get any real help, but I had to check it off the list. I'll find my answers elsewhere. I only wish there was a way to mark the post as unsatisfactory.
Copy link to clipboard
Copied
In a technical user-to-user forum like this one, all layout questions come down one thing: YOUR CODE. Nothing else matters.
For future reference, the quickest & most accurate way to solicit help here is:
1. post a brief description of the problem and the URL to your online page.
That's it! No other details are required. It really is that simple. 😁
Any questions?
Copy link to clipboard
Copied
This place is unbelievable. It's like asking a hunk of plastic to perform a simple calculation. Truth be told, I suspected all along that I wasn't going to get any real help, but I had to check it off the list. I'll find my answers elsewhere. I only wish there was a way to mark the post as unsatisfactory.
By @WHough
Its advisable to go and learn some simple html and css before you post and you won't be so frustrated. Centering an image is a 30 seconds exercise for a child if they are paying attention. Sorry we couldn't be of any help........next one please.
Copy link to clipboard
Copied
I don't expect we'll hear back from him.
Copy link to clipboard
Copied
That's the thanks that you get from arrogant pricks.
Copy link to clipboard
Copied
Fortunately, they aren't a frequent problem.