<img> sticks out the bottom of its wrapper - html

I have a wrapper wrapping around 3 divs that are inline-block and all three divs are 128px high. There is no padding nor margin anywhere. The first div contains an image and ends up not the same height as the other two (lower by 3.3px).
<div style={{width:"700px",height:"700px",position:"relative",left:"50%",transform:"translateX(-50%)"}}>
<hr style={{width:"100%"}}/>
<div>
<div style={{display:"inline-block",width:"128px",height:"128px",backgroundColor:"grey",position:"relative",top:0}}>
<img style={{width:"100%"}} src="https://screenshotlayer.com/images/assets/placeholder.png"/>
</div>
<div style={{display:"inline-block",height:"128px",width:"*"}}>
<span style={{display:"block"}}>Name of Product</span>
<span style={{display:"block"}}>Quantity: <input type="text" className="form-control" style={{width:"50px",display:"inline-block"}}/></span>
<span style={{display:"block"}}><button className="btn-link">Remove from cart</button></span>
</div>
<div style={{display:"inline-block",height:"128px",float:"right"}}>
<span style={{position:"relative",top:"50%",transform:"translateY(-50%)",display:"block"}}>$$$</span>
</div>
</div>
<hr style={{width:"100%"}}/>
</div>
The code is written in JSX.
I've tried setting the wrapper to 128px, but the <img> is still sticking out the bottom
Why does the <img> act like that?

Add verticalAlign:top to each of the three <div>'s style attributes. This align's inline-block elements along their top edges.
<div style={{width:"700px",height:"700px",position:"relative",left:"50%",transform:"translateX(-50%)"}}>
<hr style={{width:"100%"}}/>
<div>
<div style={{verticalAlign:"top",display:"inline-block",width:"128px",height:"128px",backgroundColor:"grey",position:"relative",top:0}}>
<img style={{width:"100%"}} src="https://screenshotlayer.com/images/assets/placeholder.png"/>
</div>
<div style={{verticalAlign:"top",display:"inline-block",height:"128px",width:"*"}}>
<span style={{display:"block"}}>Name of Product</span>
<span style={{display:"block"}}>Quantity: <input type="text" className="form-control" style={{width:"50px",display:"inline-block"}}/></span>
<span style={{display:"block"}}><button className="btn-link">Remove from cart</button></span>
</div>
<div style={{verticalAlign:"top",display:"inline-block",height:"128px",float:"right"}}>
<span style={{position:"relative",top:"50%",transform:"translateY(-50%)",display:"block"}}>$$$</span>
</div>
</div>
<hr style={{width:"100%"}}/>
</div>
See My inline-block elements are not lining up properly for additional information.

Related

HTML / CSS float left doesn't work on my code

