I have an alignment problem in html/css. I simplified my problem to this:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<style>
span { display: inline-block; height: 50px; }
span.text { background-color: Yellow;}
span.left, span.right { background-color: Red; width: 20px;}
</style>
</head>
<body>
<span class="left">x</span>
<span class="text">Text comes here</span>
<span class="right">x</span>
</body>
</html>
The output in the browser is as expected:
However, span.left and span.right should not contain any content. They are there for layout purposes only. But when I remove the content ("x") of both spans like this:
<span class="left"></span>
<span class="text">Text comes here</span>
<span class="right"></span>
The output changes to this:
Why is it doing this? What can I do to solve this?
To align things in the inline direction, use the properties which begin with justify- . Use justify-content to distribute space between grid tracks, and justify-items or justify-self to align items inside their grid area in the inline direction.
You can force the content of the HTML <div> element stay on the same line by using a little CSS. Use the overflow property, as well as the white-space property set to “nowrap”.
This is because text-align:center only affects inline elements, and <aside> is not an inline element by default. It is a block-level element. To align it, we will have to use something other than text-align , or turn it into an inline element.
To just center the text inside an element, use text-align: center; This text is centered.
Vertical align is problematic, since it is set to the default baseline. Just change it to top:
span { display: inline-block; height: 50px;vertical-align:top; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With