CSS min-width property is not functioning - html

I have following problem:
I have div containing other elements and I try to make its width dependent from the content. I also restrict maximum width of this div. I use min-width and max-width in CSS, but it seems that min-width is not working. The width of div is always the max-width value, no matter what the content is.
Example:
I'd like to have the white div (that is main div, I was talking about) strictly around the form that is in it, without empty spaces on the left and right side. I gave the form style max-width:500px to show that even if content is small, the main div stays the same.
HTML
<div class="gInnerBox sInnerBoxMain">
<form style="max-width:500px; margin-left: auto; margin-right: auto">
<div id='content'>
<!-- CONTENT -->
</div>
</form>
</div>
CSS
.gInnerBox{
position: relative;
background-color: #fff;
opacity: 0.9;
padding: 10px 10px 10px 10px;
box-shadow: -5px -5px 20px #000, 5px 5px 20px #000;
-moz-box-shadow: -5px -5px 20px #000, 5px 5px 20px #000;
-webkit-box-shadow: -5px -5px 20px #000, 5px 5px 20px #000;
border: 1px solid #000;
border-radius: 20px;
-moz-border-radius: 20px;
-webkit-border-radius: 20px;
}
.sInnerBoxMain{
max-width: 1000px;
min-width: 500px;
margin-left: auto;
margin-right: auto;
top: 50px;
}
(source: wstaw.org)

