How to avoid overlapping of html elements over each other?

5.4k views Asked by At

I'm facing a problem creating something. I want a number of <kbd> tag in my body which should be aligned right. I'm able to do so but the problem is that <kbd> elements are overlapping over each other. So I want to know that how can I keep the <kbd> elements right aligned and avoid their overlapping.

.me_msg {
  background: rgb(250, 250, 250);
  border-radius: 10px 10px 0px 10px;
  border-width: 1px;
  color: #003cff;
  padding: 10px;
  text-align: right;
  padding: 1.1% 4% 1.1% 4%;
  position: absolute;
  right: 03%;
  top: auto;
  bottom: auto;
  min-width: 20%;
  max-width: 40%;
  box-shadow: 0px 0px 3px #e9e9e9;
  display: block;
}
<kbd class='me_msg'>My First Message</kbd>
<kbd class='me_msg'>My Second Message</kbd>
<kbd class='me_msg'>My Third Message</kbd>

2

There are 2 answers

2
Samuel Liew On BEST ANSWER

Do not use absolute, unless you want to position each button separately/manually.

A simple solution would be to float right instead.

.me_msg {
  background: rgb(250, 250, 250);
  border-radius: 10px 10px 0px 10px;
  border-width: 1px;
  color: #003cff;
  padding: 10px;
  text-align: right;
  margin-left: 10px;
  padding: 1.1% 4% 1.1% 4%;
  position: relative;
  float: right;
  min-width: 20%;
  max-width: 40%;
  box-shadow: 0px 0px 3px #e9e9e9;
  display: block;
}
<kbd class='me_msg'>My First Message</kbd>
<kbd class='me_msg'>My Second Message</kbd>
<kbd class='me_msg'>My Third Message</kbd>

0
Yonas Hailu On

Here is a demo If I got you question right I mean the css part

 .me_msg {
         background:rgb(250,250,250);
         border-radius:10px 10px 0px 10px;
         border-width:1px;
         color:#003cff;
         padding:10px;
         text-align:right;
         padding:1.1% 4% 1.1% 4%; 
             float: right;
             display: inline-block;
             bottom:auto;
         min-width:10%;     
             max-width:40%;
         box-shadow:0px 0px 3px #e9e9e9;
        }

Link https://jsfiddle.net/1uh3ha5w/