I'm trying to design a flag for a website i'm doing and the design is the parts at the bottom of the flag, they stack when i don't float them (expected) but when i do float them, they shrink to the text inside of the box, How can i fix this? Here's my code:
#flag1{
max-width:400px;
max-height:1000px;
margin:0 auto;
}
#mainflag{
background-color:#BA0500;
max-width:400px;
max-height:1000px;
position:relative;
height:auto;
margin: 0 auto;
text-align:center;
padding:5px;
color:white;
}
#flagdesign1{
background-color:#BA0500;
max-width:100px;
position:relative;
max-height:50px;
color:#BA0500;
margin-top:-21px;
margin-right:20px;
}
<div id="flag1">
<div id="mainflag">
<h1>Flag</h1>
</div>
<div id="flagdesign1">
<h1>A</h1>
</div>
<div id="flagdesign1">
<h1>A</h1>
</div>
</div>
In the end, it should look something like these
If I understand your question well, you could try using display: table;.
Also, an ID is supposed to be unique, you should use classes instead.
I also used span instead of h1 for the flag element, as IE might not permit using display: inline-block;, depending on the version you're supporting.
#flag1{
max-width:400px;
max-height:1000px;
margin:0 auto;
}
#mainflag{
background-color:#BA0500;
max-width:400px;
max-height:1000px;
position:relative;
height:auto;
margin: 0 auto;
text-align:center;
padding:5px;
color:white;
}
.bottomFlag {
display: table;
width: 100%;
}
.bottomFlagElem {
display: table-cell;
}
.bottomFlagElem.center {
text-align: center;
}
.bottomFlagElem.left {
text-align: left;
}
.bottomFlagElem.right {
text-align: right;
}
.bottomFlagElem span {
display: inline-block;
width: 100%;
background-color:#BA0500;
max-width:100px;
position:relative;
min-height:30px;
max-height:50px;
color:#BA0500;
margin: 0;
}
<div id="flag1">
<div id="mainflag">
<h1>Flag</h1>
</div>
<div class="bottomFlag">
<div class="bottomFlagElem left">
<span>A</span>
</div>
<div class="bottomFlagElem center">
<span>A</span>
</div>
<div class="bottomFlagElem right">
<span>A</span>
</div>
</div>
</div>
I will have a three child div's in a wrapper, two of them will need to float right and one will always float left(one which has .main class). you can have a look at my HTML structure in the fiddle
My Fiddle Here
HTML:
<div id="wrap">
<div class="child">
This is initiator
</div>
<div class="child">
This is second joinee
</div>
<div class="main child">
This is third joinee
</div>
</div>
CSS:
#wrap{
width:600px;
height:400px;
}
.child:nth-child(even){
background:red;
}
.child:nth-child(odd){
background:green;
}
.child{
height: 200px;
width: 200px;
display: block;
float: right;
clear:right;
text-align: center;
vertical-align: middle;
}
.main{
height: 400px!important;
width: 400px!important;
float:left!important;
clear:none!important;
background:yellow !important;
}
But the Left floated Div always comes down. can some one help me understanding this behaviour.
Note: I don't want to change my HTML structure.
Add the following to the main class in your css file:
.main{
position:absolute;
left:0;
}
I am trying to center the contents of the container divs inside which will have four div's alignned 2 divs in a row, but it is not getting centered.
Not sure why this happens in google chrome and other browsers.
Below is the code, please help.
CSS:
.container{
margin: auto;
width:80%;
height:900px;
display: block;
text-align: center;
}
.column, .columns {
float:left;
min-height:1px;
padding:0 15px;
position:relative
}
section#{
width: 100%;
min-height: 500px;
background: url(../images/sidebar_shadow.png) repeat-y left top;
float: left;
margin-top: -2px;
}
.button.largebutton {
min-width:400px;
min-height:300px;
float:left;
margin: 60px;
}
PHP
<section id="main" class="column">
<h1 class="info_bar">My Surveys</h1>
<div class="container"> //contents of this div to be centered
<?php include 'tabcontainer_surveyholder.php'; ?> //pulls the four divs
</div>
</section>
One solution to this is:
Wrap the 4 div's in a wrapper. See the width of the wrapper in console and then write following css:
.wrapper{ position:relative;
left:50%;
margin-left:-(half of its total width);
}
here is a codepen
click me
I don't now what I'm doing wrong. I want the 'artikelen' div to be centered when it's opened. I've tried all kind of combinations but can't figure out what is going wrong.
this is the HTML
<nav class="cl-effect-1"><center>
<span data-hover="Artikelen"><font size="1px">Artikelen</font></span>
<span data-hover="Drukwerk"><font size="1px">Drukwerk</font></span>
<span data-hover="Jaarverslagen"><font size="1px">Jaarverslagen</font></span>
<span data-hover="Mailings"><font size="1px">Mailings</font></span>
<span data-hover="Onderwijs"><font size="1px">Onderwijs</font></span>
<span data-hover="Webteksten"><font size="1px">Webteksten</font></span>
</center></nav>
<div id="artikelen">
<div class="inhoud">
Artikelen
</div>
</div>
this is the CSS
#artikelen {
position:absolute;
display:none;
width:auto;
height:auto;
}
#artikelen:target {
display:block;
margin-left: auto;
margin-right: auto;
}
.inhoud {
background-color:black;
color: white;
width:200px;
height:150px;
margin-left: auto;
margin-right: auto;
}
See here: http://jsfiddle.net/h8GL3/
I removed the
poistion:absolute
property from #artikelen, and now the margin left and right works.
I have two divs:
<div id="left_menu" > menu </div>
<div id="content" > centered </div>
Currently they have a css of
#content {
margin-left:auto;
margin-right:auto;
display:table;
}
So this would create a div with menu and a line below that a centered div with centered. What I want is a centered div#content with div#left_menu to the left of it. I DON'T want to center BOTH the divs together, only the div#content. This should be done with only divs and css and should work on all browsers.
So this could possibly look like
---> menu centered <--------
Just to clarify things:
I'm not centering/positioning the text, it's the divs that matter (text is there for marking the position in the example). I want both divs on the same line (like a span, but i want to use divs), the centered div should be centered in the middle of the page. The menu div should be right next to it, touching the left border of the centered div.
This solution should work for every screen size (e.g. if the screen is very large the two side gaps to the left and right of the menu and content should be very large, e.g. if the screen is too small for both the menu and content, there should be no gaps and the result should look like (the >< represent the cutoff) Notice how if the screen is too small, the menu div is fully displayed first with the centered div cutoff (as if it were just two divs floated left).
>menu cent<
Due to the number of incorrect answers being submitted:
1) Please verify your answers by creating your own .html file with your code
2) Refresh once on full screen and refresh once with browser resized to a smaller size such that the browser cannot hold both divs (e.g. the centered div is semi-cutoff)
3) Use inspect element tool(chrome) or equivalent tools to be sure that the two divs are touching, the centered div is indeed centered, etc
To further clarify what i want i've included a better example(NOT a solution though):
This does not work for every screen size:
http://jsfiddle.net/prt38/2/
Updated per requests in comments.
I really like using the vertical-align property when vertically-aligning elements.
HTML:
<div id="container">
<span id="alignment"></span><div id="wrapper">
<div id="sidebar">
</div><div id="main">
</div>
</div>
</div>
Notice how the closing and the succeeding are touching. For inline and inline-block elements to touch, there cannot be space between them in the markup.
CSS:
html, body {
height: 100%;
margin: 0;
padding: 0;
text-align: center; }
#container { white-space: nowrap; }
#wrapper {
white-space: nowrap;
text-align: left;
margin: 0 75px 0 0;
vertical-align: middle;
display: inline-block; }
#alignment {
height: 100%;
vertical-align: middle;
display: inline-block; }
#sidebar {
background: red;
width: 75px;
height: 200px;
vertical-align: middle;
display: inline-block; }
#main {
background: blue;
width: 300px;
height: 400px;
vertical-align: middle;
display: inline-block; }
Preview: http://jsfiddle.net/Wexcode/2Xrcm/8/
Your do it with simple overflow:hidden like this:
#left_menu{
float:left;
width:200px;
height:100px;
background:green;
}
#content {
margin-left:auto;
margin-right:auto;
display:table;
height:100px;
background:red;
overflow:hidden;
}
http://jsfiddle.net/hnXqg/
The solution for this is you have to create a wrapper class or id for a div like..
<div id="wrapper">
<div id="left_menu" > menu </div>
<div id="right">
<div id="content" > centered </div>
</div>
</div>
then the css is..
#wrapper{
margin:0px auto;
display:table;
width:90%;
}
#menu{
float:left;
width:300px;
margin:5px;
}
#right{
float:right;
display:block;
}
#content{
displat:table;
margin:0px auto;
}
I think this css should do the job, if I understood your question:
#left_menu{background:red;
width:100px;
height:100px;
float:left;
margin: auto 0;
z-index:2}
#content {
background:white;
width:100px;
height:100px;
margin: auto 0;
float:left;
position:absolute;
left:20%;
z-index:200;
padding-left:4%
}
And Html is below:
<div id="left_menu" >RED DIV</div>
<div id="content" >WHITE DIV</div>
I think this is what you are looking for. Adjust the sizes to suit your needs, obviously.
<style type="text/css">
.container {
margin: auto;
width: 500px;
}
.menu {
margin: 10px;
width: 180px;
}
.content {
margin: 10px;
width: 280px;
text-align: center;
}
.floatLeft {
float: left;
}
.clear {
clear: both;
}
</style>
<div class="container">
<div class="menu floatLeft">
Menu
</div>
<div class="content floatLeft">
Content
</div>
<div class="clear"></div>
</div>
Edited:
<style type="text/css">
.container {
margin: auto;
width: 500px;;
background: red;
}
.menu {
width: 50px;
margin-left: 50px;
background: green;
}
.content {
width: 300px;
margin: auto;
background: blue;
}
.floatLeft {
float: left;
}
.clear {
clear: both;
}
</style>
<div class="container">
<div class="menu floatLeft">
Menu
</div>
<div class="content">
Content
</div>
<div class="clear"></div>
</div>
<div align="center">
<span id="left_menu"> menu </span>
<span id="content"> centered </span>
</div>
html { text-align: center; }
div#content { display: inline; margin: 0 auto; text-align: left;width: 980px; }
something like this should work.