Min width equal to child width - html

I have a page with a header, content, and footer element. The wrapper arround these elements is 70% of the window width. What I'm looking for is a way to set a minimum width for this wrapper. In my first fiddle it shows how it is right now: http://jsfiddle.net/fwqZX/
HTML:
<div class=outerWrapper>
<nav>
<ul>
<li class='active' id=tab1>Test1</li>
<li id=tab2>Test2</li>
<li id=tab3>Test3</li>
</ul>
</nav>
<section class=content id=content>
<div>
sdflnsdfskdjfisahdfosad
</div>
</section>
<footer>Footer</footer>
</div>
CSS:
html {
overflow-y: scroll;
font-family: Trebuchet MS;
color: rgba(57,58,54, 0.8);
text-shadow: 1px 4px 6px #fff, 0 0 0 #000, 1px 4px 6px #fff;
font-size: 150%;
}
header, nav, footer{
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
white-space: nowrap;
cursor: default;
}
body {
margin: 0;
text-align: center;
background: url('dark_wall.png'), #393A36;
}
.content, footer, nav li {
background-color: #fff;
box-shadow: 0 0 10px -1px #000;
}
.outerWrapper {
width: 70%;
display: inline-block;
min-width: 500px;
}
nav ul {
margin: 0;
padding: 0;
text-align: left;
}
nav li {
transition: all 0.2s linear;
padding: 0.8em 0.5em;
display: inline-block;
min-width: 120px;
text-align: center;
border-radius: 5px 5px 0 0;
margin-right:10px;
}
nav li:not(.active) {
box-shadow: 0 -6px 10px -7px #000, 10px 0 10px -11px #000, -10px 0 10px -11px #000, inset 1px -10px 10px -11px #444;
background-color:#eee;
cursor: pointer;
}
nav .active {
box-shadow: 0 -6px 10px -7px #000, 10px 0 10px -11px #000, -10px 0 10px -11px #000;
}
.content {
padding: 1em;
text-align:left;
overflow: hidden;
/*transition: height 0.2s ease-in-out;*/
}
.content div {
transition: all 0.2s ease-in-out;
}
.content .hidden {
opacity: 0;
}
footer {
font-size: 0.8em;
padding: 0.8em;
text-align: left;
margin: 20px 0;
}
In this fiddle it shows how I want it to be: http://jsfiddle.net/gkZL4/
The difference between this is only a min-width value on the .outerWrapper class.
The problem with the second fiddle, is that I have a hard coded min-width value. I would like the minimum width of the .outwrapper to adapt to the width of the navigation(the tabs).
I want to prevent using javascript for this. If it is not possible without, I will use a hard coded min-width value.
Any help with this would be greatly appreciated.

You need to give a min-width in stead of a normal width.
Make it like this:
.outerWrapper {
min-width: 70%;
display: inline-block;
}

