\n","author":{"@type":"Person","name":"ProcolHarum"},"upvoteCount":0,"answerCount":3,"acceptedAnswer":{"@type":"Answer","text":"
So you need to add position: relative
to your parent container, then add position absolute
to the box-dynamic
element. This will allow the element to be pulled out of the normal flow of the document and placed in the document relative to the closest parent with a position of relative. Then you need to position it with the left/right/top and/or bottom properties.
I use top: 60px
and left: 20%
in the example below.
.box{\n position: relative; /* added */\n width: 100vw; /* added */\n height: 100vh; /* added */\n min-height: 1080px; /* this is only to mimic a larger background like your map */\n}\n\n#box-dynamic {\n width: 420px;\n line-height: 25px;\n background: rgba(0, 0, 0, 0.2);\n position: absolute;\n z-index: 500 !important;\n -ms-transition: all 0.3s ease-out;\n -moz-transition: all 0.3s ease-out;\n -webkit-transition: all 0.3s ease-out;\n -o-transition: all 0.3s ease-out;\n transition: all 0.3s ease-out;\n position: absolute; /* added */\n top: 60px; /* added */\n left: 20%; /* added */\n /* removed float and bottom */\n}\n\n#box-dynamic.minimize {\n height: 50px;\n line-height: 5px;\n}\n\n#box-dynamic h1 {\n margin-right: 5px;\n color: #fff;\n font-size: 20px;\n font-family: 'Roboto Condensed', sans-serif;\n margin-left: 5px;\n -ms-transition: all 0.3s ease-out;\n -moz-transition: all 0.3s ease-out;\n -webkit-transition: all 0.3s ease-out;\n -o-transition: all 0.3s ease-out;\n transition: all 0.3s ease-out;\n}\n\n#box-dynamic.minimize h1 {\n font-size: 20px;\n text-align: center;\n}\n\n#box-dynamic p {\n color: white;\n font-size: 15px;\n line-height: 1.4;\n margin-left: 5px;\n font-family: 'Roboto Condensed', sans-serif;\n -ms-transition: all 0.3s ease-out;\n -moz-transition: all 0.3s ease-out;\n -webkit-transition: all 0.3s ease-out;\n -o-transition: all 0.3s ease-out;\n transition: all 0.3s ease-out;\n}\n\n#box-dynamic.minimize p {\n font-size: 0px;\n}\n\n#box-dynamic small {\n color: #ccc;\n font-size: 11px;\n font-family: 'Roboto Condensed', sans-serif;\n margin-left: 5px;\n margin-top: 0;\n -ms-transition: all 0.3s ease-out;\n -moz-transition: all 0.3s ease-out;\n -webkit-transition: all 0.3s ease-out;\n -o-transition: all 0.3s ease-out;\n transition: all 0.3s ease-out;\n}\n\n#box-dynamic.minimize small {\n font-size: 10px;\n margin-right: 5px;\n float: right;\n}\n\n#box-dynamic img {\n float: left;\n width: 0;\n height: 0;\n visibility: hidden;\n -ms-transition: all 0.3s ease-out;\n -moz-transition: all 0.3s ease-out;\n -webkit-transition: all 0.3s ease-out;\n -o-transition: all 0.3s ease-out;\n transition: all 0.3s ease-out;\n}\n\n#box-dynamic.minimize img {\n float: left;\n width: 50px;\n height: 50px;\n visibility: visible;\n}
\r\n<div class=\"box\">\n <div id=\"box-dynamic\" onclick=panelView()>\n <h1>This is my title</h1>\n <p>few words about my paragraph so it goes like this...</p>\n <br><br>\n </div>\n</div>
\r\nReputation: 741
CSS complete newbie here. I'm trying to push my 'box' to the top of the page. I played with the css file but couldn't figure it out how to place it perfectly. I think the challenge I'm facing is the height and margin. I have copied the css from codepen here.
My objective is to move the box from the bottom to (almost) the top.
#box-dynamic {
width: 420px;
line-height: 25px;
background: rgba(0, 0, 0, 0.2);
float: left;
position: absolute;
bottom: 0;
z-index: 500 !important;
-ms-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-webkit-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
}
#box-dynamic.minimize {
height: 50px;
line-height: 5px;
}
#box-dynamic h1 {
margin-right: 5px;
color: #fff;
font-size: 20px;
font-family: 'Roboto Condensed', sans-serif;
margin-left: 5px;
-ms-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-webkit-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
}
#box-dynamic.minimize h1 {
font-size: 20px;
text-align: center;
}
#box-dynamic p {
color: #ccc;
font-size: 15px;
line-height: 1.4;
margin-left: 5px;
font-family: 'Roboto Condensed', sans-serif;
-ms-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-webkit-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
}
#box-dynamic.minimize p {
font-size: 0px;
}
#box-dynamic small {
color: #ccc;
font-size: 11px;
font-family: 'Roboto Condensed', sans-serif;
margin-left: 5px;
margin-top: 0;
-ms-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-webkit-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
}
#box-dynamic.minimize small {
font-size: 10px;
margin-right: 5px;
float: right;
}
#box-dynamic img {
float: left;
width: 0;
height: 0;
visibility: hidden;
-ms-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-webkit-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
}
#box-dynamic.minimize img {
float: left;
width: 50px;
height: 50px;
visibility: visible;
}
<div class="box">
<div id="box-dynamic" onclick=panelView()>
<h1>This is my title</h1>
<p>few words about my paragraph so it goes like this...</p>
<br><br>
</div>
</div>
Upvotes: 0
Views: 3024
Reputation: 8610
So you need to add position: relative
to your parent container, then add position absolute
to the box-dynamic
element. This will allow the element to be pulled out of the normal flow of the document and placed in the document relative to the closest parent with a position of relative. Then you need to position it with the left/right/top and/or bottom properties.
I use top: 60px
and left: 20%
in the example below.
.box{
position: relative; /* added */
width: 100vw; /* added */
height: 100vh; /* added */
min-height: 1080px; /* this is only to mimic a larger background like your map */
}
#box-dynamic {
width: 420px;
line-height: 25px;
background: rgba(0, 0, 0, 0.2);
position: absolute;
z-index: 500 !important;
-ms-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-webkit-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
position: absolute; /* added */
top: 60px; /* added */
left: 20%; /* added */
/* removed float and bottom */
}
#box-dynamic.minimize {
height: 50px;
line-height: 5px;
}
#box-dynamic h1 {
margin-right: 5px;
color: #fff;
font-size: 20px;
font-family: 'Roboto Condensed', sans-serif;
margin-left: 5px;
-ms-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-webkit-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
}
#box-dynamic.minimize h1 {
font-size: 20px;
text-align: center;
}
#box-dynamic p {
color: white;
font-size: 15px;
line-height: 1.4;
margin-left: 5px;
font-family: 'Roboto Condensed', sans-serif;
-ms-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-webkit-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
}
#box-dynamic.minimize p {
font-size: 0px;
}
#box-dynamic small {
color: #ccc;
font-size: 11px;
font-family: 'Roboto Condensed', sans-serif;
margin-left: 5px;
margin-top: 0;
-ms-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-webkit-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
}
#box-dynamic.minimize small {
font-size: 10px;
margin-right: 5px;
float: right;
}
#box-dynamic img {
float: left;
width: 0;
height: 0;
visibility: hidden;
-ms-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-webkit-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
}
#box-dynamic.minimize img {
float: left;
width: 50px;
height: 50px;
visibility: visible;
}
<div class="box">
<div id="box-dynamic" onclick=panelView()>
<h1>This is my title</h1>
<p>few words about my paragraph so it goes like this...</p>
<br><br>
</div>
</div>
Upvotes: 1
Reputation: 52
Give top :0 insted of bottom.For horizontal center give left:50%; and transform:translateX(-50%):
Upvotes: 1
Reputation: 278
Remove "bottom: 0" in your #box-dynamic CSS styles and replace with "left: 40%" (40% could be replaced with your customized value)
Upvotes: 1