/    Sign up×
Community /Pin to ProfileBookmark

How to make all child elements same height

I am creating a menu across the top of my page. All but one of the items in the menu is a single line, the other being 2 lines, high. I want to have the 1-line items the same height as the 2-line item but can’t figure out where to add the 100% height in my CSS. Here’s a textual version of what I have:

Home Products Staff Contact
[INDENT][INDENT][INDENT][INDENT]Us[/INDENT][/INDENT][/INDENT][/INDENT]

Right now, I have the text items centered vertically within their own elements, but the first 3 items have a different height than the last item thus making it appear to be floating when you roll over them instead of extending to the bottom of the menu’s height. Here is the HTML:

[code=html]<div class=”container”>
<div class=”navbar-header”>
<button type=”button” class=”navbar-toggle collapsed” data-toggle=”collapse” data-target=”#navbar” aria-expanded=”false” aria-controls=”navbar”>
<span class=”sr-only”>Toggle navigation</span>
<span class=”icon-bar”></span>
<span class=”icon-bar”></span>
<span class=”icon-bar”></span>
</button>
<a class=”navbar-brand” href=”#”>
<img src=”images/logoSmall.png” alt=”Mikey Heads Baits”>
<caption>Handmade for Finest Quality</caption>
</a>
</div>
<div id=”navbar” class=”collapse navbar-collapse”>
<ul class=”nav navbar-nav text-right”>
<li class=”active”>
<a href=”#”>Home</a>
</li>
<li class=”dropdown”>
<a href=”#products” class=”dropdown-toggle” data-toggle=”dropdown” role=”button” aria-haspopup=”true” aria-expanded=”false”>Products
<span class=”caret”></span>
<ul class=”dropdown-menu”>
<li>
<a href=”#”>Hooks</a>
</li>
<li>
<a href=”#”>Lures</a>
</li>
</ul>
</a>
</li>
<li>
<a href=”#staff”>Pro Staff</a>
</li>
<li>
<a href=”#photos”>Photo Gallery</a>
</li>
<li>
<a href=”#contact”>Contact</a>
</li>
<li>
<a>Rippin Lips<br>Schedule</a>
</li>
</ul>
</div>
</div>[/code]

and here’s the associated CSS for this element:

[code=html]#navbar
{
min-height: 110px;
vertical-align: bottom;
}

.navbar-brand
{
margin-left: 5px;
}

.navbar-nav
{
margin-top: 60px;
margin-left: 20px;
}

.navbar-brand > img
{
margin-left: 35px;
}

.navbar-nav > li
{
background-color: #F00; //Only made this a different color to display height of li
color: green;
font-size: 16px;
font-weight: bold;
text-align: center;
}[/code]

If you create a page with this code, you should see something similar to my first attached file (MenuNow). Instead, what I want is what is in the MenuWanted image.

Chris Cote

[canned-message]attachments-removed-during-migration[/canned-message]

to post a comment
CSS

5 Comments(s)

Copy linkTweet thisAlerts:
@pdiddles03Jul 11.2016 — I would probably use flexbox to make them the same height. If you use Compass along with SASS and use the flexibility polyfill, you won't have any trouble at at all. Flexbox gives you the ability to actually make all of the siblings the same height as the tallest one.
Copy linkTweet thisAlerts:
@davidstephanJul 14.2016 — add [U]display:flex[/U] to your container class, like:.

container {

width: 320px;

display:flex;

}

For a programe like:

<div class="container">

<button>

<span class="big-text">Okay</span>

<span class="little-text">123</span>

</button>

<button>

<span class="big-text">Another Option</span>

<span class="little-text">456</span>

</button>

<button>

<span class="big-text">Nah!</span>

<span class="little-text">789</span>

</button>

</div>

How ever the FLEX property is only compatible with :Google Chrome v21.0 above (-webkit-)

Internet Explorer v10.0 above (-ms-)

Mozilla Firefox v18.0 above (-moz-)

Safari v6.1 above (-webkit-)

Opera v12.10 above
Copy linkTweet thisAlerts:
@vignesgangboardJul 18.2016 — One solution is to change the display value from inline-block to table-cell for the descendant div.item elements:

.row {

border: 1px solid red;

display: table;

border-spacing: 20px; /* For controlling spacing between cells... */

}

.item {

background: rgba(0,0,0,0.1);

display: table-cell;

}
Copy linkTweet thisAlerts:
@missmansiraoNov 28.2017 — Creating equal height columns with CSS is not as easy as it may first seem. HTML tutorial highlights the display problems that occur with multiple column layouts, and then shows a simple solution that works in all common web browsers. The method shown here is 100% CSS hack-free, image-free and JavaScript-free so it can even be used on the most strictly coded websites.

Full Article Here
Copy linkTweet thisAlerts:
@murumeNov 28.2017 — Sorry I don't have a solution but I'd advise against doing it the way it was suggested in the solution you gave. That was a great solution in 2008 before web page had to be responsive.

Is there any particular reason why you are avoiding a CSS framework? I believe they can take care of such a problem easily.

When all you are trying doesn't work maybe you can just give the list items a set width as below:
[CODE]
.navbar-nav > li {
background-color: #F00;
font-size: 16px;
font-weight: bold;
text-align: center;
display: inline-block;
height: 50px;
}[/CODE]

I don't know how you would align them as shown in you image. [CODE]vertical-align: middle;[/CODE] did not work for me
×

Success!

Help @chrscote spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...