css - How is Bootstrap's `nav` class making anchors move to their own line -
i'm trying figure out css causing a
elements sit on own lines when have bootstrap's nav
class, when can't find meaningful difference in styles applied them vs. a
elements without nav
. i've looked @ rules applied , compared computed styles, , i'm not seeing explain it.
here's example: a
in first paragraph (with nav
class) sits on own line, whereas a
in second doesn't:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" /> <p>before <a id="a1" class="nav" href="#">link</a> after</p> <p>before <a id="a2" href="#">link</a> after</p>
if inspect a.nav
element, see rule applied:
.nav { padding-left: 0; margin-bottom: 0; list-style: none; }
...but don't see how causes sit on own line. wrote code compare computed styles of 2 a
elements in example above, in case somehow magically missing other rule. doesn't it; computed styles identical other list-style-type
(and therefore list-style
):
(function() { var s1 = getcomputedstyle(document.getelementbyid("a1")), s2 = getcomputedstyle(document.getelementbyid("a2")), diffs = {}; function logdifferences(prop) { var s1value = s1[prop], s2value = s2[prop]; if (prop != "csstext" && s1value !== s2value) { diffs[prop] = { s1: s1value, s2: s2value } } } object.keys(s1).foreach(logdifferences); object.keys(s2).foreach(logdifferences); object.keys(diffs).sort().foreach(function(prop) { var diff = diffs[prop]; display(prop + ": '" + diff.s1 + "' != '" + diff.s2 + "'") }); function display(msg) { var p = document.createelement('p'); p.innerhtml = msg; document.body.appendchild(p); } })();
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" /> <p>before <a id="a1" class="nav" href="#">link</a> after</p> <p>before <a id="a2" href="#">link</a> after</p>
list-style-type
shouldn't cause behavior, , indeed if overrule still behavior, computed styles of elements being identical:
(function() { var s1 = getcomputedstyle(document.getelementbyid("a1")), s2 = getcomputedstyle(document.getelementbyid("a2")), diffs = {}; function logdifferences(prop) { var s1value = s1[prop], s2value = s2[prop]; if (prop != "csstext" && s1value !== s2value) { diffs[prop] = { s1: s1value, s2: s2value } } } object.keys(s1).foreach(logdifferences); object.keys(s2).foreach(logdifferences); object.keys(diffs).sort().foreach(function(prop) { var diff = diffs[prop]; display(prop + ": '" + diff.s1 + "' != '" + diff.s2 + "'") }); function display(msg) { var p = document.createelement('p'); p.innerhtml = msg; document.body.appendchild(p); } })();
a.nav { list-style-type: disc; }
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" /> <p>before <a id="a1" class="nav" href="#">link</a> after</p> <p>before <a id="a2" href="#">link</a> after</p>
so it's not list-style-type
.
nor order of elements:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" /> <p>before <a id="a2" href="#">link</a> after</p> <p>before <a id="a1" class="nav" href="#">link</a> after</p>
what that's causing a.nav
move own line?
note question isn't how fix it. we've fixed (they shouldn't have nav
, using else before applied bootstrap project , we've renamed ours bootstrap's rules don't incorrectly applied). question what's causing it?
this due ::before
, ::after
pseudo-elements. they're set clear floated elements surrounding them, side affect of cause element pushed down new line.
the offending style quite simply:
...::before, ...::after { display: table; content: " "; }
where ... here long chain of selectors including .nav::after
, .nav::before
.
Comments
Post a Comment