Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML/CSS close button overlapping right/upper corner

Tags:

html

css

Looking to place a button overlying, and partially outside parent div such as in this picture. MY attempts have it within the parent DIV. The picture below is what I am after.

enter image description here

#container {
  width: 80%;
  border-radius: 25px;
  border: 2px solid Black;
  padding: 15px 15px 15px 15px;
  margin: 20px 20px 20px 20px;
  background: #A4D3EE;
  overflow: auto;
  box-shadow: 5px 5px 2px #888888;
  position: relative;
}

#x {
    position: relative;
    float: right;
    background: red;
	color: white;
    top: -10px;
    right: -10px;
}
<div id="container">
        <button id = "x">
            X
        </button>
    Text Text Text
    Text Text Text
    Text Text Text
</div>
like image 873
cycle4passion Avatar asked Oct 25 '15 23:10

cycle4passion


People also ask

How do I stop HTML overlapping?

Answer 5523099de39efeabcb0002f2from each <img> , and they should stop overlapping each other.

How do you put a button in the top right corner in CSS?

Just add position:absolute; top:0; right:0; to the CSS for your button.

How do I overlap a button in CSS?

Set the position property value for the parent to relative (to control overlap) and that of the button DIV to absolute . Now place your button inside the button DIV , then use negative values for left , right , top or bottom to position the button DIV where you want.


1 Answers

I guess this is what you looking for:

Just add position:absolute; instead relative

#container {
  width: 80%;
  /*border-radius: 25px;*/
  border: 2px solid Black;
  padding: 15px 15px 15px 15px;
  margin: 20px 20px 20px 20px;
  background: #A4D3EE;
  overflow: visible;
  box-shadow: 5px 5px 2px #888888;
  position: relative;
}

#x {
    position: absolute;
    background: red;
    color: white;
    top: -10px;
    right: -10px;
}
<div id="container">
        <button id = "x">
            X
        </button>
    Text Text Text
    Text Text Text
    Text Text Text
</div>
like image 158
divy3993 Avatar answered Sep 22 '22 16:09

divy3993