Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase width of anchor tag inside li to li width

Tags:

html

css

I have structure like this

  <div class='myClass'>
     <ul>
          <li>
               <a href="myfile.html">My link</a>
          </li>
     </ul>
  </div>

My li has a fixed with.
But a text is not always equal to li width
So the click able area is less than li.
I tried to fix it by increasing the width of the a but it is not working.
How can I achieve it.
I am using the following css

.tooltipinner ul {
   list-style-type: none;
   margin: 0;
   overflow-y: auto;
   padding: 0;
   width: 305px;
}
.tooltipinner ul li {
    background-color: #BBAEA5;
    background-image: url("../../Images/UIFiles/Menu/SubmenuBg.jpg");
    background-position: left top;
    background-repeat: repeat-x;
    border-top: 1px solid #C1BFBD;
    color: #FFFFFF;
    cursor: pointer;
    float: left;
    font-size: 12px;
    padding-bottom: 4px;
    padding-left: 5px;
    padding-top: 4px;
    width: 199px;
}
.tooltipinner ul li:hover {
    background-color: #BBAEA5;
    background-image: url("../../Images/UIFiles/Menu/SubmenuBgHover.jpg");
    background-position: left bottom;
    background-repeat: repeat-x;
    border-top: 1px solid #C1BFBD;
    cursor: pointer;
    float: left;
    padding-left: 5px;
}
.tooltipinner ul li a {
    color: #000000;
    font-size: 12px;
    font-weight: 400;
    text-decoration: none;
}
.tooltipinner ul li a:link {
    color: #000000;
    min-width: 200px;
    text-decoration: none;
}

I was also trying to put a div inside a but block element can not be placed inside a. How can I fixed this.

Here is a fiddle
http://jsfiddle.net/qry45/2/
http://jsfiddle.net/qry45/4/

like image 283
शेखर Avatar asked Feb 21 '13 05:02

शेखर


People also ask

How do I change the width of an anchor tag?

You need to make your anchor display: block or display: inline-block; and then it will accept the width and height values.

Can we give width to anchor tag?

An anchor is an inline element by default so you can't add dimensions to it unless you change its display property.

How do you increase the size of a tag?

To change the font size in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <p> tag, with the CSS property font-size. HTML5 do not support the <font> tag, so the CSS style is used to add font size.


1 Answers

Something like this in your CSS:

.myClass li a {
    width: 100%;
}

Block elements can be placed inside inline elements (<a>, <span>, etc.) if you're using the HTML5 doctype, and if you set display: block; on the <a> element:

.myClass li a {
    display: block;
}
like image 184
Web_Designer Avatar answered Nov 14 '22 23:11

Web_Designer