bring second div in center is failing - html

Having Following code, M trying to bring the second div in the center, somehow it is not coming, i do not want to use margin in minus:
Here is html and css
<div id="headerLeft">
<div id="imgsection">
<div class="logo"></div>
</div>
<div id="usersection">
<div class="user">Sign</div>
<div class="location">Find</div>
</div>
</div>
my CSS
#headerLeft {
width:45%;
}
#headerLeft #imgsection {
width:150px;
}
#headerLeft #imgsection .logo {
background: url('../img/logo.png') no-repeat;
background-size: cover;
width:88px;
height:71px;
width:100px;
}
#headerLeft #usersection {
float:right;
width:200px;
margin: auto;
}
#headerLeft #usersection .user {
width:80px;
float:left;
}
#headerLeft #usersection .location {
width:80px;
float:left;
}
check this fiddle
http://jsfiddle.net/CF6kX/
the second one which is covered with id: usersection needs to be in between, currently it is appearing at the bottom

In the image section add property float:left ,increase headerleft width below is the code
#headerLeft {
width: 58%;
}
#headerLeft #imgsection {
width:150px;
float: left;
}
#headerLeft #imgsection .logo {
background: url('../img/logo.png') no-repeat;
background-size: cover;
width:88px;
height:71px;
width:100px;
}
#headerLeft #usersection {
float:right;
width:200px;
margin: auto;
}
#headerLeft #usersection .user {
width:80px;
float:left;
}
#headerLeft #usersection .location {
width:80px;
float:left;
}

remove float:right from This CSS
#headerLeft #usersection
{
float:right;
width:200px;
margin: auto;
}
FIDDLE

Related

How to center img inside position absolute

I try to center image inside this absolute position div I try margin: 0 auto but it can't work. what I am doing wrong?
<div class="support"> <img src="../image/contact.jpg" /></div>
.support {
position:absolute;
left:30px;
top:50px;
width:300px;
height:450px;
}
.support img {
width:243px;
height:350px;
margin:0 auto;
}
add display:block to image:
.support img {
width:243px;
height:350px;
margin:0 auto;
display: block; /* add this */
}
You can also use display: block; like this:
.support {
left:30px;
top:50px;
width:300px;
height:450px;
}
.support img {
width:100px;
height:100px;
margin:0 auto;
display: block;
}
<div class="support"> <img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBwgHBgkIBwgKCgkLDRYPDQwMDRsUFRAWIB0iIiAdHx8kKDQsJ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dasmGzUYGd9/Km1gkkHdiOMeH96NAAqZUAHHMVgJY945586dY0/YG6IrZsPfkCde7lj91OQ5gVuwDN2i7u2/3cqnaqpiOVBw3UUtcyOWjUu2krkjPnVViSVi6+Q57A7HKnxU1CVTISyhSMYwDSzbMcbb0VNgcf5zpKop7Ik6TjkRTEMiK80MRJbQTr28NwP96negBmwBypDhH/AJJ9PzFRy/lGiMNbRjM10zQR57oxl3NbitbaVQbWNpZMgZMmACR1J51rixOXGdhIcDw71NcK7qHTtp7QjHQ451zuTUbGF7wXyXMdvE8OoppK6+fPckgUjeTXTXJaTCsvd1RtlfTPKgcRZtb948/GsnJW9dFOFyO6OVWhGkmBskty6jAZfjvWUoedZVNCCf/Z" /></div>
Hey try this text-align center in image parent div
.support {
position:absolute;
left:30px;
top:50px;
width:300px;
height:450px;
text-align: center;
}
.support img {
width:243px;
height:350px;
margin:0 auto;
}
<div class="support"> <img src="../image/contact.jpg" /></div>
<style>
.support {
left:30px;
top:50px;
width:300px;
height:450px;
margin:0 auto;
}
.support img {
width:243px;
height:350px;
margin:0 auto;
}
</style>
<div class="support"> <img src="../image/contact.jpg" /></div>
try this.

vertically centered image in div

