Home Ask Login Register

Developers Planet

Your answer is one click away!

WutWut February 2016

Setting width of an inner div to the width of the container

I am trying to modify the bootstrap css, I want the .dropdown-menu to expand to the full width of the container, but setting width:100% sets the width to parent width. I tried using jquery and this works but as the menus increase they don't fit into the container. how do I fix this such that each dropdown menu has the same width and fits the whole container from left to right? jsfiddle


$(window).bind("load resize", function(){


<div class="container">

  <!-- Static navbar -->
  <nav class="navbar navbar-default">
    <div class="container-fluid">
      <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>
      <div id="navbar" class="navbar-collapse collapse">
        <ul class="nav navbar-nav">
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
            <ul class="dropdown-menu extend">
              <li><a href="#">Action</a></li>
              <li><a href="#">Another action</a></li>
              <li><a href="#">Something else here</a></li>
              <li role="separator" class="divider"></li>


Sahil February 2016

$(window).bind("load resize", function(){

function adjust(){
var left = ($('body').width()-$('.container').width())/2;

Please try this out. Here is the working fiddle.

Post Status

Asked in February 2016
Viewed 2,923 times
Voted 14
Answered 1 times


Leave an answer

Quote of the day: live life