html - How to align aside as sidebar? -
i working on page employees biography 1 picture. biography (content) display on left , photo of employee on right sidebar. page have footer full width.
i used css layout page, , float:left
both content , photos , set width divided accordingly, photo (aside) not display on right , appear under content, used display:inline
properties both content , aside. trying display aside
on right side of article
.
article, h1, aside, footer { padding: 20px; } h1 { width: 100%; background-color: gray; } article { width: 60% float: left; display: inline; } aside { width: 40%; float: left; display: inline; } footer { width: 100%; background-color: gray; clear: both; }
<body> <article> <h1>biography</h1> <p>general information goes here</p> <p>rest of information goes here</p> </article> <aside> <h2>employee photo</h2> <img src="http://placehold.it/350x150" /> </aside> <footer> <p>copyright goes here</p> </footer> </body>
a couple of issues should corrected:
you have width set 60% , 40%
article
,aside
, havepadding:20px
, make total width on 100%, easy fix setbox-sizing:border-box
, makes padding part of % width.if set
float:left
on element, turns replaced element,display:inline
orblock
won't take effects.there syntax error, it's missing
;
@ end ofwidth: 60%
.it better set
img {max-width:100%; height:auto;}
, make responsive.
below updated example:
* { box-sizing: border-box; } article, h1, aside, footer { padding: 20px; } h1 { background-color: gray; } article { width: 60%; float: left; } aside { width: 40%; float: left; } footer { background-color: gray; clear: both; } img { max-width: 100%; height: auto; }
<body> <article> <h1>biography</h1> <p>general information goes here</p> <p>rest of information goes here</p> </article> <aside> <h2>employee photo</h2> <img src="http://placehold.it/350x150" /> </aside> <footer> <p>copyright goes here</p> </footer> </body>
Comments
Post a Comment