my outer div background extends when using negative margins in the child div - css

Here is my stylesheet code
#topwrapper {
background: url(images/orangebg.jpg) repeat-x top;
height: 502px;
}
#mainwrapper {
background:url(images/bluebg.jpg) repeat;
}
#maincontent {
margin: 0 auto;
width: 961px;
background-color:#F0EFEF;
position: relative;
margin-top: -312px;
}
I want the maincontent div to move up into the orange div but it is bringing the bluebg.jpg with it (cutting short the orangebg.jpg). When I tried using -top: 312px; instead of the negative margin it added space below the #maincontent.
The code on the page reads
<div id="topwrapper"></div>
<div id="mainwrapper"><div id="maincontent">test test</div></div>
View on jsfiddle
jsfiddle.net/bdh2a - remove the margin-top: -312px; and that is how I need the orange background to look with the grey box on top of it

maybe you can set margin-top: -312px; to mainwrapper div?

Re-arrange your html like this:
<div id="mainwrapper">
<div id="maincontent"><p>text text</p></div>
<div id="topwrapper"></div>
</div>
Then use this CSS setup (adjusting the heights and stuff of course):
#mainwrapper{
height:100%;
background-color:#FF4200;
width:100%;
}
#topwrapper {
background-color:#1B00FF;
height:100px;
min-width:100%;
margin:0 auto;
position:absolute;
top:0;
z-index:0;
}
#maincontent {
margin: 0 auto;
padding:20px;
top:20px;
background-color:#ccc;
position: relative;
color:#000;
z-index:1;
width:80%
}
Check out this jsfiddle:http://jsfiddle.net/imakeitpretty/yqnfk/
There is a lot of greek text in there because you can't see the orange expand without it. "text text" isn't enough to do it.

I Found a solution!!
#topwrapper {
background: url(images/orangebg.jpg) repeat-x top;
height: 502px;
}
#mainwrapper {
background:url(images/bluebg.jpg) repeat;
float: left;
width: 100%;
display: block;
position: relative;
}
#maincontent {
width: 961px;
background-color:#F0EFEF;
position: relative;
margin-top: -312px;
margin-left: -480px;
position: relative;
float: left;
left: 50%;
}
The code on the page stays the same

Related

Icons separation and horizontal line behind

I search any problem but without results. Have big problem with separation of icons in inline-block after add css spearation ::after and ::before in the middle icon and with rwd of it.here's my code.
HTML:
<div class="icon-box">
<div class="icon_1"></div>
<div class="icon_2"></div>
<div class="icon_3"></div>
</div>
CSS:
.icon_1 {
float: left;
display: inline-block;
height: 66px;
width: 66px;
background-image: url("../img/timing_icon.png");
background-color: #97735e;
background-position: center;
background-repeat: no-repeat;
}
.icon_2 {
float: left;
display: inline-block;
height: 66px;
width: 66px;
background-image: url("../img/presentation_icon.png");
background-color: #97735e;
background-position: center;
background-repeat: no-repeat;
}
.icon_3 {
float: left;
display: inline-block;
height: 66px;
width: 66px;
background-image: url("../img/accurate_icon.png");
background-color: #97735e;
background-position: center;
background-repeat: no-repeat;
}
.icon_2::before,
.icon_2::after {
display: inline-block;
content: "";
height: 10px;
border-bottom: 1px solid #97735e;
width: 100%;
}
.icon_2::before {
right: 100%;
margin-right: 10%;
}
.icon_2::after {
left: 100%;
margin-left: 200%;
}
I think my code is very messy and got to fix.
effect,what I want get enter image description here
first. you have common styles for all the .icon_1,.icon_2,.icon_3 divs except the background-image . so, give a common class icon for example, to all those divs, or, if you can't change the HTML , use .icon_1,.icon_2,.icon_3 instead of .icon in my example below. but don't write the same styles 3 times.
second. either use display:inline-block either use float:left . i chose to use float:left; because inline-block adds additional whitespaces between elements. ( if you want to use inline-block let me know . there are ways to override the whitespaces . )
third. add margin:0 15px to .icon_2 which adds margin-left and margin-right of 15px
fourth. add the pseudo-element ( :before in my example ) to the div that wraps the three icons ,respectively .icon-box . and style it as you want.
i added z-index:-1 so that the line ( :before ) goes under the icons.
added background:red to it so you can see that it goes under the icons.
.icon {
float:left;
height: 66px;
width: 66px;
background-color: #97735e;
background-position: center;
background-repeat: no-repeat;
position:relative;
}
.icon_1 {
background-image: url("../img/timing_icon.png");
}
.icon_2 {
background-image: url("../img/presentation_icon.png");
margin:0 15px;
}
.icon_3 {
background-image: url("../img/accurate_icon.png");
}
.icon-box { position:relative;width:auto;float:left;}
.icon-box:before {
content:"";
position:absolute;
height:1px;
background:red;
top:50%;
width:100%;
left:0;
z-index:-1;
}
<div class="icon-box">
<div class="icon icon_1"></div>
<div class="icon icon_2"></div>
<div class="icon icon_3"></div>
</div>

