Is there something wrong with my float:left in CSS - html

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>

Related

How to make divs display in one line in my situation

The "blank" is as wide as the whole page. Now I want to add a google ads div after the text "back to topic". I already try "float:left". It do not work well.
<div class="blank">
<p>
< Back to the topic
</p>
this is google ads!
</div>
CSS
.blank p{
width:980px;
height:25px;
margin:80px auto 0px auto;
}
.blank p a{
color:#007aff;
font-size:20px;
}
Separate your elements what you want to float, and wrap them with a container. After that, clear. JSFIDDLE
<div class="container">
<div class="blank">
<p>« Back to the topic</p>
</div>
<div class="advert"><p>this is google ads!</p></div>
<div class="clear"></div>
</div>
CSS
div.container {
width:980px;
height:25px;
margin:80px auto 0px auto;}
.blank {
float: left;
margin-right: 20px;
}
.blank p a{
color:#007aff;
font-size:20px;
}
.advert {float: left;}
.clear {clear: both;}
You could use display: inline-block;
html
<div class="blank">
<p>< Back to the topic</p>
<div class="google-ad">this is google ads!</div>
</div>
css:
.blank p{
width:980px;
height:25px;
margin:80px auto 0px auto;
display: inline-block;
}
.blank p a{
color:#007aff;
font-size:20px;
}
.google-ad{
display: inline-block;
}

Placing links over an image

I'm trying to create a navigation bar. The background consists of an image, and I'm using text placeholders until I have the links sorted. I cannot seem to get the text to appear on the navigation bar, rather they insist on appearing below in a list style.
An example:
The grey gradiented bar is intended to be the navigation bar.
HTML:
<div id="pagewrapper">
<div id="container">
<div id="left"></div>
<div id="right"></div>
<div id="center">
<div id="pagebanner">
<img src="img/banner.png" />
</div>
<div id="navibar">
<img src="img/navibar.png">
<div class="naviitems">
Home
</div>
<div class="naviitems">
PHolder1
</div>
<div class="naviitems">
PHolder2
</div>
<div class="naviitems">
PHolder3
</div>
<div class="naviitems">
Contact Us
</div>
</img>
</div>
<div id="pagecontent">
<h1>Oh no, I broke my elephant!</h1>
<p>Wiggle!</p>
</div>
</div>
</div>
And the corresponding CSS:
#container{
margin: 0 auto;
width:1017px;
text-align:center;
}
#left{
float:left;
width:160px;
height:900px;
background-color: #D8D8D8;
}
#right{
float:right;
width:160px;
height:900px;
background-color: #D8D8D8;
}
#center{
display: inline-block;
margin:0 auto;
width: 697px;
}
#pagebanner{
display: inline-block;
margin:0 auto;
width: 697px;
}
#navibar{
display: inline-block;
margin:0 auto;
width: 697px;
height: 27px;
}
.naviitems{
margin: 0 auto;
height:25px;
width:20%;
}
#pagecontent{
display: inline-block;
margin:0 auto;
width: 697px;
}
You need to set the background property of the parent DIV to the image instead of calling it using an IMG tag.
.navibar {
background:url(URLofImage)
}
I used
background: linear-gradient(180deg, #777, #eee);
instead of a background image, see if it fits your needs... jsfiddle

how to set icon and text inline on header of in phonegap app?

____________________________________________________________
| logo_icon page_Tittle |
------------------------------------------------------------
I want to make a header of my phonegap app like this one. On the left of the header there should be a logo(img) and on center there should be page tittle(text). Now I have already try this one.
<div data-role="header" >
<div class="logo" > <img src="img/logo.png" /> </div>
<h1 id="tittle">Main Page</h1>
Exit
</div>
and the css its css is:
.logo {
vertical-align: left;
}
.tittle{
text-align: center;
display: inline-block;
vertical-align: middle;
}
Kindly help me how it will be work? I am new in css.
<div data-role="header" class="header" >
<div class="logo" > <img src="img/logo.png" /> </div>
<h1 id="tittle">Main Page</h1>
Exit
</div>
the css:
.header{display:inline-block;
padding:5px 15px;
text-align:center;
width:100%;
}
.logo{float:left;}
.header h1 {font-size:15px;
width:80%;
text-align:center;}
basically, by adding the text align property of the header div as center, and setting the float property of the logo element to left, should solve your problem
check out the js fiddle link :)
http://jsfiddle.net/Q2Hkj/
This should work for you:
.logo {
float:left;
}
.tittle{
text-align: center;
width:75%; margin:0 auto;
vertical-align: middle;
}
I recommend you to do that with max number of % size and position in your css and use a JavaScript function for center the elements depending of the window size.
Anyway I created a fiddle example for you, take a look and some ideas.
HTML:
<div id="top_bar">
<img id="logo_top_bar" src="../img/logo_top_bar.png">
<section id="title">App title</section>
</div>
CSS:
html,body{
position: relative;
padding: 0px;
margin: 0px;
width: 100%;
max-width: 100%;
height: 100%;
max-width: 100%;
overflow:hidden;
}
#top_bar{
position:relative;
float:left;
height: 60px;
width:100%;
left:0;
top:0;
overflow:hidden;
background-color:rgb(46, 42, 42);
}
#logo_top_bar{
position:absolute;
height:30px;
width:70px;
left:4%;
top:15px;
}
#title{
position:absolute;
left:45%;
top:16px;
font-size: 1.5em;
color:white;
}

How to have centered content with a left menu using css only?

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.

ie6 margin expanding by 20px

i have div's wrapped under div's my html code is.
<div id="content-row">
<div id="left-box">
<div id="small-box">
</div>
<div id="small-box">
</div>
<div id="small-box">
</div>
<div id="small-box">
</div>
</div>
</div>
and my css is
/*content-row*/
#content-row {
margin: 0 auto!important;
padding-left:50px;
width:990px;
height:320px;
padding-bottom:20px;
}
#left-box {
float:left;
width:360px;
height:340px;
}
#small-box {
width:160px;
height:150px;
background-color:#fff;
float:left;
margin:0px 20px 20px 0px;
}
the above style sheet is exclusively for ie6. my problem is the left-box is taking an extra 20px at the right side. when i have defined the left-box to be 360px; it it taking as 380px;
here is the link to the full code.
http://jsfiddle.net/HXGsT/
what is wrong with the code?
It's a known bg in IE6, see this page for more information:
http://www.positioniseverything.net/explorer/doubled-margin.html
Basically, the quick fix is to also add display: inline; to the floating element.
In response to your comment:
<div class="content-row">
<div id="left-box">
<div class="small-box">
</div>
<div class="small-box">
</div>
<div class="small-box">
</div>
<div class="small-box">
</div>
</div>
</div>
.content-row {
margin: 0 auto!important;
padding-left:50px;
width:990px;
height:320px;
padding-bottom:20px;
}
#left-box {
float:left;
width:360px;
height:340px;
}
.small-box {
width:160px;
height:150px;
background-color:#fff;
float:left;
margin:0px 20px 20px 0px;
}
The id #left-box can be an ID as there is only one of these elements with id="left-box" in the document, but because the others are repeated, they must be defined with classes :)