Unable to Center a div - html

I want img_manip_header_close block to be centered, but it's not.
CSS:
#img_manip_header_close {
display:inline-block;
cursor:pointer;
width:50px;
top:5px;
text-align:center;
margin-left:5px;
margin-right:5px;
left:125px;
}
#img_manip_header {
height:30px;
width:300px;
background-color:#DEDEDE;
margin: 0 auto;
display: block;
height: 20px;
line-height: 20px;
vertical-align: middle;
}
HTML
<div id="img_manip_header">
<div id="img_manip_header_close" onclick="window.location='index.php';">Close</div>
</div>

you are missing text-align:center; in #img_manip_header
#img_manip_header {
height:30px;
width:300px;
background-color:#DEDEDE;
margin: 0 auto;
display: block;
height: 20px;
line-height: 20px;
vertical-align: middle;
text-align:center;
}
http://jsfiddle.net/KS4Z3/

Just change the css for img_manip_header_close to this:
#img_manip_header_close {
cursor:pointer;
width:50px;
text-align:center;
margin: 0 auto;
}
Fiddle: http://jsfiddle.net/82Asv/
Specifically, you need to remove margins and display:inline-block, and add margin auto.
In fact, you don't even need text-align:center here.
Updated fiddle: http://jsfiddle.net/82Asv/1/

Lose the width on the #img_manip_header_close and change display:inline-block to display:block
Did for trick here

Try this:
http://jsfiddle.net/TFHv4/
<div id="img_manip_header">
<div id="img_manip_header_close" onclick="window.location='index.php';">Close</div>
</div>
#img_manip_header_close
{
cursor:pointer;
}
#img_manip_header
{
background-color:#DEDEDE;
margin: 0 auto;
display: block;
height: 20px;
text-align:center;
}

#img_manip_header_close
{
//lose this -> display:inline-block;
cursor:pointer;
width:50px;
top:5px;
//lose this -> text-align:center; (from what you said you want to align center 'img_manip_header_close' div not the text from inside div)
margin-left:5px;
margin-right:5px;
left:125px;
}
#img_manip_header
{
text-align:center; //add this line, in this way you will align center the content from 'img_manip_header' which is 'img_manip_header_close' div
height:30px;
width:300px;
background-color:#DEDEDE;
margin: 0 auto;
display: block;
height: 20px;
line-height: 20px;
vertical-align: middle;
}

That was the right CSS. Thanks for ideas:
#img_manip_header
{
height:30px;
width:300px;
background-color:#DEDEDE;
margin: 0 auto;
display: block;
height: 20px;
line-height: 20px;
vertical-align: middle;
text-align:center;
}
#img_manip_header_back
{
position:relative;
display:inline-block;
float:left;
cursor:pointer;
width:50px;
text-align:center;
margin-left:5px;
margin-right:5px;
}
#img_manip_header_close
{
position:relative;
display:inline-block;
cursor:pointer;
width:50px;
text-align:center;
margin-left:5px;
margin-right:5px;
margin: 0 auto;
}
#img_manip_header_next
{
position:relative;
display:inline-block;
float:right;
cursor:pointer;
width:50px;
text-align:center;
margin-left:5px;
margin-right:5px;
}

Related

How to put a text inside a circle?

The page is in HTML and I've been trying with CSS with but can't get it right.
This is where i 've been :
.box3 {
background-color:yellow;
width:200px;
height:200px;
margin:20px auto;
border-radius:100% }
follow this
.box3 {
width:200px;
height:200px;
line-height: 200px;
border-radius:100% ;
font-size: 20px;
color: #fff;
text-align: center;
background-color:yellow;
margin:20px auto;
}
<div class="box3">Hello I am A Circle</div>

Fixed div with padding increase width