How to use CSS to style 4 blocks of Info in the homepage?

Ok, I want my home page to have a structure like the below picture
-The 1st block of info is just 1 "text line"
-The 2nd block of info is the "Wellcome Text" (there're many text lines in here)
-The 3rd block of info is the "Note Text" (there're some text lines in here)
-The 4th block of info is for holding a few widgets such as buttons, icon...
So, I decided to use Div. It works fine for the 1st, 2nd & 4th but I don't know how to position the 3rd.
.aTextLine
{
position:relative;
left:500px;
top:32px;
text-align:right;
width:420px;
}
.wellcomeText
{
position:relative;
left:200px;
top:50px;
text-align:left;
width:720px;
}
.widgetSection
{
position:relative;
left:200px;
top:60px;
text-align:left;
width:720px;
}
.noteText
{
position:relative;
left:230px;
top:60px;
text-align:left;
width:100px;
}
If i obmitted the noteText then it look like the picture but without the note section, so :
How to change the CSS .noteText so that it will look like the above picture
The home page is like this
<html>
<div class="{style.aTextLine}" > ...1 text line</div>
<div class="{style.wellcomeText}" > many text lines....
.....
...</div>
<div class="{style.widgetSection}" > <g:Button...> <img...> </div>
</html>
Check this
I assumed your html as designed in the fiidle. so modified only few css. If you want that design alone, i can overwrite the whole code in best manner.
.div1
{
position:relative;
left: 100px;
text-align: right;
top:32px;
width:420px;
border: 1px solid;
}
.div2
{
position:relative;
left:80px;
top:50px;
text-align:left;
width:500px;
border: 1px solid;
height: 100px;
float: left;
}
.div3
{
position:absolute;
width:100px;
left: 600px;
top: 80px;
border: 1px solid;
height: 100px;
}
.div4
{
position:relative;
left:80px;
top:60px;
text-align:left;
width:500px;
clear: both;
border: 1px solid;
}
Let me know if any problem occurs or requirement changes. I ll edit it.
EDITED FIDDLE
It ll not cause any problem..
To create WHOLE div for WELCOME and NOTE div after that split two separate div and use float:left float:right
like this DEMO
HTML
<div class="main">
<div class="header">1 text line</div>
<div class="container">
<div class="welcome">The 2nd block of info is the "Wellcome Text" (there're many text lines in here)......</div>
<div class="note">Note Text"</div>
</div>
<div class="widget">4th block of info is for holding a few widgets such as buttons, icon.</div>
CSS
.main{
width: 1300px;
margin: 0px auto;
}
.header{
width: 100%;
height: 50px;
background-color: #ffff00;
text-align: center;
font-size: 2em;
}
.container{
width: 100%;
height: 500px;
}
.welcome{
width: 75%;
height: 100%;
float: left;
background-color: #d3d3d3;
}
.note{
width: 25%;
height: 100%;
float: right;
background-color: #87cefa;
}
.widget{
width: 100%;
height: 75px;
background-color: #0cbadf;
}
See for .note text you have kept kept left = 230px and 100 px width ,so totally u need 200 + 720 + 230 +100px =1250px which is too much. Probabaly reduce it to something like this :
.welcomeText
{
position: relative;
float: left;
left: 100px;
top: 60px;
text-align: left;
width: 480px;
}
.noteText
{
position: relative;
float: right;
left: 0px;
top: 60px;
text-align: left;
width: 100px;
}
Alternatively you could put both wellcome and note text in one div and use percentage width; something like this
section {
width: 80%;
height: 200px;
background: aqua;
margin: auto;
padding: 10px;
}
div#one {
width: 75%;
height: 200px;
background: red;
float: left;
}
div#two {
margin-left: 15%;
height: 200px;
background: black;
}
For html
<section>
<div class="one">
<div>1</div>
<div>2</div>
<div>4</div>
</div>
<div class="two">
</div>
</section>
you could do like this perhaps 1,2,4 in one column and then note in rest ..so all those column will have 75% and ur note 3rd div will have rest of 25%

How to force my header to be on top?

so I have this little beginning of a site and I want the top menu to stay on top of anything else. I used position:fixed and now it does stay on top of everything except for one div that display a logo... I tried using z-index but that didn't help. How do I force that header to stay on top without using Js if possible...
The "blackBar" passes on top of the heading but it's the only this that does...
<body>
<div id="pageBloc">
<header>
<nav>
<ul>
<li>Stuff1</li>
<li>Stuff2</li>
<li>Stuff3</li>
<li>Stuff4</li>
<li>Stuff5</li>
</ul>
</nav>
</header>
<div id="topBloc">
<div id="blackBar">
<p id="logo"><img src="Images/logoSmall.png" alt="logo"</p>
<h1 id="titrePrincipal">MyTitle</h1>
<h2 id="soustitrePrincipal">SubTitle/h2>
</div>
</div>
<section id="temporatySection">
</section>
</div>
</body>
Here's the CSS
body, html
{
margin: 0px;
padding: 0px;
height:100%;
}
#pageBloc
{
height:100%;
}
/*Header*/
header
{
text-align:center;
background-color: #26292E;
height: 40px;
width: 100%;
position:fixed;
}
nav ul, nav li
{
margin-top:5px;
text-transform:uppercase;
display: inline-block;
list-style-type:none;
}
#topBloc
{
background: url('Images/backgroundBloc12.jpg') fixed center;
background-size:cover;
width: 100%;
height: 100%;
}
#blackBar
{
background: rgba(38,41,46,0.80);
position:absolute;
bottom:15%;
width: 100%;
}
#logo
{
padding: 3px;
text-align: center;
}
#titrePrincipal
{
display:none;
text-align:center;
color: white;
}
#soustitrePrincipal
{
text-align: center;
color:black;
}
#temporarySection
{
height: 1000px;
}
Add position: relative; z-index: -1; to #logo.
Then, make sure that you add z-index: -2 to #blackbar.
See here: http://jsfiddle.net/davidpauljunior/gGMzD/1/
Instead of position fixed, you can try
position: absolute
top: 0
left: 0
right: 0
z-index: 100
but if you must use position fixed, you can disregard this and see the answer above.

Vertically centering <div>s with multiple lines

I know it's been asked a few times, but upon playing around a bit I still couldn't center what I need to. What I'm looking to do it center those buttons vertically on the page. I want to put centered text above it, too.
My (sloppy) code: JsFiddle
HTML:
<div>
</div>
CSS:
div {
text-align: center;
}
a {
text-align: center;
margin: auto;
}
.cbtn {
display:inline-block;
width:60px;
height:60px;
border-radius:50px;
background:transparent;
border: solid gray 1px;
margin: 2px;
-o-transition:.5s;
-ms-transition:.5s;
-moz-transition:.5s;
-webkit-transition:.5s;
transition:.5s;
}
.cbtn:hover {
text-decoration:none;
background:#F3734F;
}
#mail {
background-image:url(http://data.novicode.com/data/img/mail.png);
background-position:50% 50%;
background-repeat:no-repeat;
}
Here is one way of doing it, assuming you want the buttons centered both horizontally and vertically on the page.
The HTML is:
<div class="wrap">
<div class="button-wrap">
</div>
</div>
and the CSS is:
html, body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
.wrap {
height: 100%;
width: 100%;
}
.button-wrap {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
height: 60px;
width: 350px;
margin: auto;
text-align: center;
}
You need to declare the width and height properties of the body and html elements to be 100%, and the same for div.wrap.
The trick is to wrap the links/buttons in div.button-wrap, which is absolutely positioned and given specific width and height values to match the buttons. The height of 60px is based on the height of the .cbtn, and the width of 350px is 5 times (60px + 2x2px + 2x1px + 4x1em) which is about 350px. However, since we can use text-align: center for centering the inline blocks, the exact width is not too critical, just make it wide enough.
The centering works by setting all the position values to 0 (left/right/top/bottom) and then setting margin: auto.
This is all based on CSS 2.1 so it should work in most browsers. The only limitation is the inline-block property, which IE7 does not recognize.
However, since you are using CSS2 animations, inline-block is probably okay.
Fiddle reference: http://jsfiddle.net/audetwebdesign/METYC/
Full page view: http://jsfiddle.net/audetwebdesign/METYC/show
check this :
http://jsfiddle.net/AT8S6/
you can change the width,height and margin property of section for different results .
HTML
<div>
<section>
</section>
</div>
CSS
div {
text-align: center;
height:400px;
width:100%;
border:2px #000 solid;
}
a {
text-align: center;
margin: auto;
}
div section {
width:65%;
height:50%;
margin:20% auto;
}
.cbtn {
display:block;
width:60px;
height:60px;
border-radius:50px;
background:transparent;
border: solid gray 1px;
margin: 2px;
-o-transition:.5s;
-ms-transition:.5s;
-moz-transition:.5s;
-webkit-transition:.5s;
transition:.5s;
float:left;
}
.cbtn:hover {
text-decoration:none;
background:#F3734F;
}
#mail {
background-image:url(http://data.novicode.com/data/img/mail.png);
background-position:50% 50%;
background-repeat:no-repeat;
}
You could set the following rules on the div:
div {
position: absolute;
left: 50%;
height: 50%;
margin-top: -(height of div);
margin-left: -(width of div);
}
Example link below:
http://jsfiddle.net/AT8S6/1/

How to keep the header,footer and outer div to be fixed and making the inner div scroll-able

Please look at this http://jsfiddle.net/jaseem/sS7HN/ . What I am trying to achieve is instead of that inner scroll-bar, I want to use the main window scroll bar; SO that I can use the windows vertical scroll bar to go through the content inside the "innerContent" but at the same time I want the outer div to be fixed. is that possible ?
CSS :
header {
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 50px;
}
footer {
position: fixed;
left: 0;
bottom:0;
width: 100%;
}
content {
background-color:#656565;
width: 940px;
margin:0 auto;
padding-top:10px;
border-radius:5px;
}
mainContent {
margin:0px auto;
background-color:#515151;
width:660px;
border-radius:5px;
padding-top:20px;
}
contentHolder {
margin:0 auto;
width:616px;
background-color:#000000;
border-radius:10px;
overflow:auto;
}
HTML :
<div id="header"></div>
<div id="content">
<div id="mainContent">
<div id="contentHolder"></div>
</div>
</div>
<div id="footer"></div>
It's a little unclear what you are trying to accomplish, but I did notice you are missing the hash tags in your CSS. You need # in front of the identifier if you are referring to an ID attribute.
Example: http://jsfiddle.net/hgcax/
CSS
#header {
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 50px;
}
#footer {
position: fixed;
left: 0;
bottom:0;
width: 100%;
}
#content {
background-color:#656565;
width: 940px;
margin:0 auto;
padding-top:10px;
border-radius:5px;
}
#mainContent {
margin:0px auto;
background-color:#515151;
width:660px;
border-radius:5px;
padding-top:20px;
}
#contentHolder {
color:#fff;
margin:0 auto;
width:600px;
height: 400px;
background-color:#000000;
border-radius:10px;
overflow:auto;
}​
for div elements you have to give #div name here your div name is contentHolder so its #contentHolder
try like this:
#contentHolder {
overflow:auto;
}
or
#contentHolder {
overflow:scroll;
}

Resources