html - CSS: Position my text block to the right (fully) of my icon (::before) -


i work on alert messages site , position left icon placed in alert message:

.alert {    padding: 20px;    border-radius: 3px;    -webkit-border-radius: 3px;    -moz-border-radius: 3px;  }  .alert p::before {    content: "";    background: red; /* icon */    width: 20px;    height: 20px;    float: left;    margin-right: 5px;  }  .alert.success {    background-color: rgb(221, 255, 181);    color: rgb(139, 195, 74);  }
<div class="alert success">    <p>hae duae provinciae bello quondam piratico catervis mixtae praedonum servilio pro consule missae sub iugum factae sunt vectigales. et hae quidem regiones velut in prominenti terrarum lingua positae ob orbe eoo monte amano disparantur. hae duae provinciae      bello quondam piratico catervis mixtae praedonum servilio pro consule missae sub iugum factae sunt vectigales. et hae quidem regiones velut in prominenti terrarum lingua positae ob orbe eoo monte amano disparantur.</p>  </div>

enter image description here

as can see, icon placed, text not. text placed right.

enter image description here

since width of pseudo-element known, can add pading-left container, , use absolute positioning icon:

.alert p {   position: relative; /* become containing block of abspos children */   padding-left: 25px; /* push text 25px right */ } .alert p::before {   position: absolute; /* take out-of-flow */   left: 0;            /* place @ left of containing block */ } 

.alert {    padding: 20px;    border-radius: 3px;    -webkit-border-radius: 3px;    -moz-border-radius: 3px;  }  .alert p {    padding-left: 25px;    position: relative;  }  .alert p::before {    content: "";    background: red;    width: 20px;    height: 20px;    margin-right: 5px;    position: absolute;    left: 0;  }  .alert.success {    background-color: rgb(221, 255, 181);    color: rgb(139, 195, 74);  }
<div class="alert success">    <p>hae duae provinciae bello quondam piratico catervis mixtae praedonum servilio pro consule missae sub iugum factae sunt vectigales. et hae quidem regiones velut in prominenti terrarum lingua positae ob orbe eoo monte amano disparantur. hae duae provinciae      bello quondam piratico catervis mixtae praedonum servilio pro consule missae sub iugum factae sunt vectigales. et hae quidem regiones velut in prominenti terrarum lingua positae ob orbe eoo monte amano disparantur.</p>  </div>


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -