Disclaimer: I have seen similar threads to this before, but none of which seem to work. I have a layout which looks as follows:
See the pink text? Well, I want that to be aligned with Initial text
after the line break and not start from the beginning of the div which wraps it all around.
As other threads suggested, I have played a bit with display: inline-block
, which only brought the whole pink text down, but did nothing for the alignment. What can I do in this context so that after the lign break it starts from the same spot the Initial text
starts?
here is my current JSX code:
<div style={{width: '500px'}}>
<span>5-</span>
<span className='label-margins label label-default' style={{backgroundColor: 'rgb(FF, AA, AA)'}}>Some Label</span>
<span>
<span className='initial-text'>Initial text</span>
<small className='warning-text'>
Warning text. Blablablablabalbalbalablablablablablablablabalb asbhlablablanl akbadlnalbnda kbadslkds baksdbld
</small>
</span>
</div>
And here is the relevant CSS:
.initial-text {
padding: 0 4px;
}
.warning-text {
color: #ff8080;
padding: 3px 7px;
}
Also, my fully-functional example:
class App extends React.Component {
render() {
return (
<div style={{width: '500px'}}>
<span>5-</span>
<span className='label-margins label label-default' style={{backgroundColor: 'rgb(FF, AA, AA)'}}>Some Label</span>
<span>
<span className='initial-text'>Initial text</span>
<small className='warning-text'>
Warning text. Blablablablabalbalbalablablablablablablablabalb asbhlablablanl akbadlnalbnda kbadslkds baksdbld
</small>
</span>
</div>
)
}
}
ReactDOM.render(
<App />,
document.getElementById('app')
);
.initial-text {
padding: 0 4px;
}
.warning-text {
color: #ff8080;
padding: 3px 7px;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id="app"></div>
2
Answers
Flexbox can do that…apply flexbox to the parent
div
&span
and…Have you try using the dl list? You can adjust the style in order to get what you want using float:
Good luck!