I want to right and left align a list but i'm not sure the best way to do this with html and css.
I want it to look something like this.
Name: John Doe
Email: someone@example.com
Birthday: January 01, 1971
Gender: Male
I want to right and left align a list but i'm not sure the best way to do this with html and css.
I want it to look something like this.
Name: John Doe
Email: someone@example.com
Birthday: January 01, 1971
Gender: Male
You can use the description list tag, fiddle here: http://jsfiddle.net/jmhk9bjs/ more info here https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dl
It will be something like this
<dl>
<dt>
Name
</dt>
<dd>
John Doe
</dd>
</dl>
CSS
dl dt, dl.inline dd {
float: left;
}
dl dd + dt, dl.inline dd + dd {
clear: left
}
dl.inline dd + dd {
float: none
}
dl.inline dt {
font-weight: bold
}
with a simple list, you may use class
and pseudo elements : DEMO
<ul class="centerhem">
<li class="Name">John doe</li>
<li class="Email"><span class="Hide" data-name="J-doe" data-com="domain.org"></span></li>
<li class="Birthday">January, 01, 01</li>
<li class="Gender">Male</li>
</ul>
And some style:
.centerhem {
list-style-type:none;
display:table;
border:solid;
padding:0;
margin:1em auto;
}
.centerhem li:before {
content:attr(class)' : ';
display:inline-block;
width:5em;
text-align:right;
margin-right:0.25em;
color:#A56F10;
}
li {
color:#1A97D4;
width:15em;
}
li span.Hide:before {
content:attr(data-name)'@'attr(data-com);
}
Class can be reused any time.
data-attributes within the span is to try to hide email from spammer harvest.
You can also use floating divs: http://jsfiddle.net/ctwheels/pnh920qn/
HTML
<div id="left">
<div>Name</div>
<div>Email</div>
<div>Birthday</div>
<div>Gender</div>
</div>
<div id="right">
<div>John Doe</div>
<div>someone@example.com</div>
<div>January 01, 1971</div>
<div>Male</div>
</div>
CSS
div {
color:#05BEE3;
}
#left {
float:left;
}
#left>div{
text-align:right;
}
#left>div:after{
content:":";
}
#right {
float:left;
margin-left:10px;
}