Currently on my page I have this layout
<div class="card">
<div class="card-block">
<h4 class="card-title text-muted">UltimateWarrior15</h4>
<h6 class="card-subtitle text-muted">
Adventurer card
</h6>
</div>
<img data-src="holder.js/100px180/?text=Image">
<div class="card-block">
<div class="form-group row">
<label for="player-level-text" class="col-xs-2 col-form-label">Rank</label>
<div class="col-xs-10">
<label class="form-control text-muted">D</label>
</div>
</div>
</div>
</div>
It gives pretty simple result
But what I want to achieve is to move rank
value from label
formatted similar to input to some image asset or maybe just label with bigger font, that would overlap image like this
How to achieve this using HTML
and CSS
?
Sample https://jsfiddle.net/46qnx1LL
You can use the CSS position property in combination with the z-index property to overlay an individual div over another div element. The z-index property determines the stacking order for positioned elements (i.e. elements whose position value is one of absolute , fixed , or relative ).
You can apply the CSS position:relative; and then specify an offset such as top:-50px;left:-20px; which would shift the element 20 pixels to the left and 50 pixels up. You can also specify right and bottom and use positive or negative values.
Similarly, box elements may overlap for a few reasons, ranging from positioning errors to overflow issues and simple float problems. In most cases, a quick and easy change to your website's style sheet will fix the problem.
In order an element to appear in front of another you have to give higher z-index to the front element, and lower z-index to the back element, also you should indicate position: absolute/fixed... Save this answer.
You can achieve this with a simple negative margin, e.g. margin-top: -75px;
. With setting the border: none;
and background: transparent;
only the font is visible. Now you only need to apply text-align: right;
to the parent div and your letter is on the right side.
Here is an example:
.card-block .col-form-label {
display: none;
}
.card-block > .row > div {
text-align: right;
}
.card-block .text-muted {
border: none;
background: transparent;
font-size: 4em;
font-weight: bold;
margin-top: -75px;
color: black !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/holder/2.9.4/holder.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="card">
<div class="card-block">
<h4 class="card-title text-muted">UltimateWarrior15</h4>
<h6 class="card-subtitle text-muted">
Adventurer card
</h6>
</div>
<img data-src="holder.js/100px180/?text=Image">
<div class="card-block">
<div class="form-group row">
<label for="player-level-text" class="col-xs-2 col-form-label">Rank</label>
<div class="col-xs-10">
<label class="form-control text-muted">D</label>
</div>
</div>
</div>
</div>
You can apply the CSS position:relative;
and then specify an offset such as top:-50px;left:-20px;
which would shift the element 20 pixels to the left and 50 pixels up. You can also specify right
and bottom
and use positive or negative values.
If you find that the element is hidden underneath another element, then you can move it up to a higher layer by specifying the z-index:
layer number;
so that the element is positioned on the right layer.
JS Fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With