Hello awesome programmers,
I have been struggling greatly with CSS for some time now. I have an issue when resizing a window, some of my divs begin to collapse down the page. (As shown)
Before:
before http://411metrics.com/pics/before.PNG
After:
before http://411metrics.com/pics/after.PNG
I have tried setting the min-width to 100% on various divs and also tried setting the overflow to hidden.
Does anyone have any suggestions as to how to fix this?
My HTML:
<div id="navigation">
<div id="branding-logo"><img src="/Portal/images/sharktek-logo.png" width="35" height="35"></div>
<div id="branding">Sharktek Tracking</div>
<div id="link-wrap">
<div id="active-nav">Dashboard</div>
Reports
Call Logs
Manage Campaigns';
</div>
<div id="nav-user">
Welcome<br>
Account Settings
Logout
</div>
</div>
<div id="nav-accent"></div>
My CSS:
#navigation {
z-index:3;
position: fixed;
top: 0;
width: 100%;
min-width:100%;
color: #ffffff;
height: 60px;
text-align: center;
/* Adds the transparent background */
background-color: rgba(22, 29, 37,1);
color: rgba(1, 172, 237, 1);
}
#navigation a {
float:left;
font-size: 14px;
padding: 25px 25px 0 25px;
color: white;
text-decoration: none;
}
#link-wrap {
float: left;
overflow: hidden;
margin-left: 15%;
}
#active-nav{
z-index: 2;
float:left;
color:white;
height: 60px;
background: -webkit-linear-gradient(#346c83, rgba(1, 172, 237, 1)); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(#346c83, rgba(1, 172, 237, 1)); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(#346c83, rgba(1, 172, 237, 1)); /* For Firefox 3.6 to 15 */
background: linear-gradient(#346c83, rgba(1, 172, 237, 1)); /* Standard syntax */
}
#active-nav a:hover {
color:white;
}
#navigation a:hover {
color: grey;
}
#branding-logo {
margin-top: 15px;
margin-left: 10px;
float: left;
}
#branding{
margin-top: 20px;
margin-left: 10px;
font-size:1.4em;
color: white;
float: left;
padding: 0px;
}
#nav-accent {
z-index:2;
position: fixed;
top: 60px;
width: 100%;
color: #ffffff;
height: 2px;
padding-top: 1px;
/* Adds shadow to the bottom of the bar */
-webkit-box-shadow: 0px 0px 8px 0px #000000;
-moz-box-shadow: 0px 0px 8px 0px #000000;
box-shadow: 0px 0px 8px 0px #000000;
/* Adds the transparent background */
background-color: rgba(1, 172, 237, 0.95);
color: rgba(1, 172, 237, 1);
}
#nav-user {
color: white;
font-family:Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;
padding: 15px 30px 0 0;
font-size: .8em;
float:right;
}
#nav-user a{
margin: 0;
padding: 0 0 0 10px;
font-size:.8em;
}
I have had similar problems until I started to understand and apply absolute positioning. i.e. positioning relative the div you are in.
For absolute positioning the parent div must be set to relative positioning and after that you fix your inner elements to whatever side you like without having the browser take over the flow control.
e.g. in your case, with ...
#link-wrap {
position: absolute;
width: 500px;
/* ... the rest */
}
... your nav links will stop jumping all over the page. I made a few more tweaks in this fiddle http://jsfiddle.net/xb9cdu34/2/ .
Related
My target output want same as like blow image.
My CSS and HTML:
header {
height: 40px;
width: 100%;
position: fixed;
background: #00A6E3;
top: 0;
left: 0;
border-radius: 0 0 10px 10px;
padding: 15px;
box-shadow: 0 2px 5px rgba(44, 62, 88, 0.15);
display: block;
z-index: 5;
}
header .todoitem {
width: 100%;
height: 100%;
float: left;
border: none;
border-radius: 5px;
background: rgba(255, 255, 255, 0.2);
text-indent: 20px;
}
header input::-webkit-input-placeholder {
color: #fff;
}
<header>
<input type="text" name="todoitem" class="todoitem" placeholder="Enter your activity...">
</header>
After write my code input left side showing properly but the right side not showing properly. From my knowledge right side need show 15px padding. But I can't understand what wrong with my code.
Two possible solutions:
First, you could add box-sizing: border-box to your styles. As it is, your header is set to match the entire width of its container, and then the padding is applied outside that, which is the default behaviour for box-sizing, and which makes the padding extend outside the limits of the container.
Some more reading on css-tricks.com.
You also need to adjust the height to allow for the new box model (total height now includes the height of the padding) - here's your updated code:
header {
box-sizing: border-box;
height: 70px;
width: 100%;
position: fixed;
background: #00A6E3;
top: 0;
left: 0;
border-radius: 0 0 10px 10px;
padding: 15px;
box-shadow: 0 2px 5px rgba(44, 62, 88, 0.15);
display: block;
z-index: 5;
}
header .todoitem {
width: 100%;
height: 100%;
float: left;
border: none;
border-radius: 5px;
background: rgba(255, 255, 255, 0.2);
text-indent: 20px;
}
header input::-webkit-input-placeholder {
color: #fff;
}
<header>
<input type="text" name="todoitem" class="todoitem" placeholder="Enter your activity...">
</header>
Option 2: if you prefer to keep the default box model, you can use a calculated width to compensate for the padding: set the width of header to calc(100% - 30px) (be careful to keep the spaces around the - if you choose this option).
This solution is for you.
body{
margin:0;
padding:0;
}
header{
height: 40px;
display:block;
background: #00A6E3;
border-radius: 0 0 10px 10px;
padding:15px 15px 15px 15px;
box-shadow: 0 2px 5px rgba(44, 62, 88, 0.15);
z-index: 5;
}
header .todoitem{
height: 100%;
width:100%;
display:block;
border: none;
border-radius: 5px;
background: rgba(255, 255, 255, 0.2);
text-indent: 20px;
}
header input::-webkit-input-placeholder{
color: #fff;
}
<header>
<input type="text" name="todoitem" class="todoitem" placeholder="Enter your activity...">
</header>
You can do something like this, too.
header {
height: 70px;
width: 100%;
position:fixed;
background: #00A6E3;
top: 0;
left: 0;
border-radius: 0 0 10px 10px;
padding: 15px;
box-sizing:border-box;
}
header .todoitem {
width: 100%;
height: 100%;
float: left;
border: none;
border-radius: 5px;
background: rgba(255, 255, 255, 0.2);
text-indent: 20px;
}
header input::-webkit-input-placeholder {
color: #fff;
}
<header>
<input type="text" name="todoitem" class="todoitem" placeholder="Enter your activity...">
</header>
I have used box-sizing:border-box so padding is included in total width, and increased height of header, accordingly... Main problem was that your padding actually increased width of header - so header width was over 100% (100% + padding).
More about box-sizing: https://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing
header {
height: 40px;
background: #00A6E3;
top: 0;
left: 0;
border-radius: 0 0 10px 10px;
padding: 15px;
box-shadow: 0 2px 5px rgba(44, 62, 88, 0.15);
display: block;
z-index: 5;
}
header .todoitem {
width: 100%;
height: 100%;
float: left;
border: none;
border-radius: 5px;
background: rgba(255, 255, 255, 0.2);
text-indent: 20px;
}
header input::-webkit-input-placeholder {
color: #fff;
}
<header>
<input type="text" name="todoitem" class="todoitem" placeholder="Enter your activity...">
</header>
header {
height: 40px;
width: 100%;
position: fixed;
background: #00A6E3;
top: 0;
left: 0;
border-radius: 0 0 10px 10px;
padding: 15px;
box-shadow: 0 2px 5px rgba(44, 62, 88, 0.15);
display: block;
z-index: 5;
}
header .todoitem {
width: 100%;
height: 100%;
float: left;
border: none;
border-radius: 5px;
background: rgba(255, 255, 255, 0.2);
text-indent: 20px;
}
header input::-webkit-input-placeholder {
color: #fff;
}
<header>
<input type="text" name="todoitem" class="todoitem" placeholder="Enter your activity...">
</header>
Try removing float:left, and add text-align:center to header, and text-align:left to .todoitem, then add margin values to .todoitem to position it where you want.
Width:100% and padding:2px;
doesn't goes well, It never does. Either reduce width to 98% or add padding as padding :15px 0;
header {
height: 40px;
width: 100%;
position: fixed;
background: #00A6E3;
top: 0;
left: 0;
border-radius: 0 0 10px 10px;
padding: 15px 0;
box-shadow: 0 2px 5px rgba(44, 62, 88, 0.15);
display: block;
z-index: 5;
}
I have created a slated div to use with my navbar, but it messes up the rest of the formatting for the website. The navbar is in the top right and the slanted div is underneath it, but it messes up everything else on the webpage. I've been trying everything to no avail.
http://imgur.com/a/bmv6l
Navbar HTML:
<template name="navbar">
<div class="navbar">
<ul>
<li>Contact</li>
<li>Services</li>
<li>Experience</li>
<li>Home</li>
</ul>
</div>
</template>
Navbar CSS:
.navbar {
position: relative;
display: inline-block;
padding: 0em 0em 1em 10em;
overflow: hidden;
color: #fff;
float: right;
}
.navbar:after {
content: '';
position: absolute;
top: 0; left: 0;
width: 100%; height: 100%;
background: #000;
-webkit-transform-origin: 100% 0;
-ms-transform-origin: 100% 0;
transform-origin: 100% 0;
-webkit-transform: skew(45deg);
-ms-transform: skew(45deg);
transform: skew(45deg);
z-index: -1;
}
ul {
list-style-type: none;
margin-left: 100px;
margin: 0;
padding: 0;
padding-top: 1em;
padding-right: 1em;
padding-bottom: 5px;
overflow: hidden;
font-family: 'Open Sans', sans-serif;
font-size: 20px;
font-weight: bolder;
-webkit-font-smoothing: antialiased;
z-index: -1;
}
li {
margin-left: 1em;
margin-right: 2em;
float: right;
}
li a {
display: block;
color: white;
text-align: center;
padding: 16px 16px;
text-decoration: none;
-webkit-box-shadow: 0px 0px 8px 0.5px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 0px 8px 0.5px rgba(0,0,0,0.75);
box-shadow: 0px 0px 8px 0.5px rgba(0,0,0,0.75);
border: 5px;
border-style: solid;
border-radius: 10px;
border-color: white;
transition: background 0.2s ease,
padding 0.8s linear;
}
li a:hover {
background-color: #111;
}
.active {
border-radius: 8px;
border-color: white;
background-color: #555;
}
"Bobcats Services" Div HTML:
<body>
<div id="nav">
{{> navbar}}
</div>
<div id="center">
<h1>Bobcats Services</h1>
<h2>Everything you need!</h2>
</div>
</body>
"Bobcats Services" Div CSS:
/* CSS declarations go here */
html {
height: 100%;
}
body {
margin: 0;
padding: 0;
/*background-color: #0193ff;*/
/* Permalink - use to edit and share this gradient: http://colorzilla.com/gradient-editor/#00b7ea+0,009ec3+100;Blue+3D+%2315 */
background: rgb(135,224,253); /* Old browsers */
background: -moz-linear-gradient(top, rgba(135,224,253,1) 0%, rgba(83,203,241,1) 40%, rgba(5,171,224,1) 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(top, rgba(135,224,253,1) 0%,rgba(83,203,241,1) 40%,rgba(5,171,224,1) 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to bottom, rgba(135,224,253,1) 0%,rgba(83,203,241,1) 40%,rgba(5,171,224,1) 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#87e0fd', endColorstr='#05abe0',GradientType=0 ); /* IE6-9 */
/* Image instead of standard color
background-image: url("images/watch-plane.png");
background-repeat: no-repeat;
background-size: cover;
*/
}
#nav {
}
#center {
width: 30%;
padding-bottom: 2em;
padding-top: 2em;
margin: auto;
margin-top: 2em;
text-align: center;
background-color: rgba(0, 0, 0, 0.5);
color: white;
border-style: solid;
border-radius: 5px;
border-color: #008fc8;
font-family: 'Open Sans', sans-serif;
}
When using float, you need to clear, so the folllowing elements to look right. I have added here: https://jsfiddle.net/44x11g34/ an example.
What i had added between the 2 main blocks:
<div class="clear"></div>
and some small css
.clear {
clear: both;
}
Hope this will help you.
I want to show my button in Mozilla like Chrome so please help me what will I do for it.
This is my code.
CSS:
.green {
background: linear-gradient(to bottom, #9CD645 0%, #8AC530 100%) repeat scroll 0 0 rgba(0, 0, 0, 0);
border: 1px solid #82B436;
}
.large {
font-size: 18px;
}
.btn {
border: 1px solid #82B436;
border-radius: 25px;
box-shadow: 0 1px rgba(99, 159, 8, 0.35);
color: #508400;
display: inline-block;
font-weight: bold;
padding: 3px 12px;
text-decoration: none;
text-transform: uppercase;
}
.green {
background-color: #8CC63F;
}
.btn span {
background: url("images/icon_arrows.png") no-repeat scroll 0 0 rgba(0, 0, 0, 0);
display: block;
float: right;
height: 18px;
margin: 5px;
width: 18px;
}
HTML:
<a href="smoodees" class="btn large green">
Check out our Smoodees
<span></span>
</a>
Checkout this fiddle:
http://jsfiddle.net/realdeepak/gvC9z/1/
or For browser compatibility in firefox, you can use css hack like this:
#-moz-document url-prefix() {
.large {
font-size: 17px;
}
}
Or Try this, And fix minor css padding alignment as per your screen:
<style type="text/css">
.green {
background: linear-gradient(to bottom, #9CD645 0%, #8AC530 100%) repeat scroll 0 0 rgba(0, 0, 0, 0);
border: 1px solid #82B436;
}
.large {
font-size: 18px;
}
.btn {
border: 1px solid #82B436;
border-radius: 25px;
box-shadow: 0 1px rgba(99, 159, 8, 0.35);
color: #508400;
display: inline-block;
font-weight: bold;
padding: 3px 30px 3px 10px;
text-decoration: none;
text-transform: uppercase;
position: relative;
}
.green {
background-color: #8CC63F;
}
.btn span {
background: url("images/icon_arrows.png") no-repeat scroll 0 0 rgba(0, 0, 0, 0);
height: 18px;
margin: 5px;
width: 18px;
position: absolute;
top: 0;
right: 0;
}
</style>
Changing the answer completely.
Try this structure:
<a href="smoodees" class="btn large green">
<p id="text">Check out our Smoodees</p>
<span></span>
</a>
and change the CSS like so:
#id{
float: left
}
span{
float: left
}
edit: For multiple buttons, change the ID to a Class
I've searched everywhere for this but I haven't found anything (maybe because I don't know exactly how to put it into words). I'm a newbie with HTML and CSS.
What I basically have is a wrapper, nav, logo, content and footer. I added a fixed background image to the body and made my divs semi transparent. My divs have a fixed width of about 1152px, margin auto and a semi transparent background color that covers the background image.
What I want to do is to make the divs transparent background color to extend to the sides, covering the full width of the screen but keeping all the content in a fixed width.
Here is an example of what I want to do:
http://electricladystudios.com/
The content, nav bar, logo, it's all centered in a specific width, but the backgrounds go beyond that width.
This is my HTML body:
<body>
<div id="wrapper">
<div id="logo"> <img src="logo.png"></div>
<div id="nav">
<ul id="navbar">
<li>HOME</li>
<li>ABOUT</li>
<li>STUDIO</li>
<li>GALLERY</li>
<li>DEMOS</li>
<li>BLOG</li>
<li>CONTACT</li>
</ul>
</div>
</div>
<div id="content">
<h1>Something </h1>
</div>
<div id=footer>
<p>WEBPAGE MADE BY ME lol</a></p>
</div>
</body>
And this is my CSS (I know there are a lot of things repeated in here, but this is my first try at coding by myself and I'm just trying to get everything to look right before I optimize the code) So please, bear with me.
#charset "utf-8";
/* CSS Document */
body {
background-image:url(bg2.jpg);
background-repeat: no-repeat;
background-position:center center;
background-attachment:fixed;
color: white;
font-family: Arial;
font-size: 1 em;}
#wrapper {
width: 1152px;
background: rgba(0, 0, 0, 0.8);
margin: auto;
margin-top: 20px;
padding: 30px;
height: 100px;
box-shadow: 0px 10px 10px 0px rgba(50, 50, 50, 0.75); }
#logo {
display: inline-block;
width: 40%;
float: left; }
#nav {
width: 52%;
display: inline-block;
text-align: right;
float: right;
padding: 20px;
margin-top: 5px;
margin-bottom: 75px;}
#navbar li {
font-size: 12px;
display:inline;
padding: 12px; }
#navbar li a {
text-decoration: none;
color: white;
-o-transition:.5s;
-ms-transition:.5s;
-moz-transition:.5s;
-webkit-transition:.5s; }
#navbar li a:hover {
color: #0062A4;
transition: .5s; }
a {
text-decoration: none;
color: #0062A4;
-o-transition:.5s;
-ms-transition:.5s;
-moz-transition:.5s;
-webkit-transition:.5s;}
a:hover {
color: #C33;
transition: .5s; }
#content {
clear:both;
width: 1152px;
margin: auto;
margin-top: 20px;
margin-bottom: 20px;
padding: 30px;
height: 800px;
box-shadow: 0px 10px 10px 0px rgba(50, 50, 50, 0.75);
background: rgba(240, 240, 240, 0.6);
color: #333;
font-family: Arial;}
#footer {
width: 1152px;
background: rgba(0, 0, 0, 0.8);
text-align: right;
color: grey;
margin:auto;
padding:5px;
padding-left: 30px;
padding-right: 30px;
box-shadow: 0px 10px 10px 0px rgba(50, 50, 50, 0.75);
font-size: 75%; }
Any help will be greatly appreciated!
Thanks
I managed to do it. This is the method I used:
I applied margin 0 to the body so as to remove any borders imposed to the rest of the divs.
Then I wrapped all my divs around another div and gave that parent div a width of 100% and the transparent background color and then specified the width of the content on the child div.
Result is, semi transparent black background takes the full width of the page while the content stays inside that same div but with a fixed width.
Like so:
#outwrap {
box-shadow: 0px 10px 10px 0px rgba(50, 50, 50, 0.75);
background: rgba(240, 240, 240, 0.6);
width: 100%; }
#content {
width: 1152px;
margin: auto;
padding: 30px;
color: #333;
font-family: Arial; }
Heres a quick demo on jsfiddle:
http://jsfiddle.net/Dasch/fK5aB/
The way they do the fixed background is this:
background: url(images/Hero.jpg) no-repeat center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
body {
background-image:url(bg2.jpg);
background-repeat: no-repeat;
background-attachment:fixed;
color: white;
font-family: Arial;
font-size: 1 em;}
add
background-size:100% 100%;
and remove
background-position:center center;
I want to have the header's navigation to have a box shadow. However, the box-shadow seems to be hidden by the carousel I placed below it. I put a z-index of all children of #carousel but the box-shadow still doesn't show up.
(page snippet)
Here's what happens when I push #carousel down when I give it margin-top: 40px;
(another page snippet)
HTML
<header>
<nav>
<div class="container">
<h1><img src="images/logo.png" alt="" id="logo"></h1>
<h1 id="NHS">Newport High School</h1>
<ul id="nav">
<li>Home</li>
<li>About</li>
<li>Students</li>
<li>Parents</li>
<li>Activities & Atletics</li>
<li>Resources</li>
</ul>
</div><!--container--->
</nav>
</header><div id="carousel">
<div class="inner">
<ul>
<li><img src="images/example-slide-1.jpg" alt="Fish"></li>
<li><img src="images/example-slide-2.jpg" alt="Elephant"></li>
<li><img src="images/example-slide-3.jpg" alt="Giraffe"></li>
<li><img src="images/example-slide-4.jpg" alt="Fish"></li>
</ul>
</div>
</div>
CSS
/* - - - header - - - */
header {
background: rgb(30,27,27); /* Old browsers */
background: -moz-linear-gradient(top, rgba(30,27,27,1) 0%, rgba(2,2,2,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(30,27,27,1)), color-stop(100%,rgba(2,2,2,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(30,27,27,1) 0%,rgba(2,2,2,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(30,27,27,1) 0%,rgba(2,2,2,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(30,27,27,1) 0%,rgba(2,2,2,1) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(30,27,27,1) 0%,rgba(2,2,2,1) 100%);
box-shadow: 0px 3px 15px rgba(50, 50, 50, .7);
-webkit-box-shadow: 0px 3px 15px rgba(50, 50, 50, .7);
-moz-box-shadow: 0px 3px 15px rgba(50, 50, 50, .7);
z-index: 1000;
}
header h1, header li {
float: left;
}
header a {
color: #A1A1A1 ;
font-family: arial, helvetica, verana, sans-serif;
}
header a:hover {
color: #A1A1A1;
text-decoration: none;
}
#logo {
width: 50px;
}
#NHS {
margin: 1.8% 0 0 2%;
font-size: 1.2em;
text-transform: uppercase;
}
#NHS a {
color: #F6F6F6;
letter-spacing: 2px;
}
#nav {
float: right;
margin: 3% 0 0 0;
}
#nav li {
margin-right: 20px;
padding: 0;
}
#nav li:last-of-type {
margin-right: 0px;
}
#nav a {
font-size: .8em;
text-transform: uppercase;
padding-top: 3px;
font-weight: 400;
}
#nav a:hover {
border-top: 1px dotted #C41D0E;
}
/* - - - carousel - - - */
#carousel {
margin: 40px 0 0 0;
width: 100%;
overflow: hidden;
z-index: -999;
}
#carousel .inner {
box-sizing: border-box;
margin-left: -50px;
z-index: -5000;
}
#carousel ul {
width: 60000px;
height: 480px;
z-index: -5000;
}
#carousel li {
height: 480px;
float: left;
overflow: hidden;
z-index: -5000;
}
#carousel img {
text-align: center;
width: 1375px;
height: auto;
z-index: -5000;
}
Remember z-index only works with positioned elements. So both your carousel and header needs to have a position value other than static and then you can specify a higher z-index to the header. That way box-shadow will appear properly above the carousel.
You only need to add position:relative to the header. The carousel doesn't need a z-index alteration.
try adding !important to your shadowbox. I think that should work.
box-shadow: 0px 3px 15px rgba(50, 50, 50, .7) !important;
-webkit-box-shadow: 0px 3px 15px rgba(50, 50, 50, .7) !important;
-moz-box-shadow: 0px 3px 15px rgba(50, 50, 50, .7) !important;