Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overlap element over other elements

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

enter image description here

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

enter image description here

How to achieve this using HTML and CSS?

Sample https://jsfiddle.net/46qnx1LL

like image 910
lapots Avatar asked Nov 02 '16 21:11

lapots


People also ask

How do you overlay one element over another?

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 ).

How do you overlap elements in HTML?

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.

Why are my elements overlapping CSS?

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.

How do you put a div in front of another?

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.


2 Answers

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>
like image 55
andreas Avatar answered Sep 19 '22 00:09

andreas


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

like image 45
Andrew Avatar answered Sep 20 '22 00:09

Andrew