Line up and put div on the other

Asked

Viewed 34 times

1

Well I created a div called 'notification'. Where I will put a text and at the end of it has a menu. Everything is working fine, but when the text is too big and the screen is small, the menu button is on the text, and it is not aligned in the vertical center. Someone knows how to fix it?

In some cases the div notification will not have the menu.

$(document).ready(function() {

  // Abre Sidenav
  $(".overflow-menu").click(function() {
    $(this).find("ul").animate({
      height: 'toggle'
    }, 'fast');
  });
});
/*====================================================================================================================*/

/* Over-Flow Menu */

/*====================================================================================================================*/

.container-head .overflow-menu .material-icons {
  padding-right: 20px;
}
.container-head .overflow-menu {
  vertical-align: middle;
  display: table-cell;
  vertical-align: middle;
  width: 24px;
  position: relative;
  cursor: pointer;
}
.notification .overflow-menu {
  margin-right: 5px;
  float: right;
  margin-top: -4px;
  display: table-cell;
  vertical-align: middle;
  width: 24px;
  position: relative;
  cursor: pointer;
}
.overflow-menu ul {
  padding: 0;
  position: absolute;
  width: 260px;
  display: none;
  margin-left: -196px;
  overflow: hidden;
  border-radius: 0px 0px 4px 4px;
  top: 50px;
}
.notification .overflow-menu ul {
  text-align: left;
  font-style: normal;
  top: 22px;
  margin-left: -220px;
}
.overflow-menu li {
  padding-left: 10px;
  line-height: 40px;
  cursor: pointer;
  color: #FFFFFF;
  background: #484848;
}
.overflow-menu li:hover {
  background: #0091FF;
}
/*====================================================================================================================*/

/* Notification */

/*====================================================================================================================*/

.notification {
  background: #0091FF;
  padding: 15px;
  color: #FFFFFF;
  font-style: italic;
  text-a
}
lign:center;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!-- Notification -->
<div class="notification">
  <b>título</b> texto kjh jkkj k hk gh jghjgjk g jh jhgk hjg gkj hgj hg jhgj kjhgg jkhg jhg jg jhg j gjh gj g jhg j

  <!-- Over-Flow Menu -->
  <div class='overflow-menu'>
    <i class="material-icons">more_vert</i>
    <ul>
      <li>OPÇÃO 1</li>
      <li>OPÇÃO 2</li>
      <li>OPÇÃO 3</li>
    </ul>
  </div>
</div>

  • 1

    Hello, I couldn’t understand how you want the button to react to the various alternatives. no text, little text, lots of text.

  • That’s what I was wondering too.

  • Sorry I’ll try to explain better, I want the menu button to always be right and aligned vertically. And when the ceiling is too big, it can’t stay under the menu. That’s it. The structure has to be exactly the same as the question, open it on a large monitor that you will see as I want it to be. Understood better?

3 answers

2


Only changing the order of the written HTML solves the problem.

$(document).ready(function() {

  // Abre Sidenav
  $(".overflow-menu").click(function() {
    $(this).find("ul").animate({
      height: 'toggle'
    }, 'fast');
  });
});
/*====================================================================================================================*/

/* Over-Flow Menu */

/*====================================================================================================================*/

.container-head .overflow-menu .material-icons {
  padding-right: 20px;
}
.container-head .overflow-menu {
  vertical-align: middle;
  display: table-cell;
  vertical-align: middle;
  width: 24px;
  position: relative;
  cursor: pointer;
}
.notification .overflow-menu {
  margin-right: 5px;
  float: right;
  margin-top: -4px;
  display: table-cell;
  vertical-align: middle;
  width: 24px;
  position: relative;
  cursor: pointer;
}
.overflow-menu ul {
  padding: 0;
  position: absolute;
  width: 260px;
  display: none;
  margin-left: -196px;
  overflow: hidden;
  border-radius: 0px 0px 4px 4px;
  top: 50px;
}
.notification .overflow-menu ul {
  text-align: left;
  font-style: normal;
  top: 22px;
  margin-left: -220px;
}
.overflow-menu li {
  padding-left: 10px;
  line-height: 40px;
  cursor: pointer;
  color: #FFFFFF;
  background: #484848;
}
.overflow-menu li:hover {
  background: #0091FF;
}
/*====================================================================================================================*/

/* Notification */

/*====================================================================================================================*/

.notification {
  background: #0091FF;
  padding: 15px;
  color: #FFFFFF;
  font-style: italic;
  text-a
}
lign:center;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
 
<!-- Notification -->
<div class="notification">
  <!-- Over-Flow Menu -->
  <div class='overflow-menu'>
    <i class="material-icons">more_vert</i>
    <ul>
      <li>OPÇÃO 1</li>
      <li>OPÇÃO 2</li>
      <li>OPÇÃO 3</li>
    </ul>
  </div>
  <b>título</b>  texto kjh jkkj k hk gh jghjgjk g jh jhgk hjg gkj hgj hg jhgj     kjhgg jkhg jhg jg jhg j gjh gj g jhg j
</div>

  • Really good solution.

  • Perfect hahahahahaha. Is it possible to make the overflow-menu open below the notification? I noticed he’s sweating the menu button as a reference.

  • It would have to change a lot in html and css to do this since, to know the size of the text you have to put it in a container or put the <i> above the text as I did and the UL below but would no longer be a generic overflow-menu.

0

I don’t understand so well what you need, but it follows something I did thinking about what I understood.

