html - how to align the content of a box -


i have 2 paragraphs in html code shows:

<div class="mainhead">     <p class="paragraph">this paragraph</p>     <div class="info">             <p><span class="infomail">info@zazzoo.co.za</span> <span class="infonumber">082 888 7385 </span></p>         </div>   </div><!-- end of mainhead -->  

and following css:

.mainhead {   background-color: #d9edf7;   width: 100%;   display: flex; } .info{   text-align: right; } .mainhead .parapgraph{     text-align: center; } 

how can align div info far right , keep paragraph in center?

here goes jsfiddle :https://jsfiddle.net/wosley_alarico/60a8qw5l/

to make p centered , not affected width of .info can use position: absolute , add float: right on .info. can use overflow: hidden clear float , fix height.

.mainhead {    background-color: #d9edf7;    width: 100%;    position: relative;    overflow: hidden;  }  .mainhead > p {    position: absolute;    top: 50%;    left: 50%;    transform: translate(-50%, -50%);    margin: 0;  }  .info {    float: right;  }
<div class="mainhead">    <p>this paragraph</p>    <div class="info">      <p><span class="infomail">info@zazzoo.co.za</span>  <span class="infonumber">082 888 7385 </span>      </p>    </div>  </div>

if want center paragraph in space left when subtract width of .info can use flexbox , add margins auto

.mainhead {    background-color: #d9edf7;    display: flex;  }  .mainhead > p, .info {    margin-left: auto;  }
<div class="mainhead">    <p>this paragraph</p>    <div class="info">      <p><span class="infomail">info@zazzoo.co.za</span>  <span class="infonumber">082 888 7385 </span>      </p>    </div>  </div>


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -