javascript - How to position text and Div on top of eachother and align them in center? -


so can't figure out. i'm trying red vertical box display in middle of page. i've set div's margin auto. , there's div holds centered text. setting margin auto on both. both stacking on top of eachother fine in middle of page.

however want responsive heights. right it's responsive x-axis , not height.

html & css:

.parentdiv {    position: relative;    width: 250px;    height: 450px;    margin: auto;  }  #redbox {    width: 250px;    height: 450px;    background-color: #ff0000;    margin: auto;  }  #cstext {    position: absolute;    top: 45%;    width: 250px;    color: black;    text-align: center;  }
<div class="parentdiv" style="margin-top: auto;">    <div id="cstext" class="textaligncenter">    </div>    <div id="redbox">    </div>  </div>

flexbox great solution this:

.container {    height: 100vh;    display: flex;    flex-direction: column;    align-items: center;    justify-content: center;  }  .red-box {    background-color: red;    padding: 100px;    color: white;  }
<div class="container">    <div class="red-box">text</div>  </div>


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -