li大小与文本大小相同

时间:2016-02-10 02:07:42

标签: html css menu

我正在创建带有ul / li的自定义菜单,但我的尺寸有问题。

  1. 左右两侧溢出。在左侧,当元素被缩放时,它确实用完了父元素。
  2. 它确实占据整个尺寸作为父元素,我希望li的大小与li的文本长度相同,以便橙色背景与文本完全相同。
  3. 我试过

    SELECT * INTO #Demo FROM (VALUES (9,'00001',1), (9,'00001',1), (9,'00001',1), (9,'00001',1), (9,'00001',1), (9,'00002',1), (9,'00003',1), (9,'00003',1), (9,'00003',1) ) A (iStore,vCode,iQty); DECLARE @rowcountdivider INT = 4; SELECT iStore ,vCode ,iQty ,((ROW_NUMBER() OVER (ORDER BY vCode) - 1) / @rowcountdivider) + 1 MasterCounter FROM #Demo; iStore vCode iQty MasterCounter ----------- ----- ----------- -------------------- 9 00001 1 1 9 00001 1 1 9 00001 1 1 9 00001 1 1 9 00001 1 2 9 00002 1 2 9 00003 1 2 9 00003 1 2 9 00003 1 3 public static void main(String[] args) throws FileNotFoundException { File fil1 = new File("Banking.txt"); File fil2 = new File("Records.txt"); Scanner sc1 = new Scanner(fil1); Scanner s1 = new Scanner(fil2); String fname; String mname; String lname; String uid = null; int pin = 0; double balance = 0; java.io.PrintWriter output = new java.io.PrintWriter(fil2); while (sc1.hasNext()) { fname = sc1.next(); mname = sc1.next(); lname = sc1.next(); uid = sc1.next(); pin = sc1.nextInt(); balance = sc1.nextDouble(); BankRecord person = new BankRecord(fname,mname,lname,uid,pin,balance); System.out.print(pin); } Scanner input = new Scanner(System.in); System.out.print("Please enter a user ID: "); String entereduid = input.nextLine(); if(entereduid.equals(uid)){ System.out.print("Please enter a Pin #: "); String enteredpin = input.nextLine(); if(enteredpin.equals(pin)){ Scanner input2 = new Scanner(System.in); System.out.print("press 1 to check balance, 2 for a deposit, or 3 for a withdrawal: "); int ans = input.nextInt(); if(ans == 1){ System.out.print(balance); output.println("The balance is now "+balance+"$."); } else if(ans == 2){ System.out.print("Your current balance is: " + balance+". Please enter an amount to deposit: "); double dep = input.nextDouble(); balance = balance + dep; System.out.print("You deposited "+dep+"$. Your new balance is: " + balance+"$."); output.println("The balance is now "+balance+"$."); } else if(ans == 3){ System.out.print("Yor current balance is: "+balance+". Please enter an amount to withdrawl: "); double wit = input.nextDouble(); balance = balance - wit; System.out.print("You withdrew "+wit+"$. Your new balance is: "+balance+"$."); output.println("The balance is now "+balance+"$."); }}}}}

    这是我的代码:

    HTML:

    width:100%;

    CSS:

    width:auto;

    Live

2 个答案:

答案 0 :(得分:1)

您可以在display:inline-block上使用:hover,而且我已经修复了您的CSS代码,因为在其他小问题中重写了相同的类。



.icon {
  padding-left: 20px;
  list-style: none;
}
.info {
  float:left;
  clear:left;
  font-weight: bold;
  transition: all .2s ease-in-out;
  margin: 0 0 10px 20px
}
.info:before {
  font-family: 'FontAwesome';
  margin: 0 5px 0 -15px;
  font-weight: bold;
  content: "->";
  color: green;
}
.info:hover {
  font-style: italic;
  transform: scale(1.1);
  display: inline-block;
  cursor: hand;
  background-color: rgb(242, 105, 34);
}

<ul class="icon">
  <li class="info">aaaaaa</li>
  <li class="info">bbbbb</li>
  <li class="info">cccccccccccc</li>
  <li class="info">ddd</li>
</ul>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

如果您在display: inline-block上添加:hover并将clear: bothfloat: left添加到li.info,请执行以下操作:

li.info {
  clear: both;
  float: left;
  font-weight: bold;
  transition: all .2s ease-in-out;
}

li.info:hover {
  display: inline-block;
  font-style: italic;
  transform: scale(1.1);
}

它应该正常工作,如here所示。