i have a parent div which contain two child. i want that first child to be centered while the other to be at the end of flex but using margin auto does center the first child according to the space left for him not according to the size of parent div.i mean margin on left should be different from margin on right as i have second element on the right of first one.so how to make margin calculated responsively or if there another solution to center one element and make the other at end.I would like to apologize for this long question.
HTML
<div class="parent">
<h2 class="firstchild">line of text</h2>
<div class="secondchild">
<form>
<input type="text" placeholder="search.. " name="search">
<span class="searchbutton"><button id="button" type="submit" name="search" >Search</button></span>
</form>
</div>
</div>
parent
.parent{
display: flex;
flex-wrap: wrap;
flex-direction:row;
width: 100%;
first child
.firstchild{
margin-top: 10px;
text-align: center;
margin-bottom: 5px;
margin: 0 auto;
justify-self: center;
position: absolute;
second child
.secondchild {
margin-left: 0px;
margin-bottom: 5px;
margin-right: 0px;
position: relative;
justify-self: flex-end;
Thank you for everyone who replied. maybe i express my question wrongly but i have found the solution using java script the solution is:
<script>
function myFunction() {
var elmnt=document.getElementById('parent');
var w=elmnt.clientWidth;
var m=(w-256.922)/2;
var r=m-240.594;
document.getElementById("child1").style.marginLeft=m+'px';
document.getElementById('child1').style.marginRight=r+'px';
}
window.onresize=myFunction;
</script>
where 256.922 and 240.594 is width of first and second child respectively.