ofca1234
ofca1234

Reputation: 53

Position one div in top-right corner above another one in bottom-right corner

How can I achieve that the gray arrow goes to the red position? To be above the button.

enter image description here

<div class="media">
    <img class="rounded-circle profile-img" src="{{ user.userprofile.image.url }}">
    <div class="one-above-the-other">
        <div class="dropdown">
            <a class="link-hover" data-toggle="dropdown">
                <i class="fas fa-cog dark-icon"></i>
            </a>
            <div class="dropdown-menu my-drop-menu">
                <span class="my-drop-menu-item-span">
                    <a class="my-drop-menu-item dropdown-item change-email link-hover"
                        data-id="{% url 'change-email' user.pk %}">
                        Change email
                    </a>
                </span>
            </div>
        </div>
        <div class="edit-profile-button">
            <a class="edit-profile link-hover btn my-purple-btn">Edit profile</a>
        </div>
    </div>
</div>

Media and rounded-circle are from bootstrap. my-drop-menu and edit-profile-button are just for styling.

.one-above-the-other {
    margin-left: auto; 
    margin-right: 0; 
    margin-top: auto; 
    margin-bottom: 0;
}

.profile-img {
    width: 132px;
    height: 132px;
}

Updated with the newest code.

Upvotes: 1

Views: 1008

Answers (2)

VSM
VSM

Reputation: 1785

Try both methods below. Hope one of these works for you.

Method 1

.one-above-another {
  display: flex;
  flex-direction: row-reverse;
  justify-content: space-between;
  width: 100%;
}

Method 2

.one-above-another {
   position: relative;
   width: 100%;
}

.one-above-another .dropdown {
  position: absolute;
  top: 0;
  right: 0;
}

Updated Method

Check this Jsfiddle link.

.media {
    position: relative;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: flex-end !important;
}

/* .one-above-the-other {
    margin-left: auto; 
    margin-right: 0; 
    margin-top: auto; 
    margin-bottom: 0;
} */

.circle-img {
  display: inline-flex;
  width: 100px;
  height: 100px;
  border-radius: 50%;
}

.dropdown-box {
    position: absolute;
    top: 0;
    right: 0;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script
src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>

<div class="media">
<img class="circle-img" src="https://via.placeholder.com/300">
<div class="one-above-another">
    <div class="dropdown-box">
      <div class="dropdown">
        <a class=" link-hover" data-toggle="dropdown">
            <i class="fas fa-cog dark-icon"></i>
        </a>
        <div class="dropdown-menu my-drop-menu">
            <span class="my-drop-menu-item-span">
                <a class="my-drop-menu-item dropdown-item edit-post link-hover" data-id="">
                    Change email
                </a>
            </span>
        </div>
    </div>
    </div>
    <div class="edit-profile-button">
        <a class="edit-profile link-hover btn my-purple-btn">Edit profile</a>
    </div>
</div>
</div>

Upvotes: 1

Ranjith v
Ranjith v

Reputation: 1062

try like this

css

.one-above-the-other {
    margin-left: auto; 
    margin-right: 0; 
    margin-top: auto; 
    margin-bottom: 0;
}
.dropdown{
  position: absolute;
right: 0;
top: 0;
  }
.edit-profile-button{
  position: absolute;
left: 0;
bottom: 0;
}

Upvotes: 0

Related Questions