I am using Angular5, and I have tried to set margin: 0 auto as well as setting left: 50% and top: 50% but the margin doesn't do anything and setting left to 50% only aligns the side of the div to the middle and doesn't move the div down at all.
How do I align the div #loading to the middle?
My code:
#loading, #outlet {
width: 100%;
height: 100%;
position: absolute;
}
#loading{
z-index: 10;
height: 100px;
width: 200px;
background-color: rgba(255,255,255,0.85);
padding: 40px;
border: 1px solid #d3d3d3;
border-radius: 5px;
margin: 0 auto;
margin-bottom:10px;
box-shadow: 0px 1px 3px rgba(0,0,0,0.5);
}
#app{
position: relative;
}
<div id="app">
<div id="outlet">
<router-outlet></router-outlet>
</div>
<div id="loading" *ngIf="data.Loading">
<h2>Loading...</h2>
</div>
</div>
I am also overlaying the #loading div over #outlet.
The problem you are having is because of the position: absolute thing that you have assigned to both #loading and #outlet. You can solve the issue with this code. Try this.
<div id="app">
<div id="wrap">
<div id="outlet">
<router-outlet></router-outlet>
</div>
<div id="loading" *ngIf="data.Loading">
<h2>Loading...</h2>
</div>
</div>
</div>
#wrap {
margin: 0 auto;
width: 200px;
}
#loading, #outlet {
width: 100%;
height: 100%;
position: absolute;
}
#loading{
z-index: 10;
height: 100px;
width: 200px;
background-color: rgba(255,255,255,0.85);
padding: 40px;
border: 1px solid #d3d3d3;
border-radius: 5px;
margin: 0 auto;
margin-bottom:10px;
box-shadow: 0px 1px 3px rgba(0,0,0,0.5);
}
#app{
position: relative;
width: 100%;
}
To align the text in the center, use text-align: center:
#loading, #outlet {
width: 100%;
height: 100%;
}
#loading{
z-index: 10;
height: 100px;
width: 200px;
background-color: rgba(255,255,255,0.85);
padding: 40px;
border: 1px solid #d3d3d3;
border-radius: 5px;
text-align: center;
margin-bottom:10px;
box-shadow: 0px 1px 3px rgba(0,0,0,0.5);
}
#app{
position: relative;
}
<div id="app">
<div id="outlet">
<router-outlet></router-outlet>
</div>
<div id="loading" *ngIf="data.Loading">
<h2>Loading...</h2>
</div>
</div>
To align the box in the center, use margin: auto, but DO NOT use position: absolute:
#loading, #outlet {
width: 100%;
height: 100%;
}
#loading{
z-index: 10;
height: 100px;
width: 200px;
background-color: rgba(255,255,255,0.85);
padding: 40px;
border: 1px solid #d3d3d3;
border-radius: 5px;
margin: auto;
margin-bottom:10px;
box-shadow: 0px 1px 3px rgba(0,0,0,0.5);
}
#app{
position: relative;
}
<div id="app">
<div id="outlet">
<router-outlet></router-outlet>
</div>
<div id="loading" *ngIf="data.Loading">
<h2>Loading...</h2>
</div>
</div>
Then if you put those two together, you get:
#loading, #outlet {
width: 100%;
height: 100%;
}
#loading{
z-index: 10;
height: 100px;
width: 200px;
background-color: rgba(255,255,255,0.85);
padding: 40px;
border: 1px solid #d3d3d3;
border-radius: 5px;
margin: auto;
text-align: center;
margin-bottom:10px;
box-shadow: 0px 1px 3px rgba(0,0,0,0.5);
}
#app{
position: relative;
}
<div id="app">
<div id="outlet">
<router-outlet></router-outlet>
</div>
<div id="loading" *ngIf="data.Loading">
<h2>Loading...</h2>
</div>
</div>
Related
I want to make the width of an image relative to it's parent div and still the highlighted box properly alinged on the words. But when I give image 100% width, it will not properly aligned.
Fiddle: https://jsfiddle.net/cv7g149k/3/
.summary {
background-color: #fff;
border: 2px solid #9197ae;
width: 700px;
padding: 15px;
margin: auto;
z-index: 1;
text-align: left;
box-shadow: 0 0 3px #000;
}
.image-results {
max-width: 700px;
margin: auto;
}
.image-holder {
display: block;
position: relative;
}
.word-highlight {
background-color: rgba(240, 45, 58, 0.3);
border: 1px solid rgba(240, 45, 58, 0.4);
position: absolute;
border-radius: 4px;
margin: -2px -4px;
padding: 2px 4px;
box-sizing: initial !important;
}
<div class="summary align-items-center">
<div class="px-2">
Number of Detected Words:<span>64</span>
</div>
<div class="px-2">
Detected words: <span>Python, Javascript</span>
</div>
</div>
<div class="image-results">
<div class="image-holder">
<img src="https://miro.medium.com/max/1400/0*GV5Xm8Ve-tb_qAAs" class="iimg-width-banned-words">
<div class="word-highlight" style="left: 171px; top: 173px; width: 70px; height: 22px;"></div>
<div class="word-highlight" style="left: 141px; top: 241px; width: 100px; height: 22px;"></div>
</div>
</div>
Instead of specifying exact px for the position of word-highlight classes, you may want to use % to define the position
.summary {
background-color: #fff;
border: 2px solid #9197ae;
width: 700px;
padding: 15px;
margin: auto;
z-index: 1;
text-align: left;
box-shadow: 0 0 3px #000;
}
.image-results {
max-width: 700px;
margin: auto;
}
.image-holder {
display: block;
position: relative;
}
.word-highlight {
background-color: rgba(240, 45, 58, 0.3);
border: 1px solid rgba(240, 45, 58, 0.4);
position: absolute;
border-radius: 4px;
margin: -2px -4px;
padding: 2px 4px;
box-sizing: initial !important;
}
img {
width: 100%;
}
<div class="summary align-items-center">
<div class="px-2">
Detected words:<span>64</span>
</div>
</div>
<div class="image-results">
<div class="image-holder">
<img src="https://miro.medium.com/max/1400/0*GV5Xm8Ve-tb_qAAs" class="iimg-width-banned-words">
<div class="word-highlight" style="left: 12%; top: 19%; width: 5.5%; height: 4%;"></div>
<div class="word-highlight" style="left: 10%; top: 26.5%; width: 8%; height: 4%;"></div>
</div>
</div>
Add width: 100%; and height: 100%: to your image class so that it fills 100% of the parent div. Then you will have to adjust your values for word-highlight.
.summary {
background-color: #fff;
border: 2px solid #9197ae;
width: 700px;
padding: 15px;
margin: auto;
z-index: 1;
text-align: left;
box-shadow: 0 0 3px #000;
}
.image-results {
max-width: 700px;
margin: auto;
}
.image-holder {
display: block;
position: relative;
}
.word-highlight {
background-color: rgba(240, 45, 58, 0.3);
border: 1px solid rgba(240, 45, 58, 0.4);
position: absolute;
border-radius: 4px;
margin: -2px -4px;
padding: 2px 4px;
box-sizing: initial !important;
}
.img-width-banned-words {
height: 100%;
width: 100%;
}
<div class="summary align-items-center">
<div class="px-2">
Number of Detected Words:<span>64</span>
</div>
<div class="px-2">
Detected words: <span>Python, Javascript</span>
</div>
</div>
<div class="image-results">
<div class="image-holder">
<img src="https://miro.medium.com/max/1400/0*GV5Xm8Ve-tb_qAAs" class="img-width-banned-words">
<div class="word-highlight" style="left: 80px;top: 83px;width: 44px;height: 20px;"></div>
<div class="word-highlight" style="left: 73px; top: 117px; width: 47.5px; height: 20px;"></div>
</div>
</div>
I've got a basic html that contain such lines
<div id="circle">
<div id="slider"></div>
</div>
<div id="audio-player-core" class="controls">
<img src="" alt="nothing" width="65px" height="65px">
</div>
And css
#circle {
width: 100px;
height: 100px;
border: 2px solid rgba(0,0,0,0.5);
border-radius: 100%;
float: left;
margin-left: 10px;
}
#slider {
position: relative;
height: 30px;
width: 30px;
background: rgba(0,0,0,0.5);
border-radius: 100%;
cursor: pointer;
}
.controls {
position: relative;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
z-index: 99;
background-color: transparent;
width: 500px;
margin-left: 20px;
}
#audio-player-core {
border: 1px solid;
border-radius:0 10px 10px 0;
border-color: rgba(0,0,0,0.5);
}
But I cannot make them overlap each other (specifically I want for rectangle to start at the center of the circle while hiding part of circle inside). When I try to move one via margin - another moves and so on.
jsfiddle
How to overlap them?
Use positioning. For example,
#audio-player-core {
border: 1px solid;
border-radius:0 10px 10px 0;
border-color: rgba(0,0,0,0.5);
position: absolute;
left: 50px;
top: 60px;
}
#circle {
width: 100px;
height: 100px;
border: 2px solid rgba(0,0,0,0.5);
border-radius: 100%;
float: left;
margin-left: 10px;
}
#slider {
position: relative;
height: 30px;
width: 30px;
background: rgba(0,0,0,0.5);
border-radius: 100%;
cursor: pointer;
}
.controls {
position: relative;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
z-index: 99;
background-color: transparent;
width: 500px;
margin-left: 20px;
}
#audio-player-core {
border: 1px solid;
border-radius:0 10px 10px 0;
border-color: rgba(0,0,0,0.5);
position: absolute;
left: 50px;
top: 60px;
}
<div id="circle">
<div id="slider"></div>
</div>
<div id="audio-player-core" class="controls">
<img src="" alt="nothing" width="65px" height="65px">
</div>
I read this post but still ain't able to center the inner <div> :
div {
margin: 0 auto;
border: 5px solid orange;
width: 60%;
font-family: Verdana;
text-align: center;
}
.game {
border: 5px solid black;
overflow: hidden;
position: absolute;
}
<div>
<div class="game" style="width: 100px; height: 100px;">
</div>
</div>
It must be related to the position: absolute; property but it is required in order to insert absolute-position <img> elements in the inner <div>.
Simple, add this:
.game {
right: 0;
left: 0;
margin: 0 auto;
}
Since the width is given left and right will not affect your elements width. margin: 0 auto; will do the positioning
Example:
div {
margin: 0 auto;
border: 5px solid orange;
width: 60%;
font-family: Verdana;
text-align: center;
}
.game {
border: 5px solid black;
overflow: hidden;
position: absolute;
right: 0;
left: 0;
margin: 0 auto;
}
<div>
<div class="game" style="width: 100px; height: 100px;">
</div>
</div>
div {
margin: 0 auto;
border: 5px solid orange;
width: 60%;
font-family: Verdana;
text-align: center;
}
.game {
border: 5px solid black;
overflow: hidden;
position: absolute;
left: 0;
right: 0;
margin: auto;
}
<div>
<div class="game" style="width: 100px; height: 100px;">
</div>
</div>
div {
margin: 0 auto;
border: 5px solid orange;
width: 60%;
font-family: Verdana;
text-align: center;
}
.game {
border: 5px solid black;
overflow: hidden;
position: absolute;
left: 0;
right:0;
}
<div>
<div class="game" style="width: 100px; height: 100px;">
</div>
</div>
Just add
left: 0;
right:0;
To the game class, and it will be horziontally centered. The trick here is to set the position to left 50%, and margin left to minus 1 half of the container width. Let me know if this solves it for you.
EDIT: helpful comments have shown me that we do not need the margin left negative, we can just set the left and right attribute for horizontal alignment. This is better because it will work regardless of the width of the element
Here's another approach..
.game {
border: 5px solid black;
overflow: hidden;
position: absolute;
left: 50%;
transform: translateX(-50%);
}
div {
margin: 0 auto;
border: 5px solid orange;
width: 60%;
font-family: Verdana;
text-align: center;
}
.game {
border: 5px solid black;
overflow: hidden;
position: absolute;
left: 50%;
transform: translateX(-50%);
}
<div>
<div class="game" style="width: 100px; height: 100px;">
</div>
</div>
http://www.codeply.com/go/E0xL0KyOkU
you can use the image as the background of the class game
div {
margin: 0 auto;
border: 5px solid orange;
width: 60%;
height:300px;
font-family: Verdana;
text-align: center;
}
.game {
border: 5px solid black;
overflow: hidden;
position:relative;
left: 0;
top:28%;
right: 0;
margin: auto;
}
<div>
<div class="game" style="width: 100px; height: 100px;">
</div>
</div>
try this
div {
margin: 0 auto;
border: 5px solid orange;
width: 60%;
font-family: Verdana;
}
.game {
border: 5px solid black;
width:30%; margin:0 auto;
position: absolute;
left: 0;
right: 0;
padding: 0 20px;
}
<div>
<div class="game">
test
</div>
</div>
so i am having trouble collapsing borders between two floating divs. I know how to do it with table cells but these are not cells and I'm not using tables. Here is a picture of what the picture looks like page image
Here is my html and css code as well.
body{
background-color: #C8C8C8;
}
h1{
text-shadow: 2px 3px gray;
margin-left: auto;
margin-right: auto;
width: 200px;
}
img.width{
width: 100%;
}
img.tLeft {
float: left;
z-index: -1;
padding-right: 3em;
}
img.tRight {
float: right;
z-index: -1;
}
.div1 {
width: 900px;
height: 700px;
margin-left: auto;
margin-right: auto;
border-radius: 20px;
box-shadow: 10px 10px 5px #A8A8A8;
background-color: #4dffa6;
overflow: hidden;
z-index: -1;
}
.div2 {
height: auto;
border: 1px solid red;
overflow: hidden;
border-top-left-radius: 20px;
top: 0;
left: 0;
float: left;
border-right: collapse;
}
.div3 {
height: auto;
border: 1px solid red;
overflow: hidden;
border-top-right-radius: 20px;
top: 0;
right: 0;
z-index: -1;
float: right;
}
.div4 {
height: auto;
border: 1px solid blue;
background-color: lightgray;
overflow: hidden;
left: 0;
display: block;
}
strong{
font-size: 70px;
color: red;
}
<div>
<img class="width" src="images/rancidbanner.png" alt="Rancid Tomatoes">
</div>
<h1>TMNT (2015)</h1>
<!---block one--->
<div class="div1">
<!---block two--->
<div class="div2">
<img class="tLeft" src="images/rottenlarge.png" alt="Rotten" /> <strong>33%</strong>
</div>
<!---block three--->
<div class="div3">
<img class="tRight" src="images/overview.png" alt="general overview" />
</div>
<!---box four
<div class="div4">
<p>HEllo relkgnaldfkgnadlgsknasdlkgnasldkgnaslkdgnasldkn aslkdgnslkdgn sjdnaslkdjfnaslkdjfn sdgnaslkjgnlaskjgdn
</p>
</div>
--->
</div>
Might be worth using a CSS reset so that the browser doesn't affect your CSS - http://meyerweb.com/eric/thoughts/2011/01/03/reset-revisited/
I need to know how to cut that gray part from the blue box.
The red arrows on the image bellow show which part I would like to cut from the blue box. This is the code I have:
.father {
height: 400px;
width: 400px;
margin: 150px auto;
position: relative;
}
.border {
position: relative;
bottom: 50px;
margin: auto;
border-radius: 50%;
width: 96%;
height: 30%;
background-color: #DDD;
}
<div class="father">
<div class="border"></div>
</div>
From what I understand you would like to cut off the grey part outside the blue area. If so, here's how you do it.
.father {
height: 400px;
width: 400px;
margin: 150px auto;
position: relative;
background: lightblue;
overflow: hidden;
}
.border {
position: relative;
bottom: 50px;
margin: auto;
border-radius: 50%;
width: 96%;
height: 30%;
background-color: #DDD;
z-index: 1;
}
<div class="father">
<div class="border"></div>
</div>
Can you see this approach:
border-top-left-radius: 8px;
border-top-right-radius: 8px;
.father {
height: 400px;
width: 400px;
margin: 150px auto;
position: relative;
background: lightblue;
border-top-left-radius: 8px;
border-top-right-radius: 8px;
}
.border {
position: relative;
bottom: 50px;
margin: auto;
border-radius: 50%;
width: 100%;
height: 30%;
background-color: #DDD;
}
<div class="father">
<div class="border"></div>
</div>
Are you looking for this?
.father {
height:400px;
width:400px;
margin:150px auto;
position:relative;
background:green;
}
.border {
position:relative;
bottom:50px;
margin:auto;
border-radius:50%;
width:96%;
height:30%;
background-color:#DDD;
z-index:-9;
}
<div class="father">
<div class="border"></div>
</div>
.father
{
height: 400px;
width: 400px;
margin: 150px auto;
position: relative;
background: #04aada;
border-radius: 50px 50px 0 0;
}
.border
{
position: relative;
bottom: 25px;
margin: auto;
border-radius: 50%;
width: 96%;
height: 30%;
background-color: #fff;
z-index: 1;
box-shadow: 0px -4px 0px #04aada;
}
<div class="father">
<div class="border"></div>
</div>