html - Aligning inline-block center -



html - Aligning inline-block center -

what easiest way center align inline-block element?

ideally, don't want set width elements. way depending on text inputted within elements, inline-block element expand new width without having alter width within css. inline-block elements should centered on top of 1 (not side side), text within element.

see code below or see on jsfiddle.

the current html:

<div> <h2>hello, john doe.</h2> <h2>welcome , have wonderful day.</h2> </div>

the current scss:

@import url(http://fonts.googleapis.com/css?family=open+sans:400,300,600); body { margin: 0 auto; background: rgba(51,51,51,1); font-family: 'open sans', sans-serif; } div { width: 100%; height: auto; margin: 15% 0; text-align: center; h2 { margin: 0 auto; padding: 10px; text-align: center; float: left; clear: left; display: inline-block; &:first-child { color: black; background: rgba(255,255,255,1); } &:last-child { color: white; background: rgba(117,80,161,1); } } }

adding br between 2 elements , taking out float: left/clear: left may easiest way; however, curious if there way going this.

like this? http://jsfiddle.net/bcl023ko/3/ remove float:left left , add together margin: 0 auto center element. or else looking for?

html center centering css

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -