CSS positioning without the use of float or margin adjustments -
how can move ul element on the right of browser without using float, or 'guesstimating' element flush right margin through use of tools such margin px/% etc?
.nav li { display: inline; } .nav h1 { background-color: red; display: inline-block; } .nav ul { display: inline-block; border: 1px solid black; } <div class="nav"> <h1>resume</h1> <ul> <li>home</li> <li>portfolio</li> <li>skills</li> <li>experience</li> <li>contact</li> </ul> </div>
depending on browsers need support, can use flexbox.
specifically, want container display: flex;
, justify-content: space-between;
something like:
<div class="nav" style="display: inline-flex; justify-content: space-between;"> ... child items here ... </div>
note flexbox supported on ie11+ , evergreen browsers (chrome, firefox, etc). ie10 has partial support.
see more details regarding browser support.
if need support pre-ie10 browsers, can try using position: absolute;
, right: 0;
on ul
.
flexbox:
.nav { display: inline-flex; //or flex justify-content: space-between; } .nav li { display: inline; } .nav h1 { background-color: red; display: inline-block; } .nav ul { display: inline-block; border: 1px solid black; }
using position:
.nav li { display: inline; } .nav h1 { background-color: red; display: inline-block; } .nav ul { display: inline-block; border: 1px solid black; position: absolute; right: 0; }
Comments
Post a Comment