I am currently teaching myself HTML / CSS. After some tutorials I am now building my first own project. I try to structure three images and three texts on my page using CSS.
The structure should look like this:
Text - Image
Image - Text
Text - Image.
I tried to position the images with float: right and float: left respectively. But all three images are positioned on the right again and again.
Can you help me? Thank you very much.
<div class="Food">
<div>
<p class="Foodtext">
fvjkhfhikvfdhilvdlhifbikfddbuukubfkuvbduhvdjhvdfkuvhukufvhjkdfuubfdkuhvhukvvhukfdubbf
</p>
</div>
<div>
<img src=speise.jpg alt="Speise" style="float: right">
</div>
</div>
<h3>Wine</h3>
<div class="Wine">
<p class="Winetext">
fhkvbshukveuvbkdfjvbuvfdsfkufbekfbgkrbkfewrrkgbgburfbuehu
</p>
</div>
<div>
<img src="wein.jpg" alt="Weinregal" style="float: left">
</div>
</div>
<h3>Music</h3>
<div class="Music">
<div>
<p class="Musictext"> vbhuireeehugoreiur8hgeoirorguuhghirruhgfuhkgrhukge</p>
</div>
<div>
<img src="dj.jpg" alt="DJ legt auf" style="float: right">
</div>
</div>
You've floated your images inside divs, by themselves. That's like trying to move to the right inside your clothing. Floated images should have the same parent as the content you want to flow around them.
So just combine the divs. You may even want your images inside the paragraphs.
Also, be sure to use a good editor (or at least run your code through an HTML validator). Either will make structural and semantic mistakes obvious.
<div class="Food">
<div>
<p class="Foodtext">
fvjkhfhikvfdhilvdlhifbikfddbuukubfkuvbduhvdjhvdfkuvhukufvhjkdfuubfdkuhvhukvvhukfdubbf
</p>
<img src="https://via.placeholder.com/100" alt="Speise" style="float: right">
</div>
</div>
<h3>Wine</h3>
<div class="Wine">
<p class="Winetext">
fhkvbshukveuvbkdfjvbuvfdsfkufbekfbgkrbkfewrrkgbgburfbuehu
</p>
<img src="https://via.placeholder.com/100" alt="Weinregal" style="float: left">
</div>
<h3>Music</h3>
<div class="Music">
<div>
<p class="Musictext"> vbhuireeehugoreiur8hgeoirorguuhghirruhgfuhkgrhukge</p>
<img src="https://via.placeholder.com/100" alt="DJ legt auf" style="float: right">
</div>
</div>
This is happening because you are styling the image while your image resides inside a new div.
Try this code instead
<div class="Food">
<div>
<p class="Foodtext">
fvjkhfhikvfdhilvdlhifbikfddbuukubfkuvbduhvdjhvdfkuvhukufvhjkdfuubfdkuhvhukvvhukfdubbf
</p>
</div>
<div style="float: right">
<img src=speise.jpg alt="Speise">
</div>
</div>
<h3>Wine</h3>
<div class="Wine">
<p class="Winetext">
fhkvbshukveuvbkdfjvbuvfdsfkufbekfbgkrbkfewrrkgbgburfbuehu
</p>
</div>
<div style="float: left">
<img src="wein.jpg" alt="Weinregal">
</div>
</div>
<h3>Music</h3>
<div class="Music">
<div>
<p class="Musictext"> vbhuireeehugoreiur8hgeoirorguuhghirruhgfuhkgrhukge</p>
</div>
<div style="float: right">
<img src="dj.jpg" alt="DJ legt auf">
</div>
</div>
do this and it should work you might need to specify the max-width of the divs as well and apply 100% width to the image in case you apply max-width, rest this should be working!

Align Text in a div next to an Image but vertically centered

<div>
<div style='display:inline'>
<img src='https://m.media-amazon.com/images/M/MV5BMjA5MTkzNTY5Ml5BMl5BanBnXkFtZTgwNjU4MzY1MTI#._V1_QL50_SY1000_CR0,0,734,1000_AL_.jpg' height=300px>
</div>
<div style='display:inline'>
Twin Peaks
</div>
</div>
So I have the above image with a text next to it. The thing is that I want the text next to it to appear not on the bottom right but at the middle right/ top right of the image with some space between the image and text. How can I achieve it?
<div>
<div style='display:inline'>
<img src='https://m.media-amazon.com/images/M/MV5BMjA5MTkzNTY5Ml5BMl5BanBnXkFtZTgwNjU4MzY1MTI#._V1_QL50_SY1000_CR0,0,734,1000_AL_.jpg' style='vertical-align:middle' height=300px>
</div>
<div style='display:inline'>
Twin Peaks
</div>
</div>
Solved it by adding vertial-align:middle !
You can use position absolute on the text and then align the text anywhere you want using the top property.
Example:
<div>
<div style='display:inline'>
<img src='https://m.media-amazon.com/images/M/MV5BMjA5MTkzNTY5Ml5BMl5BanBnXkFtZTgwNjU4MzY1MTI#._V1_QL50_SY1000_CR0,0,734,1000_AL_.jpg' height=300px>
</div>
<div style="display:inline; position:absolute;">
Twin Peaks
</div>
</div>
You can achieve it by using flex in the parent. Just set align-items: center
<div style="display: flex; align-items: center;">
<div>
<img src='https://m.media-amazon.com/images/M/MV5BMjA5MTkzNTY5Ml5BMl5BanBnXkFtZTgwNjU4MzY1MTI#._V1_QL50_SY1000_CR0,0,734,1000_AL_.jpg' height=300px>
</div>
<div style="margin-left: 10px;">
Twin Peaks
</div>
</div>
<div>
<div style="float: left;">
<img src="https://m.media-amazon.com/images/M/MV5BMjA5MTkzNTY5Ml5BMl5BanBnXkFtZTgwNjU4MzY1MTI#._V1_QL50_SY1000_CR0,0,734,1000_AL_.jpg" height="300px" />
</div>
<div style="float: left; margin-left: 10px;">
Twin Peaks
</div>
</div>
It'll set your Text top right side of your image.

