Search code examples
htmlcssyui-pure-css

How to put a div at left or right in pure CSS?


I am new in pure css, it is nice and easy!

My HTML:

<header class="pure-u-1 pure-u-md-1-1">
<div class="pure-u-4-5">

    <div class="left-in-header pure-u-3-8">This should be in left</div>

</div>

</header>

My CSS:

@font-face{
    font-family: 'myfont';
    src: url('myfont.ttf');
}


html, button, input, select, textarea, *, * *,
.pure-g [class *= "pure-u"] {
    /* Set your content font stack here: */
    font-family: 'myfont', Times, "Times New Roman", serif !important;
}

html{
    direction:rtl;
    box-sizing: border-box;

}


*, *:after, *:before{
    box-sizing: inherit;
}

*{
    margin:0;
    padding:0;
}

header{
    color:white;
    background:#b90101;
    background: rgba(200,1,1,0.8);
    margin:0 !important;
    padding:2px 0!important;
}

header > div{
    margin:auto;
    display:block !important;
    background:red;

}

.left-in-header{
    background:green;

}

Now please see the green div with class .left-in-header, I want to put it at the left of its parent! (its size is pure-u-3-8). (My website language is Persian, and Persian is right to left, then my direction is rtl)

And How to put a div in center of it's parent by pure classes?


Solution

  • Give below css property to :

    .pure-u-3-8{
     float:left;
    text-align:left;
    } 
    

    and remove margin:auto from div itslef and its parent if given