I try to vertically center an image in the middle of the body but nothing seems to work. I've tried different tricks found here (height 100%, table-cell, position:relative...), but with no luck until now. My code is
html:
<div id="container">
<div id="header">Header</div>
<div id="body">
<div class="image"></div>
</div>
<div id="footer">Footer</div>
</div>
CSS:
html,
body {
margin:0;
padding:0;
height:100%;
}
#container {
min-height:100%;
position:relative;
}
#header {
background:#ccc;
padding:10px;
}
#body {
padding:10px;
padding-bottom:60px;
}
.image {
background: url("http://lorempixel.com/300/200/nature/") no-repeat center;
height: 200px;
width: 100%;
}
#footer {
position:absolute;
bottom:0;
width:100%;
height:60px;
background:#ccc;
}
I made a fiddle here: http://jsfiddle.net/dragoeco/hjcz6j0r/1/
I looking for a working solution with IE8+ so maybe there is a jQuery way to do that job? What is important for me is to keep the footer at the bottom of the viewport so that's why I used a obsolute position for footer. Thanks.
Something like this maybe :
LIVE EXAMPLE
html, body {
height: 100%;
}
#container {
height: 100%;
width: 100%;
display: table;
margin-top:-60px; //height of the footer
}
#body {
display: table-cell;
height: 100%;
vertical-align: middle;
}
.image {
background: url("http://lorempixel.com/300/200/nature/") no-repeat center;
height:200px;
}
#header {
background:#ccc;
padding:10px;
}
#footer {
position:absolute;
bottom:0;
width:100%;
height:60px;
background:#ccc;
}
I had success with the following CSS:
html,
body {
margin:0;
padding:0;
height:100%;
}
#container {
min-height:100%;
position:relative;
}
#header {
background:#ccc;
padding:10px;
position: relative;
}
#body {
padding:10px;
padding-bottom:60px;
position: relative;
}
.image {
background: url("http://lorempixel.com/300/200/nature/") no-repeat center ;
position: absolute;
height: 200px;
width: 100%;
top: 50%;
}
#footer {
position:absolute;
bottom:0;
width:100%;
height:60px;
background:#ccc;
}
Source: http://www.w3.org/Style/Examples/007/center.en.html#vertical
Add this:
.image{
position: absolute;
top: 50%;
margin-top: -100px;
}
It works everywhere (except IE6-7, position relative may be needed there). You can do the same for horizontal centering.
Here is the fiddle: http://jsfiddle.net/hjcz6j0r/7/

Responsive DIV and background

For the first time i'm doing some responsive DIV'S and now i have made my responsive background and i wanted to my content look like this:
But it looks like this:
If someone could help me it would be great.. Here is my code that you see what i was doing
jsFiddle
HTML:
<div class="container">
<div class="leftColumn"><img src="projekt.png" width="400" height="400"></div>
<div class="rightColumn"><img src="projekt2.png" width="400" height="400"></div>
</div>
CSS:
.container {width:100%;}
.leftColumn {width:50%; float:left;}
.rightColumn {width:50%; float:left;}
#media(max-width:400px)
{
.leftColumn { width:100px; float:none; display:block; position:relative; background-color:red; }
.rightColumn { width:100px; float:none; display:block; position:relative; background-color:blue; }
}
Images are 400 x 400 pixels and background image is 1920 x 1080
For background, use background-size property (CSS3).
.container {width:100%;}
.leftColumn {width:50%; float:left;}
.rightColumn {width:50%; float:left;}
#media(max-width:400px)
{
.container {
width: 400px;
height: 400px;
background: url(http://www.extremedialer.com/wp-content/uploads/2013/10/bg-1.jpg);
background-size: 400px;
}
.leftColumn { width:100px; float:none; display:block; position:relative; background-color:red; }
.rightColumn { width:100px; float:none; display:block; position:relative; background-color:blue; }
}
#media (min-width:401px) and (max-width:800px)
{
.container {
width: 800px;
height: 800px;
background: url(http://www.extremedialer.com/wp-content/uploads/2013/10/bg-1.jpg);
background-size: 800px;
}
.leftColumn { width:200px; height:200px; float:left; margin: 20px; display:block; position:relative; background-color:red; }
.rightColumn { width:200px; height:200px; float:left; margin: 20px; display:block; position:relative; background-color:blue; }
}
http://jsfiddle.net/XmqNy/235/
try it in your css file:
#media(max-width:400px)
{
.leftColumn { width:100px; position:relative; background-color:red; }
.rightColumn { width:100px; position:relative; background-color:blue; }
}
You don't need to write display:none.

Placing an image on top of CSS box content.

I am trying to place my logo above a menubar i created in css, but what ever i try the logo always goes below the menu bar, i am trying to achieve a manubar the width of the page with a logo in the centre of the menubar.
My CSS code is ;
#bar {
margin-top:50px;
width: 1920px center;
height: 30px;
background: #2E2E2E;
border: 3px groove #FFD700;
}
#logo {
background-image:url(../img/LOGO1.png);
background-size:150px;
width:150px;
height:150px;
margin:0 auto;
}
and html is;
</head>
<body>
<div id="bar">
</div>
<div id="logo">
</div>
</body>
</html>
Thankyou for any help
Z:index is your friend
http://jsfiddle.net/BrvL2/1/
#logo {
position:absolute;
background-image:url(http://placehold.it/150x150/f16b20/ffffff);
background-size:150px;
width:150px;
height:150px;
margin:0 auto;
z-index:999;
top:0px;
margin: 0 auto;
left:0px;
right:0px;
}
#bar {
margin-top:50px;
width: 1920px;
height: 30px;
background-color: #2E2E2E;
border: 3px groove #FFD700;
text-align: center;
}
#logo {
position:relative;
background-image:url(http://placehold.it/150x150/f16b20/ffffff);
background-size:150px;
width:150px;
height:150px;
margin:0 auto;
z-index:999;
top:0px;
}
<div id="bar">
<div id="logo">
</div>
</div>
Hope this works for you.
Here's the CSS:
#wrap {
position:relative;
width:100%;
}
#bar {
position:relative;
margin-top:50px;
width: 100%;
height: 30px;
background-color: #2E2E2E;
border: 3px groove #FFD700;
}
#logo {
position:absolute;
background-image:url(http://placehold.it/150x150/f16b20/ffffff);
background-size:150px;
width:150px;
height:150px;
left:50%;
margin-left:-75px;
margin-top:-50px;
z-index:999;
top:0px;
}
I put in a wrap, so the #logo would have a parent container to reference when positioning. This will float the logo in the middle of the menu bar.
Here's the fiddle: http://jsfiddle.net/BrvL2/3/
alter the 'left:' attribute until it is centered
#logo {
position:absolute;
top:0;
left:45%;
right:0;
z-index:1000;
background-image:url(../img/LOGO1.png);
background-size:150px;
width:150px;
height:150px;
}

