2

I get the problem in MY CSS CODE....

The problem is....

Why 'icons friends' and 'icon privacy' do not want to be aligned with the text

Home.html

 <link rel="stylesheet" href="//cdn.materialdesignicons.com/1.9.32/css/materialdesignicons.min.css">

 <div class="privacy-select">
  <span class="display-ib">
   <span class="mdi mdi-earth"></span>
   <p>World</p>
  </span>

  <ul class="my-dropdown">
    <li>
      <span class="mdi mdi-account"></span>
      <p>Friend</p>
    </li>
    <li>
      <span class="mdi mdi-lock"></span>
      <p>Privacy</p>
    </li>
  </ul>

 </div>

Home.css

.privacy-select {
  position: relative;
  display: inline-block
}

span {
  display: inline-block;
}

p {
  margin: 0;
  display: inline-block;
}

ul {
  dispaly: inline-block;
  margin: 0;
  padding: 0;
  list-style: none;
}

.my-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 1em;
}

See my coding in https://jsfiddle.net/FIERMANDT/7gygxncp/

5 Answers 5

3

It's because you have made your privacy-select div inline block - this means that it's width is as wide as the widest element inside - in this case that is the display-ib span as you have made the ul absolutely position (moving it out of the flow)

This means that because this is not wide enough for the ul items, the ul items will wrap unless you tell them not to:

.privacy-select {
  position: relative;
  display: inline-block;
}

span {
  vertical-align: middle;
}

p {
  margin: 0;
  display: inline-block;
}

ul{
  margin: 0;
  padding: 0;
  list-style: none;
}

.my-dropdown {
  position:absolute; /* does this need to be absolutely positioned - removing this is another way fix your issue */
  top:100%;
  right: 0;
  margin-top: 1em;
  white-space:nowrap; /* add this, or alternately give this a min-width, or you could make privacy-select a block element  */
}
<link rel="stylesheet" href="//cdn.materialdesignicons.com/1.9.32/css/materialdesignicons.min.css">
<div class="privacy-select">
  <span class="display-ib">
   <span class="mdi mdi-earth"></span>
  <p>World</p>
  </span>

  <ul class="my-dropdown">
    <li>
      <span class="mdi mdi-account"></span>
      <p>Friend</p>
    </li>
    <li>
      <span class="mdi mdi-lock"></span>
      <p>Privacy</p>
    </li>
  </ul>
</div>

Sign up to request clarification or add additional context in comments.

1 Comment

THANKS :D, AWESOME FOR ME :D
1

Change position from absolute to relative. So that your icons will be relative to the div

.my-dropdown { 
  position: relative; 
  top: 100%; 
  right: 0; 
  margin-top: 1em; 
 }

Comments

0

remove position:absolute from your .my-dropdown class

.privacy-select {
  position: relative;
  display: inline-block
}

span {
  display: inline-block;
}

p {
  margin: 0;
  display: inline-block;
}

ul {
  dispaly: inline-block;
  margin: 0;
  padding: 0;
  list-style: none;
}

.my-dropdown {
  top: 100%;
  right: 0;
  margin-top: 1em;
}
<link rel="stylesheet" href="//cdn.materialdesignicons.com/1.9.32/css/materialdesignicons.min.css">

<div class="privacy-select">
  <span class="display-ib">
   <span class="mdi mdi-earth"></span>
   <p>World</p>
  </span>
  
  <ul class="my-dropdown">
    <li>
      <span class="mdi mdi-account"></span>
      <p>Friend</p>
    </li>
    <li>
      <span class="mdi mdi-lock"></span>
      <p>Privacy</p>
    </li>
  </ul>
  
</div>

also: JS Fiddle Demo

Comments

0

Your .my-dropdown container is too narrow - set a width to it and allign it left: 0 instead of right: 0 .

Also, you had a typo in ´display´ for the ul

Here#s the fiddle: https://jsfiddle.net/w133fbu8/1/

Comments

0
.privacy-select {
  position: relative;
  display: inline-block
}

span {
  display: inline-block;
}

p {
  margin: 0;
  display: inline-block;
}

ul {
  display: inline-block;
  margin: 0;
  padding: 0;
  list-style: none;
}

.my-dropdown {
  position: absolute;
  width: 90px;
  top: 100%;
  left: 0;
  margin-top: 1em;
}


<link rel="stylesheet" href="//cdn.materialdesignicons.com/1.9.32/css/materialdesignicons.min.css">

<div class="privacy-select">
  <span class="display-ib">
   <span class="mdi mdi-earth"></span>
   <p>World</p>
  </span>

  <ul class="my-dropdown">
    <li>
      <span class="mdi mdi-account"></span>
      <p>Friend</p>
    </li>
    <li>
      <span class="mdi mdi-lock"></span>
      <p>Privacy</p>
    </li>
  </ul>

</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.