I did with float:right and left.

$(document).ready(function() {

  // Abre Sidenav
  $(".overflow-menu").click(function() {
    $(this).find("ul").animate({
      height: 'toggle'
    }, 'fast');
  });
});
/*====================================================================================================================*/

/* Over-Flow Menu */

/*====================================================================================================================*/

.container-head .overflow-menu .material-icons {
  padding-right: 20px;
}
.container-head .overflow-menu {
  vertical-align: middle;
  display: table-cell;
  vertical-align: middle;
  width: 24px;
  position: relative;
  cursor: pointer;
}
.notification .overflow-menu {
  margin-right: 5px;
  margin-top: -4px;
  display: table-cell;
  vertical-align: middle;
  width: 24px;
  float: right;
  cursor: pointer;
}
.overflow-menu ul {
  padding: 0;
  position: absolute;
  width: 260px;
  display: none;
  margin-left: -196px;
  overflow: hidden;
  border-radius: 0px 0px 4px 4px;
  top: 50px;
}
.notification .overflow-menu ul {
  text-align: left;
  font-style: normal;
  top: 22px;
  margin-left: -220px;
}
.overflow-menu li {
  padding-left: 10px;
  line-height: 40px;
  cursor: pointer;
  color: #FFFFFF;
  background: #484848;
}
.overflow-menu li:hover {
  background: #0091FF;
}
/*====================================================================================================================*/

/* Notification */

/*====================================================================================================================*/

.notification {
  background: #0091FF;
  padding: 15px;
  color: #FFFFFF;
  font-style: italic;
  display: table;
  position: relative;
}
.notification .not {
  float: left;
  width: 90%;
}
.notification h4 {
  margin: 0;
  margin-bottom: 5px;
  right: 15px;
  top: 15px;
}
.notification .texto {
  width: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!-- Notification -->
<div class="notification">
  <div class="not">
    <h4>Título</h4>
    <div class="texto">
      Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
    </div>
  </div>

  <!-- Over-Flow Menu -->
  <div class='overflow-menu'>
    <i class="material-icons">more_vert</i>
    <ul>
      <li>OPÇÃO 1</li>
      <li>OPÇÃO 2</li>
      <li>OPÇÃO 3</li>
    </ul>
  </div>
</div>

  • And almost that, I don’t want to mess with the structure creating title. want it like I posted, the only problem was that the text was under the menu button. And the button was not aligned vertically.

  • So it won’t work. HTML semantics is incorrect. You need to have a parent element of your text to be on the menu side.

0

I propose to insert a paragraph within the element notifying and set a size for it, such that I left with 90%. So change some things in the classes .notification .overflow-menu and .notification, where I left the class .notification display as table to leave that element and descendants in table format and .notification .overflow-menu sized 5%. So regardless of the size of the text, the menu will always be to the right of the text and in the center.

inserir a descrição da imagem aqui

Upshot:

$(document).ready(function() {

  // Abre Sidenav
  $(".overflow-menu").click(function() {
    $(this).find("ul").animate({
      height: 'toggle'
    }, 'fast');
  });
});
/*====================================================================================================================*/

/* Over-Flow Menu */

/*====================================================================================================================*/

.container-head .overflow-menu .material-icons {
  padding-right: 20px;
}
.container-head .overflow-menu {
  vertical-align: middle;
  display: table-cell;
  vertical-align: middle;
  width: 24px;
  position: relative;
  cursor: pointer;
}
.notification .overflow-menu {
  margin-right: 5px;
  display: table-cell;
  vertical-align: middle;
  width: 5%;
  position: relative;
  cursor: pointer;
}
.overflow-menu ul {
  padding: 0;
  position: absolute;
  width: 260px;
  display: none;
  margin-left: -196px;
  overflow: hidden;
  border-radius: 0px 0px 4px 4px;
  top: 50px;
}
.notification .overflow-menu ul {
  text-align: left;
  font-style: normal;
  top: 22px;
  margin-left: -220px;
}
.overflow-menu li {
  padding-left: 10px;
  line-height: 40px;
  cursor: pointer;
  color: #FFFFFF;
  background: #484848;
}
.overflow-menu li:hover {
  background: #0091FF;
}
/*====================================================================================================================*/

/* Notification */

/*====================================================================================================================*/

.notification {
  background: #0091FF;
  padding: 15px;
  color: #FFFFFF;
  font-style: italic;
  text-align:center;
  display: table;
}

.notification p {
  width: 90%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!-- Notification -->
<div class="notification">
  <p>
    <b>Lorem Ipsum</b> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus id sem ac eros bibendum dignissim. In dignissim, orci commodo aliquet vestibulum, urna libero varius augue, ut pellentesque libero odio nec arcu. Donec hendrerit gravida sem et venenatis. Maecenas finibus elementum sapien, a faucibus erat lacinia in. Suspendisse volutpat massa nibh, sit amet maximus nulla sagittis ac. Duis maximus libero elementum, iaculis quam vitae, ornare nunc. Quisque efficitur erat justo, sit amet aliquam felis finibus non. Phasellus laoreet dolor ligula, at condimentum enim lacinia ac. 
  </p>
  <!-- Over-Flow Menu -->
  <div class='overflow-menu'>
    <i class="material-icons">more_vert</i>
    <ul>
      <li>OPÇÃO 1</li>
      <li>OPÇÃO 2</li>
      <li>OPÇÃO 3</li>
    </ul>
  </div>
</div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.