How to float left content and fix right content?

I am working on a structure to have a top navigation fixed, a left nav to be scrollable and a right nav to be fixed.
I have created a fiddle here. just need help with the css.
http://jsfiddle.net/PxbX9/
#header {
position:fixed;
background:red;
width:700px;
height:30px;
}
#left-block {
float:left;
width:350px;
background:blue;
height:1000px;
margin-top:30px;
}
#right-block {
float:left;
width:350px;
height:1000px;
background:pink;
margin-top:30px;
.fixed-block {
postion:fixed;
height:1000px;
}
This can be achieved by restructuring your CSS to this:
#header {
position:fixed;
background:red;
width:700px;
height:30px;
}
#left-block {
float:left;
width:350px;
background:blue;
height:1000px;
margin-top:30px;
}
#right-block {
display: inline-block;
float:right;
width:350px;
height:1000px;
background:pink;
margin-top:30px;
position:fixed;
}
I've only made CSS changes to the #right-block selector.
Removed the class .fixed-block, which had a typo in the form of postion (should be position).
position: fixed; has been added to the #right-block selector.
display: inline-block; and float: right; have been added also.
DEMO
Hope this helps.
Take a look at that Working Fiddle
Pure CSS solution, Very Dynamic, Totally responsive.
HTML:
<div class="Container">
<div class="Header">
</div>
<div class="HeightTaker">
<div class="Wrapper">
<div class="RightContent">
</div>
<div class="LeftContent">
</div>
</div>
</div>
</div>
CSS:
*
{
margin: 0;
padding: 0;
}
html, body, .Container
{
height: 100%;
}
.Container:before
{
content: '';
height: 100%;
float: left;
}
.HeightTaker
{
position: relative;
z-index: 1;
}
.HeightTaker:after
{
content: '';
clear: both;
display: block;
}
.Wrapper
{
position: absolute;
width: 100%;
height: 100%;
}
.Header
{
/*for demonstration only*/
background-color: #bf5b5b;
}
.Wrapper > div
{
height: 100%;
overflow: auto;
}
.LeftContent
{
/*for demonstration only*/
background-color: #90adc1;
}
.RightContent
{
float: right;
width: 500px;
/*for demonstration only*/
background-color: #77578a;
}