else, if still want it to be width:70%; or any size that feets content (width:auto;/* wich is equal to not give width at all */) + margin:auto;
Use display:table instead.
Using display:table will allow you not too mind how many tabs or how much content. The CSS is then , reusable within any similar structure and class names.
demo (no width/width or min-width and 3/4 tabs content wider/smaller)
http://jsfiddle.net/gkZL4/2/
.outerWrapper, .nowidth {
display: table;/*or inline-block*/
margin:auto;/* inefficient if inline-block, set text-align:center on parent */
}
.width {
width:70%;
}
.minwidth {
min-width:70%;
}
If you think display:table is inapropriate for old browser, you should first watch for display:inline-block .
IE6 applies width as min-width, IE7 will applie width given or full width. (any display:inline-block rules used on block-level element will need to be adapted for those two IES => haslayout with: display:inline; and zoom:1;
You may add a max-width and overflow-x:auto; to #content to avoid it to become to large on width .

Related

H1 won't center with a set width

I am trying to center an h1 tag, but it doesn't work when I set it's width. When I don't set a specific width it works, but I would like to keep the width at 400. My code is below.
body {
margin: 0;
font-family: Arial;
font-size: 1em;
}
.navbar-ul {
margin: 0;
color: white;
background-color: black;
overflow: hidden;
-webkit-box-shadow: -1px 10px 20px 0px rgba(0,0,0,0.75);
-moz-box-shadow: -1px 10px 20px 0px rgba(0,0,0,0.75);
box-shadow: -1px 10px 20px 0px rgba(0,0,0,0.75);
}
a {
color: white;
}
li, a {
text-decoration: none;
display: inline-block;
padding: 10px;
background-color: black;
transition: 1s;
border: solid 1px transparent;
}
li:hover, li:hover a {
background-color: #3f3f3f;
}
.header-text {
border: solid 5px black;
width: 400px;
text-align: center;
padding: 25px;
}
li {
list-style-type: none;
float: left;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Dark Website Template by Jordan Baron</title>
<link rel="stylesheet" href="styles-main.css">
</head>
<body>
<div class="navbar">
<ul class="navbar-ul">
<strong><li>HOME</li>
<li>CONTACT</li>
<li>ABOUT</li></strong>
</ul>
</div>
<strong><h1 class="header-text">DARK</h1></strong>
</body>
</html>
I don't think the other elements are the problem, but hey, it's a possibility.
The h1-element is a block-element. This means that the width is 100% by default. By using text-align: center you only center the text inside the element, not the h1 itself.
When you set the width to 400px the text is still centered inside the block, but the element itself no longer has a full-width.
The solution would be to center the element as a whole. This can be done by setting the horizontal margin to auto.
This should work for you:
.header-text {
border: solid 5px black;
width: 400px;
text-align: center;
padding: 25px;
margin: 0 auto;
}
<h1 class="header-text">DARK</h1>
For more information about centering with CSS, check out this guide: https://css-tricks.com/centering-css-complete-guide/
If you're trying to center the entire element, you can use the auto value for the left and right margin on the header:
.header-text {
margin: 0 auto;
}

centering a button in my menubar

I'm trying to align a button so that it stays in the center of my menu bar. The jsfiddle will show you what I mean.
this does not seem to work:
vertical-align: middle;
Here is the code: jsfiddle!
Unfortunately, vertical aligning is one of the tougher things to do in HTML/CSS, depending on the situation.
However, if you not want to use absolute heights and must have it vertically centered, you can always changed the display to table, instead of block: display: table;
I edited your original jsfiddle for a working example.
I added /* Comments */ where I either added or changed CSS.
save yourself some time and try to use bootstrap.
here is the css you can use :
.parent {
position: relative;
}
.child {
position: absolute;
top: 50%;
height: 100px;
margin-top: -50px; /* account for padding and border if not using box-sizing: border-box; */
}
but you can find a complete detailed solutions if you take a little time and go to this link :
https://css-tricks.com/centering-css-complete-guide/
Add below to your handle class
https://jsfiddle.net/420qk42v/2/
text-align:center;
.handle {
width: 100%;
background-color: #ffe2e2;
font-family: "century gothic";
opacity: 0.9;
box-sizing: border-box;
padding: 10px 5px;
cursor: pointer;
display: block;
text-align: center; /* this is the change */
}
Is that what you meant?
I did a test with the vertical align and it works if you remove the absolute positioning on the menu button.
I also made a new div around the text "menu" and then set that to position absolute while setting the handle to align the text to the right - the button will only move the right.
HTML
</br>
</br>
</br>
<nav>
<div>
<div class="handle">
<!--<div class="heading">MENU</div>-->
<!-- Menu button if on mobile device -->
<a class="menu">
<span class="line"></span>
</a>
</div>
</div>
</nav>
CSS
.handle {
width: 100%;
background-color: #ffe2e2;
font-family: "century gothic";
opacity: 0.9;
box-sizing: border-box;
padding: 10px 10px;
cursor: pointer;
display: block;
text-align: right;
}
/*added class for the menu - the heading text*/
.heading {
/*This is commented out in the markup but is to keep the menu heading on the right*/
position: absolute;
}
.menu {
border-radius: 3px;
border: 1px solid #ccc;
color: #5f5f5f;
font-weight: bold;
display: inline-block;
width: 1.9em;
vertical-align: middle;
height: 1.75em;
padding: 2px 0 0 0;
box-sizing: border-box;
}
.menu:hover {
/* background-image: linear-gradient(#e63d44,#c11a22);*/
/*box-shadow: 0 1px 3px 0 rgba(0,0,0,0.22);*/
}
.menu .line {
background: rgb(184,184,184);
border-radius: 2px;
box-shadow: 0 5px 0 0 rgb(184, 184, 184), 0 -5px 0 0 rgb(184, 184, 184);
display: block;
margin: 10px auto 0 auto;
height: 3px;
width: 16px;
content: " ";
overflow: visible;
}
.menu:hover .line {
background: rgb(255,255,255);
box-shadow: 0 5px 0 0 rgb(255,255,255), 0 -5px 0 0 rgb(255,255,255);
}
Js fiddle to test - https://jsfiddle.net/ToreanJoel/b7mgaasj/

Navigation bar won't entirely fill screen width

I've started making a navigation bar using the nav tag, which worked perfectly. Using CSS, I set the width of my nav tag to 100%, as well as the border and padding set to 0.
I seem to have a few pixels on each side of the nav bar that aren't getting filled. I want the entire width to be covered with the nav bar, but I can't get it to work. Here is my html:
<nav>
<ul>
<li>Home</li>
<li>
Test1 <span class="carrot"></span>
<div>
<ul>
<li>TestA</li>
<li>TestB</li>
<li>TestC</li>
</ul>
</div>
</li>
<li>Test2</li>
<li>Test3</li>
</ul>
</nav>
Css:
nav {
background-color: #fff;
border: 1px solid #dedede;
border-radius: 4px;
box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.055);
color: #888;
display: block;
margin: 8px 22px 8px 22px;
overflow: hidden;
width: 100%;
margin: 0;
padding: 0;
}
What can I do to fix this?
Set body to margin 0
CSS
body{
margin: 0px;
}
All HTML document by default have a margin surrounding all four corners of it. As desirable as margins are in most cases, sometimes they with your design, such as a header bar that spans the entire page horizontally. In that case you have to explicitly assign 0 to the margins of the body.
body{
margin: 0px;
}
Explanation of the answer given by #Luis P.A
Start all projects with the following CSS rule:
*{
border: 0;
padding: 0;
margin: 0;
}
All browsers have some default css rules. With this css rule i it will reset the browser default css...
nav {
background-color: #fff;
border: 1px solid #dedede;
border-radius: 4px;
box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.055);
color: #888;
display: block;
/* margin: 8px 22px 8px 22px; */
/* overflow: hidden; */
/* width: 100%; */
margin: 0;
padding: 0;
/* notice below: */
position: fixed;
left: 0;
right: 0;
}
Always use on your css stylesheet docs this first lines:
* {
box-sizing: border-box;
}
body, html {
margin: 0 auto;
padding: 0;
}
You can eliminate presets on browsers by "normalizing", just add this link in the head:
"https://cdnjs.cloudflare.com/ajax/libs/normalize/4.1.1/normalize.min.css"
Also add the CSS:
* { box-sizing : border-box; }
I don't know how to use Markdown yet, if that's required here..
just add nav width
nav
{
width:100%;
}