By default, a block-level element will expand to fill as much width as possible. So its width is basically "100%" (sort of) and you're saying a maximum of 1000px, so it's expanding to the maximum of 1000px. The minimum width is still being achieved (it's at least 500px). Try setting display: inline-block on the element and see if that helps you out any. This should make it only expand as far as its content while still paying attention to the minimum and maximum widths. You may have to add a breaker <br /> after to make the rest of your content adapts to it being inline.

Related

Border causes a gap in between border and content when zoomed out

I am trying to have an outside div with a border and have divs inside with content that can have a dynamic height. Problem is that when zooming out, there are some random spaces that appear at the top( on chrome browser at 67%).
How can this be fixed? (the background color has to stay white, position absolute can not be used)
js fiddle: http://jsfiddle.net/Arminaspam/djpervLh/13/
border-radius: 13px;
box-shadow: -20px 20px #f6f5f7;
margin: 20px auto;
padding: 0;
text-align: left;
width: 266px;">
<div style="background-color: white;
border-radius: 13px;
border: 2px solid #0048c1;">
<div style="
border-radius: 10px;
color: #fff;
padding: 15px;
background-color: #0048c1;">
<div>
Text that might be longer and take a dynamic amount of height in it
</div>
</div>
</div>
</div>```
chrome rendenders broders in a strange way, to fix this i used
box-shadow: 0px 0px 0px 2px #3d3691, -20px 20px 0 0 #f6f5f7 to act as a border and this doesnt bug out with differend zoom out values

Make Unordered List Height of Parent

I have a menu in an unordered list - I need to make each <li> the height of it's parent. I know this is pretty basic, I am not sure what I am doing wrong.
<div class="menu">
<ul>
<li class="current_page_item">
Home
</li>
<li class="page_item page-item-2">
Sample Page
</li>
</ul>
</div>
And I have the following CSS:
.main-navigation ul {
float: left;
list-style: outside none none;
margin: 0;
padding-left: 16px;
padding-right: 16px;
}
I don't have any CSS rules for the div that contains it.
The above is contained in a tag and I don't have any height set for it.
It is the height of an image contained within it.
The actual website is: http://notthedroidyouarelookingfor.com/
I need to make each <li> the height of it's parent so I can set a top border when the link is active.
The height of a block element defaults to the height of the block's
content. So, given something like this:
<div id="outer">
<div id="inner">
<p>Where is pancakes house?</p>
</div>
</div>
#inner will grow to be tall enough to contain the paragraph and
#outer will grow to be tall enough to contain #inner.
When you specify the height or width as a percentage, that's a
percentage with respect to the element's parent. In the case of width,
all block elements are, unless specified otherwise, as wide as their
parent all the way back up to <html>; so, the width of a block
element is independent of its content and saying width: 50% yields a
well defined number of pixels.
However, the height of a block element depends on its content
unless you specify a specific height. So there is feedback between the
parent and child where height is concerned and saying height: 50%
doesn't yield a well defined value unless you break the feedback loop
by giving the parent element a specific height.
The credits of the above are for #muistooshort: https://stackoverflow.com/a/5658062/4966662
I guess you want set the height of each li to vertical align the menu, if I'm right, here you have a workaround using flexbox:
body{
margin: 0;
}
.main-navigation {
background-color: #fff;
margin-left: auto;
margin-right: auto;
-webkit-box-shadow: 3px 2px 2px 0px rgba(0, 0, 0, 0.75);
-moz-box-shadow: 3px 2px 2px 0px rgba(0, 0, 0, 0.75);
box-shadow: 3px 2px 2px 0px rgba(0, 0, 0, 0.75);
margin-bottom: 4px;
}
#middleNavigation {
margin-left: auto;
margin-right: auto;
width: 960px;
display: flex;
}
.main-navigation a {
font-size: 1.4rem;
font-size: 14px;
font-weight: normal;
margin-left: 1em;
text-decoration: none;
padding: 0 0.8em;
word-spacing: 4px;
font-family: Arial;
color: #000;
border-top: 4px solid transparent;
display: flex;
align-items: center;
}
.main-navigation a:hover {
border-top-color: #000;
}
<nav role="navigation" class="site-navigation main-navigation">
<div id="middleNavigation">
<img src="http://notthedroidyouarelookingfor.com/wp-content/themes/striker/images/NTDYALF-Logo.png" alt="" id="NTDYALFLogo">
<span>Home</span>
<span>Sample Page</span>
</div>
</nav>
<p>Hover the links to see the border</p>
Here a working JSFiddle to play with
You need to set height manually or through script, I believe this cannot achieved in css.
Also the parent 'div.menu' is not the height of logo image because the ul is float:left. You actually need to apply float:left to div.main just in case to make sure you dont face any issues further on that.

despite that I used "margin: 0 auto", section is 10px more on the right side

The section on my page, should be in the middle of the page. Here the code if the section:
section{
margin: 0 auto;
margin-top: 100px;
margin-bottom: 50px;
width: 1000px;
but the section is 10px more on the right side. If you change the size of the page you can see it better:
I hope you can see my problem and can help me. Tell me if you want that I write the whole css file here.
Your article tag is overflowing the container. Its width ends up being 300px + 4px + 4px because of the border. If you set the box-sizing to be border-box, width will account for border correctly:
article {
width: 1000px;
border: 4px solid rgb(25, 25, 25);
background-color: rgb(75, 75, 75);
float: left;
-webkit-box-shadow: 0px 0px 3px 1px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 0px 3px 1px rgba(0,0,0,0.75);
box-shadow: 0px 0px 3px 1px rgba(0,0,0,0.75);
box-sizing:border-box;
}
A lot of frameworks, such as Twitter Bootstrap, will do *{box-sizing:border-box;} because it's much more intuitive.
Edit:
Note that while this solution is a common pattern, changing box-sizing in an existing page can create other things to pop up, especially since you've been using px widths instead of percentage based widths. You may want to just do a width:308px to the section prevent the other issues.
I would recommend border-box as more robust, but it's up to you.

Fiddling with wrappers width

I'm trying to extend my wrapper, but it's not extending, and if it does it goes past that "X" button you see on the overlay.
Code:
#hire-wrapper {
margin: 0 auto;
position:relative;
right: 140px;
width: 900px;
margin-top: 15px;
margin-bottom: 20px;
border: 1px solid green;
}
#hire-content {
float:left;
width:500px;
border: 1px solid #E8E8E8;
margin-bottom: 3px;
margin-left: 5px;
color: #8E8E8E;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
-moz-box-shadow: 0 0 3px 3px #888;
-webkit-box-shadow: 0 0 5px 5px#888;
box-shadow: 0 0 5px 3px #888;
padding: 4px 0 0 5px;
}
.hire-right {
float: right;
width: 420px;
display: block;
border: 1px solid grey;
}
That green line is the wrapper, I'm just using that to see where the width stands. I'm trying to get that other box right next to it, but i'm having trouble and it has something to do with my wrapper. Any ideas?
http://jsfiddle.net/gkKa5/
thanks
Have a look at adding a clearfix solution to counter 0 height floated elements.
I would also recommend adding a box-sizing style to all your elements so that you dont run into issues with padding pushing the width of content outwards
This should help with calculating exact widths of your elements should you want to continue with using float for your positioning.
An alternative to exact widths for your two elements would be to use something like percentage based widths for your internal sections. (This should also allow you to more create responsive sizing based on container width rather than hard coding each of the internal sides - but this is just a personal preference)
Have a look at this updated fiddle
PS. watch your html tag closures (there were a few extra open tags in your code)

Regarding the absolute positioning property

I have a div which I have positioned using the absolute positioning property of css. And now I want to know whether there is a way to allow this div showing in the exact same position that I am seeing right now in my screen even when the screen is smaller or larger without changing the absolute positioning property of the div?
this is just a rough example:
<div class="name"> I am somewhere in the body </div>
...................
..................so and so codes...
..................
<div class="display">I want to stand beside the class called name </div>
If I write the css for the display, Then it comes exactly beside the class name
.display {
position: absolute;
width: 200px;
top : 132px; [assume]
left : 200px; [assume]
border: #D3D3D3;
-webkit-box-shadow: 5px 5px 15px #888;
-moz-box-shadow: 5px 5px 15px #888;
box-shadow: 5px 5px 15px #888;
}
It is displaying correct for my screen. But if the screen size varies then it is no longer showing the correct position since I have used the absolute positioning property. But now I want to find whether there is a way or a trick to solve it without changing the absolute positioning property.
Wrap this like -
<div id="someId">
<div class="display"></div>
</div>
and add this css
#someId {
position: relative;
width: 0;
height: 0;
}
This seems like something for the float property, change your css like:
.display {
float:right;
width: 200px;
border: #D3D3D3;
-webkit-box-shadow: 5px 5px 15px #888;
-moz-box-shadow: 5px 5px 15px #888;
box-shadow: 5px 5px 15px #888;
}