teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

コード追記

2020/02/13 08:26

投稿

hatena19
hatena19

スコア34367

answer CHANGED
@@ -51,4 +51,72 @@
51
51
  }
52
52
  ```
53
53
 
54
- [動作確認用サンプル](https://codepen.io/hatena19/pen/LYVpmgY)
54
+ [動作確認用サンプル](https://codepen.io/hatena19/pen/LYVpmgY)
55
+
56
+ 質問の追記部分について
57
+ ---
58
+ そのような複雑な仕様になるなら、Flexboxで横並びにするようにすると楽ですね。
59
+ 下記のサンプルはFlexboxのほぼデフォルトの状態ですが、
60
+ 垂直位置やボックスの高さの伸縮など自由に設定できます。
61
+
62
+ ```css
63
+ .tab {
64
+ height: 40px;
65
+ width: 100px;
66
+ }
67
+
68
+ .selected {
69
+ background-color: gray;
70
+ }
71
+
72
+ #container {
73
+ overflow: hidden;
74
+ width: 400px;
75
+ }
76
+
77
+ #slide {
78
+ display: flex;
79
+ flex-wrap: nowrap;
80
+ width: 800px;
81
+ transition: transform 1s ease-in-out 0s;
82
+ -moz-transition: -moz-transform 1s ease-in-out 0s;
83
+ -webkit-transition: -webkit-transform 1s ease-in-out 0s;
84
+ }
85
+
86
+ .box {
87
+ width: 50%;
88
+ }
89
+
90
+ #first {
91
+ background-color: pink;
92
+ }
93
+
94
+ #second {
95
+ background-color: aqua;
96
+ }
97
+
98
+ .move-to-first {
99
+ transform: translateX(0px);
100
+ -moz-transform: translateX(0px);
101
+ -webkit-transform: translateX(0px);
102
+ }
103
+ .move-to-second {
104
+ transform: translateX(-400px);
105
+ -moz-transform: translateX(-400px);
106
+ -webkit-transform: translateX(-400px);
107
+ }
108
+ .box-red {
109
+ width:100px;
110
+ height:100px;
111
+ background-color:red;
112
+ }
113
+ .box-blue {
114
+ width:100px;
115
+ height:100px;
116
+ background-color:blue;
117
+ }
118
+ ```
119
+ [動作確認用サンプル](https://codepen.io/hatena19/pen/LYVpoOb)
120
+
121
+ Flexboxの詳細は下記を参照してください。
122
+ [もう迷わない!CSS Flexboxの使い方を徹底解説 | Web Design Trends](https://webdesign-trends.net/entry/8148#_align-self)