Reputation: 1265
I have a navigation bar similar to this, and my problem is I want the search field to stretch to the end of the .PageMenu
container. I have tried to use 100%
on these elements:
.search_query
element, which puts the search field on the next line while keeping the same Y position..SearchForm
Element, which also puts the search field on the next line, but it's also moved to the start of the line.I've tried a few other things, but not really sure where to go from here.
All the code and stuff is in the CodePen Link: http://codepen.io/DrOverbuild/pen/PGyLpW/
Upvotes: 0
Views: 40
Reputation: 2701
I suggest using flex-boxes. Then increase the elements inside to width: 100%
The relevant changes in the code would be:
#SearchForm {
display: flex;
flex: 1;
}
#SearchForm form {
width: 100%;
}
#search_query {
width: calc(100% - 22px); /* minus the width of the button */
}
Full version on codepen
Upvotes: 2
Reputation: 9063
The property 'width' inherits directly from the parent element, so if you want element that's low in the DOM hierarchy to be 100% of the page for example, you have to make sure that all its parents are, or make it independent of the DOM or something else. Here's a small sample of what I think you're wanting, a few links and a search bar beside them that stretches to fill the rest of the screen. Just save this in a html file and open it in the browser:
<div id="pageMenuContainer" style="width:100%;min-width:350px;">
<a href="#">Contact us</a>
<a href="#">Shipping</a>
<a href="#">Potato</a>
<div style="float:right;width:calc(100% - 200px)">
<input type="text" placeholder="Search..." style="width:100%;"/>
</div>
</div>
Upvotes: 0