How add new line after each iteration in thymeleaf?

How can I add new line after each iteration in thymeleaf?
th:each generated content is rendered on a single line.
<div th:each="table: ${mapEntry.value}">
<div>
<span th:text="${table}"></span>
</div>
</div>
You can do it with using <br> or <hr> tag before each statement finish.
<div th:each="table: ${mapEntry.value}">
<div>
<span th:text="${table}"></span>
</div>
<br/>
</div>
mrtasln is correct. Even you can add one more <div> </div> or set some stylesheet with adding padding / margins for bottom.
<div th:each="table: ${mapEntry.value}">
<div>
<span th:text="${table}"></span>
</div>
<div>
</div>
</div>

stack image and span tag next to each other - bootstrap

I want to align both image tag and p span tag next to each other. And I do not want to put them in two different div's to follow the grid system as then it doesn't give me the correct final output that I desire.
Here is my small piece of code that I want to correct: FIDDLE
<div class="row">
<div>
<div class="col-md-9 col-md-offset-3" style="padding-right:0px">
<img src="Images/signin_logo.jpg" width="150" height="110" />
<p> <span style="color:#989898; font-size:36px">Template Fire Sign In</span>
<br /> <span style="color:#A8A8A8; font-size:18px">Please sign in with your credentials now to get access.</span>
</p>
</div>
</div>
</div>
FIDDLE
I want the <p> tag next to the image tag.
Two options
.row p {
display: inline-block;
}
<div class="row">
<div>
<div class="col-md-9 col-md-offset-3" style="padding-right:0px">
<img src="Images/signin_logo.jpg" width="150" height="110" />
<p> <span style="color:#989898; font-size:36px">Template Fire Sign In</span>
<br /> <span style="color:#A8A8A8; font-size:18px">Please sign in with your credentials now to get access.</span>
</p>
</div>
</div>
</div>
or
.row img {
float: left;
}
<div class="row">
<div>
<div class="col-md-9 col-md-offset-3" style="padding-right:0px">
<img src="Images/signin_logo.jpg" width="150" height="110" />
<p> <span style="color:#989898; font-size:36px">Template Fire Sign In</span>
<br /> <span style="color:#A8A8A8; font-size:18px">Please sign in with your credentials now to get access.</span>
</p>
</div>
</div>
</div>
Apply this css --
img, p {
display:inline-block;
}
This will make the img and p tag to be next to each other, as long as both element's width doesn't cross the container's width.

Proper Way to Float Elements

I have the following HTML:
<fieldset>
<legend>Details</legend>
<div class="form-section first">
<div class="abc">
<div class="editor-label">
<label for .../>
</div>
<div class="editor-field">
<input type="text" ... />
</div>
</div>
<div class="def">
...
</div>
<div class="ghi">
...
</div>
</div>
<div class="form-section">
</div>
<div class="form-section last">
</div>
</fieldset>
I have a fieldset that is wrapping all of my form elements. The fieldset contains multiple form sections, which basically hold one "row" of content. The divs in the form sections I want to float to the left:
||||||| ||||||| ||||||| <-- first form section, 3 floated elements
||||||| ||||||||||| <-- second form section, 2 floated elements
What is the proper way to float these elements so that:
1) The second form section occurs on its own line.
2) The second form section can apply a top margin.
I can't seem to get it right. I need the solution to work in IE7. I tried putting a clear: both on the form-section element but it didn't seem to work right. All 5 elements occurred on the same line instead of 2 separate lines.
** EDIT **
I can somewhat get this to work. My issue is the following:
When I float the elements within a container, they essentially have 0 height. This messes up any containers that come after it if they want to apply a top margin.
for the row of three try:
<div style="clear:both; width:100%;">
<div style="float: left;"></div>
<div style="float: left;"></div>
<div style="float: right;"></div>
</div>
<div style="clear:both; width:100%; height:10px;"></div>
<div style="clear:both; width:100%;">
<div style="float: left;"></div>
<div style="float: left;"></div>
</div>
That should get you the desired output.
<fieldset>
<legend>Details</legend>
<div id="section 1">
<span style="height: 500px;">1</span>
<span style="height: 500px;">2</span>
<span style="height: 500px;">3</span>
</div>
<div id="section 2" style="margin-top: 50px;">
<span>4</span>
<span>5</span>
</div>
</fieldset>