I have a simple template where I show header, content and footer section in the centre, Header has background color and all the contents should have 30px padding on left & right.
I dint it following way but it increases the width.
http://codepen.io/anon/pen/xZapEE?editors=1100
html, body, form {
height: 100%;
background-color: #fff;
height:100%;
}
body {
font-family: "Open Sans","Trebuchet MS",Verdana,Arial,sans-serif;
-webkit-font-smoothing: antialiased;
font-size: 13px;
line-height: 18px;
height: 100%;
margin: 0;
padding: 0;
border: 0;
color: #687074;
height:100%;
background-color: #fff;
}
.main-wrapper{
width:1000px;
margin:0 auto;
position:relative;
height:100% !important;
padding:0 30px;
}
.header-wrapper{
width:100%;
min-height:200px;
background-color:#f5f5f5;
margin:0 auto;
position:relative;
padding:0 30px;
}
.content-main{
width:1000px;
min-height:400px;
margin:0 auto;
position:relative;
height:auto;
background-color:#ccc;
}
.footer-wrapper{
width:1000px;
min-height:200px;
background-color:#f5f5f5;
margin:0 auto;
position:relative;
}
.header-row1{
float:left;
width:100%;
height:150px;
margin-bottom:15px;
}
.header-col1
{
float:left;
width:132px;
width:50%;
}
.header-col2
{
float:right;
width:50%;
}
.header-col2 > h1{
font-size:60px;
text-align:right;
}
.header-logo{
}
.header-row2{
float:left;
width:100%;
height:30px;
margin-bottom:15px;
padding:0 30px;
}
You can use box-sizing to fit it in:
box-sizing: border-box;
Box-sizing values:
content-box: This is the initial and default value as specified by the CSS standard. The width and height properties are measured including only the content, but not the padding, border or margin.
border-box: The width and height properties include the padding and border, but not the margin.

Centering a specific sized div within a div

I have tried the normal techniques for horizontally centering a div within a div. I must still be doing something wrong. Check out the following jsFiddle and help me center the depiction of a tank under the "Inner Level" heading. For convenience I have added a border to all the div tags.
jsFiddle Source
HTML:
<body>
<a href="#">
<div class="div-inline-block" style="text-align:left;width:150px;">
<h2>TEST</h2>
<p>A description</p>
</div>
<div class="div-inline-block"><p><b>Last Update:</b><br />???</p></div>
<div class="div-inline-block"><p><b>Flow Rate:</b><br />??? gpm</p></div>
<div class="div-inline-block"><p><b>Inner Level:</b><br />???</p><div class="tank-level-outer"><div class="tank-level-inner"></div></div></div>
<div class="div-inline-block"><p><b>Outer Level:</b><br />???</p></div>
<div class="div-inline-block"><p><b>Battery Voltage:</b><br />???</p></div>
<div class="div-inline-block"><p><b>Rainfall:</b><br />???</p></div>
<div class="div-inline-block" style="text-align:left;width:100%;"><p><b>Notifications:</b><br />???<br />???</p></div>
</a>
</body>
CSS:
a{
text-decoration:none;
}
div{
border:1px solid red;
}
.div-inline-block {
text-align: center;
height: 100%;
display: inline-block;
vertical-align: top;
margin-left:15px;
width: 100px;
}
.tank-level-outer {
border:1px solid black;
width:25px;
height:32px;
display:table-cell;
vertical-align:bottom;
margin:0 auto;
}
.tank-level-inner {
background-color:dodgerblue;
width:25px;
height:25px;
}
add this
.div-inline-block {
text-align: center;
height: 100%;
display: inline-block;
vertical-align: top;
margin-left:15px;
width: 100px;
margin:0 auto;
}
.tank-level-outer {
border: 1px solid black;
width: 25px;
height: 32px;
margin: 0 auto;
padding: 0;
}
.tank-level-inner {
background-color:dodgerblue;
width:25px;
height:25px;
margin-top:7px;
display: table;
vertical-align: bottom;
}
Updated Fiddle
http://jsfiddle.net/czgoxafr/22/
Add this:
.tank-level-outer {
display: table;
margin: 0 auto;
}
change the css of div .tank-level-outer and add margin zero auto , remove display table-cell
.tank-level-outer {
border: 1px solid #000;
width: 25px;
height: 32px;
margin: 0px auto;
vertical-align: bottom;}
This works:
.tank-level-outer {
width:25px;
height:32px;
display:block; // not necessary since this class is applied to a div
vertical-align:bottom;
margin:0 auto;
}
try this:
//css
.firstDiv{
padding:25% 25% 25% 25%
height:400px;
width:400px;
background-color:red;
}
.secondDiv{
height:200px;
width:200px;
background-color:pink;
}
//html
<div class="firstDiv">
<div class="secondDiv">
</div>
</div>

