Skip to content

Commit 97de90d

Browse files
authored
Center images when not using 100% width (#2060)
* Center images when not using 100% width * Add exception for images in lists * Prettify
1 parent c9e680d commit 97de90d

File tree

3 files changed

+50
-11
lines changed

3 files changed

+50
-11
lines changed

docs/syntax/images.md

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ If a page uses an image that exists outside the folder that contains the `toc.ym
1919

2020
![APM](/syntax/images/apm.png)
2121

22-
2322
Or, use the `image` directive.
2423

2524
```markdown
@@ -34,12 +33,41 @@ Or, use the `image` directive.
3433
:width: 250px
3534
:::
3635

36+
### Image centering
37+
38+
Images that are not full width are automatically centered within their container. This is particularly useful when you specify a width constraint:
39+
40+
```markdown
41+
:::{image} /syntax/images/apm.png
42+
:alt: APM Logo
43+
:width: 400px
44+
:::
45+
```
46+
47+
:::{image} /syntax/images/apm.png
48+
:alt: APM Logo
49+
:width: 400px
50+
:::
51+
52+
The image above is centered because it has a width of 400px, which is less than the full container width.
53+
54+
Note that images nested within other content (like lists or admonitions) are not centered:
55+
56+
- First item in the list
57+
- Second item with an image:
58+
59+
:::{image} /syntax/images/apm.png
60+
:alt: APM Logo in list
61+
:width: 400px
62+
:::
63+
64+
- Third item in the list
65+
3766
## Screenshots
3867

3968
Screenshots are images displayed with a box-shadow. Define a screenshot by adding the `:screenshot:` attribute to a block-level image directive.
4069

4170
```markdown
42-
4371
:::{image} /syntax/images/apm.png
4472
:screenshot:
4573
:::
@@ -57,7 +85,6 @@ Here is the same image used inline ![Elasticsearch](/syntax/images/observability
5785

5886
Here is the same image used inline ![Elasticsearch](/syntax/images/observability.png "elasticsearch =50%x50%")
5987

60-
6188
### Inline image titles
6289

6390
Titles are optional making this the minimal syntax required:
@@ -74,7 +101,6 @@ For inline images, the alt text always overrides any title specified in the Mark
74101

75102
![Elasticsearch](/syntax/images/observability.png "Different title =50%x50%")
76103

77-
78104
### Inline image sizing
79105

80106
Image sizing is specified through the title argument. You can specify just the size without needing to provide a redundant title:
@@ -99,24 +125,24 @@ If `H` is omitted `W` is used as the height as well.
99125
When specifying just the size without a title, no space is required before the `=` sign. When combining a title with sizing, a space is required before the `=`:
100126

101127
```markdown
102-
![alt](img.png "=50%") <!-- Just size, no space needed -->
103-
![alt](img.png "My Title =50%") <!-- With title, space required -->
128+
![alt](img.png "=50%") <!-- Just size, no space needed -->
129+
![alt](img.png "My Title =50%") <!-- With title, space required -->
104130
```
105131

106-
107-
108-
### SVG
132+
### SVG
109133

110134
```markdown
111135
![Elasticsearch](/syntax/images/alerts.svg)
112136
```
137+
113138
![Elasticsearch](/syntax/images/alerts.svg)
114139

115140
### GIF
116141

117142
```markdown
118143
![Elasticsearch](/syntax/images/timeslider.gif)
119144
```
145+
120146
![Elasticsearch](/syntax/images/timeslider.gif)
121147

122148
## Asciidoc syntax
@@ -147,11 +173,14 @@ The image carousel directive builds upon the image directive.
147173

148174
:::{image} images/applies.png
149175
:alt: Second image description
176+
150177
### Title is optional - alt text will be used as title if not specified
178+
151179
:::
152180

153181
::::
154182
```
183+
155184
::::{carousel}
156185

157186
:id: nested-carousel-example

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Elastic.Documentation.Site/Assets/markdown/images.css

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
a.image-reference {
44
@apply mt-4 block align-middle;
55
& > img {
6-
@apply block;
6+
@apply mx-auto block;
77
}
88
}
9-
/*
9+
/* Override centering for images in lists */
10+
li a.image-reference > img {
11+
@apply mr-0 ml-0;
12+
}
13+
/*
1014
* tailwind reset makes all images `display: block`
1115
* this resets it to `display: initial`
1216
*/

0 commit comments

Comments
 (0)