Reputation: 17
I am trying to put 2 input elements inside an image element. I set the position of the input elements to absolute and only the left input was entered inside the image element, While the second stayed outside.
I like to know why its happening and I also need a solution for putting the right input inside the image.
.container-fluid {
text-align: center;
position: relative;
}
img {
display: inline;
max-height: 100%;
}
.myB {
position: absolute;
top: 50%;
}
<div class='container-fluid'>
<input class='myB' type='button' value='<'>
<img src="https://www.w3schools.com/w3css/img_mountains.jpg" class="img-fluid" alt="Responsive image">
<input class='myB' type='button' value='>'>
</div>
Upvotes: 0
Views: 59
Reputation: 1
I hope this will be helpfull, basically i set the position of button, or input nevermind, with the size of image. Obviusly the "background" of button element overflows from the image, but if tou set the "position" of element with less px you'll set the arrow in the right position. Sorry for my English..
img{
width:400px;
height:300px;
}
#next,
#prev{
position:absolute;
top:inherit;
}
#next{
left:400px;
}
<button id="prev" type="input" > < </button>
<button id="next" type="input" > > </button>
<img src="https://www.w3schools.com/w3css/img_mountains.jpg" class="img-fluid" alt="Responsive image">
Upvotes: 0
Reputation:
Multiple problems:
inline-block
because you dont want it to cover the whole width.container-fluid {
position: relative;
display:inline-block;
width:auto;
}
img {
max-height: 100%;
}
.myB {
position: absolute;
top: 50%;
}
.myBRight{
right:0px;
}
.myBLeft{
left:0px;
}
<div class='container-fluid'>
<input class='myB myBLeft' type='button' value='<'>
<img src="https://www.w3schools.com/w3css/img_mountains.jpg" class="img-fluid" alt="Responsive image">
<input class='myB myBRight' type='button' value='>'>
</div> <!-- container-fluid -->
Upvotes: 2