回答編集履歴

1

コード追記

2022/09/28 11:16

投稿

hatena19
hatena19

スコア33722

test CHANGED
@@ -1,10 +1,11 @@
1
1
  bootstrapを使っているという前提で、とりあえず、
2
2
 
3
+ **親要素(.flex)の全体の幅からbの幅を引いた幅で中央配置**
3
4
  ```html
4
5
  <div class="container">
5
6
  <div class="row mx-auto text-center">
6
7
  <div class="col-12">
7
- <div class="d-flex">
8
+ <div class="flex d-flex">
8
9
  <p class="ms-auto me-auto">A</p>
9
10
  <p class="">B</p>
10
11
  </div>
@@ -17,5 +18,28 @@
17
18
  .flex{
18
19
  background:lightblue;
19
20
  }
20
-
21
21
  ```
22
+ ---
23
+ **親要素(.flex)の全体の幅に対して中央配置**
24
+ ```html
25
+ <div class="container">
26
+ <div class="row mx-auto text-center">
27
+ <div class="col-12">
28
+ <div class="flex d-flex justify-content-center">
29
+ <p class="">A</p>
30
+ <p class="">B</p>
31
+ </div>
32
+ </div>
33
+ </div>
34
+ </div>
35
+ ```
36
+ ```css
37
+ .flex{
38
+ background:lightblue;
39
+ position: relative;
40
+ }
41
+ .flex p:last-child {
42
+ position: absolute;
43
+ right: 0;
44
+ }
45
+ ```