How to keep a range slider within a div in a flex-container
up vote
0
down vote
favorite
Using Javascript, I am trying to create a grid of images, and I'd like to embed a range slider at the bottom of one of the images. To get the grid, I am using flex-container (below I just show two numbers, 1 and 2, as examples, but in the real application they are replaced by images):
<style>
.flex-container {
display: flex;
flex-wrap: wrap;
background-color: LightYellow;
}
.flex-item {
background-color: #f1f1f1;
width: 300px;
margin: 10px;
text-align: center;
line-height: 300px;
font-size: 30px;
}
</style>
<body>
<div class="flex-container">
<div class="flex-item">1</div>
<div class="flex-item"> 2 </div>
</div>
</body>
This part works ok - I get two images side by side, as I want:
Now, suppose I'd like to add a range slide to the second div. So I add this to my styles:
.slidecontainer {
flex: 0 1 auto;
order: 0;
position: relative;
align-items: center;
width: 100%;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 5px;
border-radius: 5px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.slider:hover {
opacity: 1;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 15px;
border-radius: 50%;
background: #4CAF50;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 25px;
height: 15px;
border-radius: 50%;
background: #4CAF50;
cursor: pointer;
}
and then attempt to embed the slider into one of the flex-container divs, say the second one:
<div class="flex-item"> 2
<div class="slidercontainer">
<input type="range" min="1" max="100" value="50" class="slider" id="myRange">
<p>Value: <span id="demo"></span></p>
</div>
</div>
For reasons I don't understand the images explode. Here's what they look like now:
Is there a way to keep the dimensions of the images intact and just add the slider at the bottom of one of the images within its div?
Thanks!
javascript html css css3 flexbox
add a comment |
up vote
0
down vote
favorite
Using Javascript, I am trying to create a grid of images, and I'd like to embed a range slider at the bottom of one of the images. To get the grid, I am using flex-container (below I just show two numbers, 1 and 2, as examples, but in the real application they are replaced by images):
<style>
.flex-container {
display: flex;
flex-wrap: wrap;
background-color: LightYellow;
}
.flex-item {
background-color: #f1f1f1;
width: 300px;
margin: 10px;
text-align: center;
line-height: 300px;
font-size: 30px;
}
</style>
<body>
<div class="flex-container">
<div class="flex-item">1</div>
<div class="flex-item"> 2 </div>
</div>
</body>
This part works ok - I get two images side by side, as I want:
Now, suppose I'd like to add a range slide to the second div. So I add this to my styles:
.slidecontainer {
flex: 0 1 auto;
order: 0;
position: relative;
align-items: center;
width: 100%;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 5px;
border-radius: 5px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.slider:hover {
opacity: 1;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 15px;
border-radius: 50%;
background: #4CAF50;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 25px;
height: 15px;
border-radius: 50%;
background: #4CAF50;
cursor: pointer;
}
and then attempt to embed the slider into one of the flex-container divs, say the second one:
<div class="flex-item"> 2
<div class="slidercontainer">
<input type="range" min="1" max="100" value="50" class="slider" id="myRange">
<p>Value: <span id="demo"></span></p>
</div>
</div>
For reasons I don't understand the images explode. Here's what they look like now:
Is there a way to keep the dimensions of the images intact and just add the slider at the bottom of one of the images within its div?
Thanks!
javascript html css css3 flexbox
To keep the slider contained in the parent div, addmargin:0;
to your.slider
class
– Dacre Denny
Nov 9 at 3:40
the main problem here is theline-height:300px
on your.flex-item
class
– ElefantPhace
Nov 9 at 3:52
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Using Javascript, I am trying to create a grid of images, and I'd like to embed a range slider at the bottom of one of the images. To get the grid, I am using flex-container (below I just show two numbers, 1 and 2, as examples, but in the real application they are replaced by images):
<style>
.flex-container {
display: flex;
flex-wrap: wrap;
background-color: LightYellow;
}
.flex-item {
background-color: #f1f1f1;
width: 300px;
margin: 10px;
text-align: center;
line-height: 300px;
font-size: 30px;
}
</style>
<body>
<div class="flex-container">
<div class="flex-item">1</div>
<div class="flex-item"> 2 </div>
</div>
</body>
This part works ok - I get two images side by side, as I want:
Now, suppose I'd like to add a range slide to the second div. So I add this to my styles:
.slidecontainer {
flex: 0 1 auto;
order: 0;
position: relative;
align-items: center;
width: 100%;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 5px;
border-radius: 5px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.slider:hover {
opacity: 1;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 15px;
border-radius: 50%;
background: #4CAF50;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 25px;
height: 15px;
border-radius: 50%;
background: #4CAF50;
cursor: pointer;
}
and then attempt to embed the slider into one of the flex-container divs, say the second one:
<div class="flex-item"> 2
<div class="slidercontainer">
<input type="range" min="1" max="100" value="50" class="slider" id="myRange">
<p>Value: <span id="demo"></span></p>
</div>
</div>
For reasons I don't understand the images explode. Here's what they look like now:
Is there a way to keep the dimensions of the images intact and just add the slider at the bottom of one of the images within its div?
Thanks!
javascript html css css3 flexbox
Using Javascript, I am trying to create a grid of images, and I'd like to embed a range slider at the bottom of one of the images. To get the grid, I am using flex-container (below I just show two numbers, 1 and 2, as examples, but in the real application they are replaced by images):
<style>
.flex-container {
display: flex;
flex-wrap: wrap;
background-color: LightYellow;
}
.flex-item {
background-color: #f1f1f1;
width: 300px;
margin: 10px;
text-align: center;
line-height: 300px;
font-size: 30px;
}
</style>
<body>
<div class="flex-container">
<div class="flex-item">1</div>
<div class="flex-item"> 2 </div>
</div>
</body>
This part works ok - I get two images side by side, as I want:
Now, suppose I'd like to add a range slide to the second div. So I add this to my styles:
.slidecontainer {
flex: 0 1 auto;
order: 0;
position: relative;
align-items: center;
width: 100%;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 5px;
border-radius: 5px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.slider:hover {
opacity: 1;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 15px;
border-radius: 50%;
background: #4CAF50;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 25px;
height: 15px;
border-radius: 50%;
background: #4CAF50;
cursor: pointer;
}
and then attempt to embed the slider into one of the flex-container divs, say the second one:
<div class="flex-item"> 2
<div class="slidercontainer">
<input type="range" min="1" max="100" value="50" class="slider" id="myRange">
<p>Value: <span id="demo"></span></p>
</div>
</div>
For reasons I don't understand the images explode. Here's what they look like now:
Is there a way to keep the dimensions of the images intact and just add the slider at the bottom of one of the images within its div?
Thanks!
javascript html css css3 flexbox
javascript html css css3 flexbox
edited Nov 9 at 4:04
Michael_B
141k43224335
141k43224335
asked Nov 9 at 3:25
user3490622
13910
13910
To keep the slider contained in the parent div, addmargin:0;
to your.slider
class
– Dacre Denny
Nov 9 at 3:40
the main problem here is theline-height:300px
on your.flex-item
class
– ElefantPhace
Nov 9 at 3:52
add a comment |
To keep the slider contained in the parent div, addmargin:0;
to your.slider
class
– Dacre Denny
Nov 9 at 3:40
the main problem here is theline-height:300px
on your.flex-item
class
– ElefantPhace
Nov 9 at 3:52
To keep the slider contained in the parent div, add
margin:0;
to your .slider
class– Dacre Denny
Nov 9 at 3:40
To keep the slider contained in the parent div, add
margin:0;
to your .slider
class– Dacre Denny
Nov 9 at 3:40
the main problem here is the
line-height:300px
on your .flex-item
class– ElefantPhace
Nov 9 at 3:52
the main problem here is the
line-height:300px
on your .flex-item
class– ElefantPhace
Nov 9 at 3:52
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
Here is the HTML:
<div class="flex-container">
<div class="flex-item">
<img src="https://placeimg.com/300/150/any" alt="">
</div>
<div class="flex-item">
<img src="https://placeimg.com/300/150/any" alt="">
<div class="slidercontainer">
<input type="range" min="1" max="100" value="50" class="slider" id="myRange">
<p>Value: <span id="demo"></span></p>
</div>
</div>
</div>
And here is the CSS:
img {
max-width: 100%;
object-fit: cover;
}
.flex-container {
display: flex;
flex-wrap: wrap;
background-color: LightYellow;
}
.flex-item {
background-color: #f1f1f1;
width: 300px;
margin: 10px;
font-size: 30px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
}
.slidecontainer {
flex: 0 1 auto;
order: 0;
position: relative;
align-items: center;
width: 100%;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 5px;
border-radius: 5px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.slider:hover {
opacity: 1;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 15px;
border-radius: 50%;
background: #4CAF50;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 25px;
height: 15px;
border-radius: 50%;
background: #4CAF50;
cursor: pointer;
}
while this "works" there's still a typo in the css.slidecontainer
vsclass="slidercontainer"
– ElefantPhace
Nov 9 at 3:50
I just copied his html.
– Shuvo
Nov 9 at 3:57
obviously, since you didn't find the typo, just worked around it
– ElefantPhace
Nov 9 at 3:58
add a comment |
up vote
0
down vote
It looks blown out of proportion because of the line-height: 300px;
you have set on the .flex-item
. Take that out and it should look more normal.
To keep the images in its native aspect ratio, simply just set the max-width
to your width value then set width: 100%;
. You probably want to have a div around the image too as IE11 tends to play funny with images as flex elements.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Here is the HTML:
<div class="flex-container">
<div class="flex-item">
<img src="https://placeimg.com/300/150/any" alt="">
</div>
<div class="flex-item">
<img src="https://placeimg.com/300/150/any" alt="">
<div class="slidercontainer">
<input type="range" min="1" max="100" value="50" class="slider" id="myRange">
<p>Value: <span id="demo"></span></p>
</div>
</div>
</div>
And here is the CSS:
img {
max-width: 100%;
object-fit: cover;
}
.flex-container {
display: flex;
flex-wrap: wrap;
background-color: LightYellow;
}
.flex-item {
background-color: #f1f1f1;
width: 300px;
margin: 10px;
font-size: 30px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
}
.slidecontainer {
flex: 0 1 auto;
order: 0;
position: relative;
align-items: center;
width: 100%;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 5px;
border-radius: 5px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.slider:hover {
opacity: 1;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 15px;
border-radius: 50%;
background: #4CAF50;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 25px;
height: 15px;
border-radius: 50%;
background: #4CAF50;
cursor: pointer;
}
while this "works" there's still a typo in the css.slidecontainer
vsclass="slidercontainer"
– ElefantPhace
Nov 9 at 3:50
I just copied his html.
– Shuvo
Nov 9 at 3:57
obviously, since you didn't find the typo, just worked around it
– ElefantPhace
Nov 9 at 3:58
add a comment |
up vote
1
down vote
accepted
Here is the HTML:
<div class="flex-container">
<div class="flex-item">
<img src="https://placeimg.com/300/150/any" alt="">
</div>
<div class="flex-item">
<img src="https://placeimg.com/300/150/any" alt="">
<div class="slidercontainer">
<input type="range" min="1" max="100" value="50" class="slider" id="myRange">
<p>Value: <span id="demo"></span></p>
</div>
</div>
</div>
And here is the CSS:
img {
max-width: 100%;
object-fit: cover;
}
.flex-container {
display: flex;
flex-wrap: wrap;
background-color: LightYellow;
}
.flex-item {
background-color: #f1f1f1;
width: 300px;
margin: 10px;
font-size: 30px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
}
.slidecontainer {
flex: 0 1 auto;
order: 0;
position: relative;
align-items: center;
width: 100%;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 5px;
border-radius: 5px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.slider:hover {
opacity: 1;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 15px;
border-radius: 50%;
background: #4CAF50;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 25px;
height: 15px;
border-radius: 50%;
background: #4CAF50;
cursor: pointer;
}
while this "works" there's still a typo in the css.slidecontainer
vsclass="slidercontainer"
– ElefantPhace
Nov 9 at 3:50
I just copied his html.
– Shuvo
Nov 9 at 3:57
obviously, since you didn't find the typo, just worked around it
– ElefantPhace
Nov 9 at 3:58
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Here is the HTML:
<div class="flex-container">
<div class="flex-item">
<img src="https://placeimg.com/300/150/any" alt="">
</div>
<div class="flex-item">
<img src="https://placeimg.com/300/150/any" alt="">
<div class="slidercontainer">
<input type="range" min="1" max="100" value="50" class="slider" id="myRange">
<p>Value: <span id="demo"></span></p>
</div>
</div>
</div>
And here is the CSS:
img {
max-width: 100%;
object-fit: cover;
}
.flex-container {
display: flex;
flex-wrap: wrap;
background-color: LightYellow;
}
.flex-item {
background-color: #f1f1f1;
width: 300px;
margin: 10px;
font-size: 30px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
}
.slidecontainer {
flex: 0 1 auto;
order: 0;
position: relative;
align-items: center;
width: 100%;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 5px;
border-radius: 5px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.slider:hover {
opacity: 1;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 15px;
border-radius: 50%;
background: #4CAF50;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 25px;
height: 15px;
border-radius: 50%;
background: #4CAF50;
cursor: pointer;
}
Here is the HTML:
<div class="flex-container">
<div class="flex-item">
<img src="https://placeimg.com/300/150/any" alt="">
</div>
<div class="flex-item">
<img src="https://placeimg.com/300/150/any" alt="">
<div class="slidercontainer">
<input type="range" min="1" max="100" value="50" class="slider" id="myRange">
<p>Value: <span id="demo"></span></p>
</div>
</div>
</div>
And here is the CSS:
img {
max-width: 100%;
object-fit: cover;
}
.flex-container {
display: flex;
flex-wrap: wrap;
background-color: LightYellow;
}
.flex-item {
background-color: #f1f1f1;
width: 300px;
margin: 10px;
font-size: 30px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
}
.slidecontainer {
flex: 0 1 auto;
order: 0;
position: relative;
align-items: center;
width: 100%;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 5px;
border-radius: 5px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.slider:hover {
opacity: 1;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 15px;
border-radius: 50%;
background: #4CAF50;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 25px;
height: 15px;
border-radius: 50%;
background: #4CAF50;
cursor: pointer;
}
answered Nov 9 at 3:46
Shuvo
487
487
while this "works" there's still a typo in the css.slidecontainer
vsclass="slidercontainer"
– ElefantPhace
Nov 9 at 3:50
I just copied his html.
– Shuvo
Nov 9 at 3:57
obviously, since you didn't find the typo, just worked around it
– ElefantPhace
Nov 9 at 3:58
add a comment |
while this "works" there's still a typo in the css.slidecontainer
vsclass="slidercontainer"
– ElefantPhace
Nov 9 at 3:50
I just copied his html.
– Shuvo
Nov 9 at 3:57
obviously, since you didn't find the typo, just worked around it
– ElefantPhace
Nov 9 at 3:58
while this "works" there's still a typo in the css
.slidecontainer
vs class="slidercontainer"
– ElefantPhace
Nov 9 at 3:50
while this "works" there's still a typo in the css
.slidecontainer
vs class="slidercontainer"
– ElefantPhace
Nov 9 at 3:50
I just copied his html.
– Shuvo
Nov 9 at 3:57
I just copied his html.
– Shuvo
Nov 9 at 3:57
obviously, since you didn't find the typo, just worked around it
– ElefantPhace
Nov 9 at 3:58
obviously, since you didn't find the typo, just worked around it
– ElefantPhace
Nov 9 at 3:58
add a comment |
up vote
0
down vote
It looks blown out of proportion because of the line-height: 300px;
you have set on the .flex-item
. Take that out and it should look more normal.
To keep the images in its native aspect ratio, simply just set the max-width
to your width value then set width: 100%;
. You probably want to have a div around the image too as IE11 tends to play funny with images as flex elements.
add a comment |
up vote
0
down vote
It looks blown out of proportion because of the line-height: 300px;
you have set on the .flex-item
. Take that out and it should look more normal.
To keep the images in its native aspect ratio, simply just set the max-width
to your width value then set width: 100%;
. You probably want to have a div around the image too as IE11 tends to play funny with images as flex elements.
add a comment |
up vote
0
down vote
up vote
0
down vote
It looks blown out of proportion because of the line-height: 300px;
you have set on the .flex-item
. Take that out and it should look more normal.
To keep the images in its native aspect ratio, simply just set the max-width
to your width value then set width: 100%;
. You probably want to have a div around the image too as IE11 tends to play funny with images as flex elements.
It looks blown out of proportion because of the line-height: 300px;
you have set on the .flex-item
. Take that out and it should look more normal.
To keep the images in its native aspect ratio, simply just set the max-width
to your width value then set width: 100%;
. You probably want to have a div around the image too as IE11 tends to play funny with images as flex elements.
answered Nov 9 at 3:53
Jack Wong
1764
1764
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53219421%2fhow-to-keep-a-range-slider-within-a-div-in-a-flex-container%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
To keep the slider contained in the parent div, add
margin:0;
to your.slider
class– Dacre Denny
Nov 9 at 3:40
the main problem here is the
line-height:300px
on your.flex-item
class– ElefantPhace
Nov 9 at 3:52