Child elements hover/link in CSS

I'm trying to get some elements to move slightly when the user mouses over them (they form buttons on a navbar). However, my code doesn't seem to work. The text in the boxes should also be clickable but that doesn't seem to work either. Here's the code:
#navbar {
position: relative;
width: max-width;
height: auto;
margin-left: 2%;
}
.nav_tab{
background-image: url('dark_exa.png');
border: 2px dashed grey;
/* rounded borders of 5px in firefox */
-moz-border-radius:10px;
/* rounded borders of 5px in chrome and other browsers */
-webkit-border-radius:10px;
/* rounded borders of 5px in browsers that support css3 */
border-radius:10px;
/* shadows for different browsers */
-moz-box-shadow: 0 0 0 3px black, 2px 1px 4px 4px rgba(10,10,0,.5);
-webkit-box-shadow: 0 0 0 3px black 2px 1px 4px 4px rgba(10,10,0,.5);
box-shadow: 0 0 0 3px black, 2px 1px 6px 4px rgba(10,10,0,.5);
position: relative;
height: auto;
width:20%;
z-index: -1;
margin-left: 2%;
margin-right: 2%;
top: -30px;
display: inline-block;
}
.nav_tab:hover{
position: relative;
top: +5px;
}
h1 {
font-size:40px;
text-align: center;
color: white;
font-family: "Gabriela";
margin: 20px;
margin-top: 130px;
}
h2 {
font-size:30px;
text-align: center;
color: white;
font-family: "Gabriela";
margin: 10px;
margin-top: 40px;
}
And the HTML:
<div id="navbar">
<div class="nav_tab"><h2>Zues</h2></div>
<div class="nav_tab"><h2>Jack</h2></div>
<div class="nav_tab"><h2>Denise</h2></div>
<div class="nav_tab"><h2>Joel</h2></div></div>
I'm not entirely sure what's going on here, though I presume it's some kind of parent-child issue.
Thanks.
The link is not clickable because you gave the .nav_tab class a negative z-index value just adjust it to a value => 0 and it'll work.
The z-index: -1; of the .nav_tab css it's your problem, it makes the container behind the page so any mouse event won't work (hover, pointer, etc) remove it and your ready to go:
see the jsfiddle demo:
http://jsfiddle.net/QmVFR/64/

Padding in <li>

see jsFiddle example here
I'm applying padding-top to an li to try to align the text nearer to the bottom. But it's just making the li bigger, even though there seems plenty of room to fit the text.
Any ideas?
<ul>
<li class="padded">x</li>
<li>x</li>
</ul>​
li {
width: 25px;
height: 25px;
border: solid 1px black;
display: inline;
margin: 0 2px 0 0;
float: left;
}
.padded {
padding: 3px 0 0 0;
text-align: center;
}
I get the same results in IE7 and Chrome, not checked any other browser.
The li.padding is growing larger because you have a height of 25px plus a padding-top of 3px.
The you should decrease the height of the li.padding if you want to increase the top-padding, yet have it remain the same height as the plain list item. So to have a 25px high block with 3px padding-top, you should set the height to 22px with a padding of 3px.
li {
width: 25px;
height: 25px;
border: solid 1px black;
display: inline;
margin: 0 2px 0 0;
float: left;
}
.padded {
padding-top: 3px;
height:22px /* original height (25px) minus padding-top (3px) */
text-align: center;
}