Fill up a <div> with text and <input>

How can I fill a <div> element with text and input so if the <div> get resized the input becomes shorter/longer?
I'm sitting since 2 hours and I just can't get it right.
Here's a Cross browser solution, Pure CSS
Demo
HTML:
<div class="Container">
<label>text</label>
<div class="Fill"><input type="text" /></div>
</div>
CSS:
.Container
{
background-color:#B5E51D;
padding: 5px;
}
label
{
float: left;
padding: 0 10px;
}
.Fill
{
overflow: hidden;
}
input
{
width: 97%;
margin: 0 1%;
}
Like this
demo
css
.divbg{
background-color:#B5E51D;
padding:5px;
overflow:hidden;
width:100%;
}
label{
float:left;
margin:0 0 0 20px;
}
input{
float:left;
background-color:#ED1B24;
color:white;
border:none;
padding:2px 5px;
margin:0 0 0 20px;
min-width:200px;
}
.pull-left{
float:left;
}

Is there a way to get a fixed width of 100% in CSS?

I am trying to make my site more scalable, and would like all of my divs to take up the whole width of the page. If not, I would like them all to be centered and 960px. The problem is that none of the divs are actually centered when I try margin-left:auto, margin-right:auto;. When I try to make the width 100%, and then try to resize the window, everything gets wacky.
Here is the site:
http://eitanrosenberg.com/newsite/index.html
Here is my CSS:
*
{
margin:0;
padding:0;
}
.everythang
{
margin-left:auto;
margin-right:auto;
}
.topbar
{
background-color:#000;
height:75px;
margin-left:auto;
margin-right:auto;
position:fixed;
width:100%;
z-index:10;
}
.logo
{
color:#FFF;
float:left;
font-family:HarabaraRegular,helvetica;
font-size:45px;
margin:15px auto 0 20px;
padding-left:100px;
position:relative;
width:160px;
}
.navbar ul
{
color:#FFF;
display:inline;
float:right;
list-style-type:none;
margin-right:25px;
margin-top:15px;
text-decoration:none;
}
.navbar ul li
{
display:block;
float:left;
margin:15px auto 0 5px;
padding-right:32px;
}
.navbar ul li a
{
color:#FFF;
font-family:HitchcockRegular, helvetica;
font-size:25px;
text-decoration:none;
}
.navbar ul li a:hover
{
color:#0CF;
}
.white
{
background-color:#F8F8F8;
background-image:url(gradients/radialg_200.png);
background-position:30% 0;
background-repeat:no-repeat;
height:300px;
margin:0;
padding:50px 0 0;
width:960px;
}
.hello
{
color:red;
font-family:CoolveticaRegular, helvetica;
font-size:50px;
margin-left:auto;
margin-right:auto;
padding-top:50px;
text-align:center;
}
.hello2
{
color:red;
font-family:CoolveticaRegular, helvetica;
font-size:35px;
margin-left:auto;
margin-right:auto;
padding-top:10px;
text-align:center;
}
.hello3
{
color:#0CF;
font-family:CoolveticaRegular, helvetica;
font-size:35px;
margin-left:auto;
margin-right:auto;
padding-top:10px;
text-align:center;
}
.orange
{
background-color:#F93;
background-image:url(gradients/radialg_400.png);
background-position:30% 0;
background-repeat:no-repeat;
height:500px;
margin:0;
padding:50px 0 0;
width:960px;
}
.workbar ul
{
color:#FFF;
float:left;
line-height:25px;
list-style-type:none;
margin-left:100px;
margin-right:25px;
margin-top:100px;
text-decoration:none;
}
.workbar ul li
{
margin:2px auto 0 35px;
padding-right:32px;
}
.workbar ul li a
{
color:#FFF;
font-family:helvetica;
font-size:25px;
font-style:bold;
text-decoration:none;
}
.workbar ul li a:hover
{
color:red;
}
.red
{
background-color:red;
background-image:url(gradients/radialg_400.png);
background-position:30% 0;
background-repeat:no-repeat;
height:500px;
margin:0;
padding:50px 0 0;
position:static;
width:960px;
}
.red h2
{
color:#FFF;
font-family:Helvetica;
font-size:45px;
margin-left:100px;
padding-top:40px;
}
.red ul
{
color:#FFF;
float:left;
list-style-type:none;
margin-left:100px;
margin-right:25px;
margin-top:15px;
text-decoration:none;
}
.red ul li a
{
color:#FFF;
font-family:helvetica;
font-size:20px;
font-style:bold;
text-decoration:none;
}
.faves img
{
display:inline;
float:left;
height:50px;
padding-top:15px;
position:relative;
width:50px;
}
.faves
{
padding-top:25px;
}
.faves h2
{
display:inline;
float:left;
margin-top:25px;
padding-top:15px;
}
.lists
{
margin-top:100px;
}
.list1
{
float:left;
width:320px;
}
.list2
{
float:left;
width:320px;
}
.list3
{
width:320px;
}
.gray
{
background-color:#2e3031;
background-image:url(gradients/radialg_400.png);
background-position:30% 0;
background-repeat:no-repeat;
height:700px;
margin:0;
padding:50px 0 0;
position:static;
width:960px;
}
.gray h2
{
color:#FFF;
font-family:Helvetica;
font-size:45px;
margin-left:100px;
padding-top:40px;
}
.resumeImg img
{
display:block;
height:550px;
margin-left:auto;
margin-right:auto;
width:900px;
}
Making an element centered using margin requires the element to have a layout. When using margin-left and margin-right, that would be the width property.
An alternate way to center your elements is :
position: absolute;
width: 800px;
left: 50%;
margin-left: -400px;
You would move the element 50% from the left and then 400px (half the width) back. This also works for heights.
Have your wrapper divs ('white', 'orange', etc) be set to width: 100%; and have your content inside (preferably in another div, set to width: 960px; margin: 0 auto;:
.white, .orange {
width: 100%;
}
.white-wrapper {
width: 960px;
margin: 0 auto;
}
And use the following HTML:
<div class="white">
<div class="white-wrapper">
-- content --
</div>
</div>
In this way, your backgrounds will appropriately fill the page, and your content will float in the center and work correctly when shrinking the page. I'd recommend against dynamically changing the width of your content, as it presents readability issues (and tends to look gross), but if you really want to, try min-width:
.white {
min-width: 960px;
}
This will ensure that your divs are always at least 960px wide;
If I understand your question correctly, you want a fixed centered layout that is 960px wide UNLESS the browser window is less than 960px, then you want the layout to be full width.
To do this, wrap your entire html code in a container, like so:
<body>
<div id="container">
<!-- your code here -->
</div>
</body>
And apply this css:
#container {margin:0 auto;max-width:960px;}
Internet Explorer 6 doesn't understand max-width, so if that's a concern you could either give IE6 a fixed width of 960px:
#container {margin:0 auto;max-width:960px;}
* html #container {width:960px;} /* IE6 hack */
or force max-width in IE6 with an even uglier hack:
* html #container {width: expression(document.body.clientWidth > 962? "960px");