html - Text does not align left inside a div -
i'm trying align span
element inside div
it's left border. code:
.bikoret { width:40%; border:1px solid black; } .bikoret > .content { width:80%; padding:0; word-wrap: break-word; } .bikoret > .username { text-align:center; padding-left:1%; padding-right:1%; position:relative; left:0; border-top:1px inset; }
<div dir="rtl" style="text-align:center; background-color:white; border-top:1px; border-style:inset; margin-top:4px; padding-left:10px; padding-right:10px;" runat="server" id="takzir"> <center> <div class='bikoret'> <div class='content'> centered </div> <span class='username'>this aligned left</span> </div> </center> </div>
how can fix it? tried now..
here how approach this.
first, define class parent block, .parent
, current styling , add text-align: center
.
for child element .bikoret
, apply display: inline-block
means element centered within parent. important: set text-align: left
.
for child elements of .bikoret
, treat each element separately.
for .content
, set width auto
, text-align: center
center text.
for .username
, inline element, , because of text-align: left
on parent (.bikoret
) sits left edge want.
.parent { text-align: center; background-color: white; border-top: 1px; border-style: inset; margin-top: 4px; padding-left: 10px; padding-right: 10px; } .bikoret { width: 40%; border: 1px solid black; display: inline-block; text-align: left; } .bikoret > .content { text-align: center; width: auto; /* why 80%? */ padding: 0; word-wrap: break-word; background-color: yellow; } .bikoret > .username { padding-left: 1em; /* % padding won't work here... */ padding-right: 1em; border-top: 1px inset; background-color: beige; }
<div class="parent"> <div class='bikoret'> <div class='content'>this centered</div> <span class='username'>this aligned left</span> </div> </div>
note: center
tag deprecated , should not used.
Comments
Post a Comment