Change width of css links

I am coding a webpage from scratch and I have a problem. I know I am using iframes, but I am not, so please leave that.


Links that are not in the sidebar, those contained in the page content, are correctly written with CSS / CSS3 in mind. However, for some reason, when you click on the link, its width changes, which is not desirable. However li

, a:link

and a:hover

all are set width, so I don't know how this could have happened. This also works when you hold down the mouse button.

<head>
    <title>BlackOwlStables</title>
    <style>
        body {
            background: rgba(112, 111, 111, 1);
            background: -moz-radial-gradient(center, ellipse cover, rgba(112, 111, 111, 1) 0%, rgba(5, 5, 5, 1) 100%);
            background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%, rgba(112, 111, 111, 1)), color-stop(100%, rgba(5, 5, 5, 1)));
            background: -webkit-radial-gradient(center, ellipse cover, rgba(112, 111, 111, 1) 0%, rgba(5, 5, 5, 1) 100%);
            background: -o-radial-gradient(center, ellipse cover, rgba(112, 111, 111, 1) 0%, rgba(5, 5, 5, 1) 100%);
            background: -ms-radial-gradient(center, ellipse cover, rgba(112, 111, 111, 1) 0%, rgba(5, 5, 5, 1) 100%);
            background: radial-gradient(ellipse at center, rgba(112, 111, 111, 1) 0%, rgba(5, 5, 5, 1) 100%);
            filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#706f6f', endColorstr='#050505', GradientType=1);
        }
        p {
            font-family:times, serif;
            color:#1a1a1a;
            padding:10px;
            margin:0;
            font-size:12px;
            letter-spacing:1px;
            text-align:justify;
        }
        h1, h2, h3 {
            font-family:times;
            letter-spacing:2px;
            font-size:30px;
            color:#1a1a1a;
            margin:0;
            padding:0;
        }
        iframe {
            width:650px;
            height:700px;
            border:1px solid #777777;
        }
        #content {
            width:860px;
            background:#888888;
            border:1px solid black;
            padding:20px;
            position:relative;
            margin:20px auto 0;
        }
        #body {
            margin-left:210px;
        }
        #side {
            width:200px;
            float:left;
            border-right:1px solid #666;
            position:absolute;
            top:10px;
            bottom:10px;
        }
        ul#navbar {
            list-style-type:none;
            margin:0;
            margin-left:-20px;
            margin-top:30px;
            padding:0;
        }
        #navbar li {
            text-align:center;
        }
        #navbar a:link, a:visited, a:active {
            transition: all 1s;
            display:inline-block;
            text-align:center;
            text-decoration:none;
            color:white;
            text-transform:uppercase;
            line-height:20px;
            font-size:10px;
            letter-spacing:3px;
            max-width:50px;
        }
        #navbar a:hover {
            transition:all 1s;
            background:#0a0a0a;
            max-width:180px;
        }
        #links {
            list-style-type:none;
            display:block;
            width:390px;
            margin:0 auto;
            padding:0;
        }
        #links li {
            text-align:center;
            display:inline-block;
            width:120px;
            overflow:hidden;
            margin:0;
        }
        #links a,a:link, a:active, a:visited, a:focus {
            transition: all 1s;
            display:inline-block;
            text-align:center;
            text-decoration:none;
            color:white;
            text-transform:uppercase;
            line-height:20px;
            font-size:10px;
            letter-spacing:1px;
            padding:0 2px;
            width:120px;
        }
        #links a:hover {
            transition:all 1s;
            background:#0a0a0a;
            width:120px;
        }
    </style>
</head>

<body>
    <div id="content">
        <div id="side">
            <ul id="navbar">
                <li><a href="#">Text</a>
                </li>
                <li><a href="#">Text</a>
                </li>
                <li><a href="#">Text</a>
                </li>
                <li><a href="#">Text</a>
                </li>
            </ul>
        </div>
        <div id="body">
        <h2>title hurr</h2>
            <p>Text</p>
            <ul id="links">
                <li><a href="/mog.html" target="box">M. Oceangaze</a></li
                ><li><a href="/lbh.html" target="box">L. Bloodhorn</a></li
                ><li><a href="/apv.html" target="box">A. Poisonvine</a></li
                ><li><a href="/vft.html" target="box">V. Flickertail</a></li
                ><li><a href="" target="box">-air-</a></li
                ><li><a href="" target="box">-water-</a></li
                >
            </ul>
            <iframe name="box">Your browser does not support iframes.</iframe>
            <p>2014 &copy; Brittny Baldwin</p>
        </div>
    </div>
</body>

      

I just would like to know what is causing the unwanted width to change and how I can fix it.

EDIT: NOT NAVBAR. INNER #links

UL.

+3


source to share


3 answers


#navbar a:link, #navbar a:visited, #navbar a:active {
    ....
}

#links a, #links a:link, #links a:active, #links a:visited, #links a:focus {
     transition: all 1s;
     display:inline-block;
     text-align:center;
     word-wrap: normal;
     overflow-wrap: normal;
     white-space: nowrap;
     text-decoration:none;
     color:white;
     text-transform:uppercase;
     line-height:20px;
     font-size:10px;
     letter-spacing:1px;
     padding:0 2px;
     width:120px;
     margin-right:1px;
}

      



+1


source


it max-width:50px;

is installed in #navbar a:link, a:visited, a:active

. change this or remove it and it will work

        #navbar a:link, a:visited, a:active {
            transition: all 1s;
            display:inline-block;
            text-align:center;
            text-decoration:none;
            color:white;
            text-transform:uppercase;
            line-height:20px;
            font-size:10px;
            letter-spacing:3px;
            max-width:50px; //<--THIS
        }

      

UPDATE



since showdev pointed out the reason the max-width is bleeding is because you are specifying at all a

, be sure to include them under your parent:

 #navbar a, #navbar a:link, #navbar a:active, #navbar a:visited, #navbar a:focus {

      

0


source


The problem is with the following overlapping definitions:

Below you set the visited and active states of all links:

#navbar a:link, a:visited, a:active { ... }

      

Below you set the links, active, visited and focal states of all links:

#links a, a:link, a:active, a:visited, a:focus { ... }

      

You need to provide a parent for each state to prevent overlap between the two definitions. For example:

#navbar a:link, 
#navbar a:visited, 
#navbar a:active {
    ....
}

#links a, 
#links a:link, 
#links a:active, 
#links a:visited, 
#links a:focus {
    ....
}

      

WORKING EXAMPLE

0


source







All Articles