I am trying to put a title in a div toolbar next to some pictures. The problem is that my text is not well placed, it should be at least on top of the toolbar but instead it is at bottom and doesn't move.
I would like it to be in the vertical middle at left near the pictures.
Here is a codepen : http://codepen.io/anon/pen/fDojK
And a picture :
Here is the html part of the title bar:
<div id="bar" >
<div id="picturesmenu">
<img src='images/back.jpg' alt='back' />
<img src='images/home.jpg' alt='home' />
<img src='images/reload.jpg' alt='reload' />
</div>
<div id="titlemenu">Main</div>
</div>
<div id="body">
...
And style :
#bar
{
width:100%;
height:50px;
padding-top:3px;
padding-left:10px;
border-bottom:2px solid white;
vertical-align:top;
}
#picturesmenu
{
margin:0;
padding:0;
display:inline;
}
#bar img
{
border:3px solid white;
width:40px;
margin:2px;
}
#titlemenu
{
margin:0;
padding-left:20px;
height:100%;
display:inline;
font-size:20pt;
font-weight:bold;
color:white;
}
#bar span
{
margin-left:20px;
margin-top:200px;
font-size:20pt;
font-weight:bold;
color:white;
}
I tried vertical align and margin but the "Main" text doesn't move...
Thanks in advance before I change anything into tables ;)
[EDIT]
Thank you all for your answers ! I didn't thought about handling the alignment of the content (#titlemenu) instead of the container (#bar), it's not very logical...
You need to work the vertical align for both #picturesmenu and #titlemenu and remove the padding left for that title if you want it to the left. Then work with inline-block elements. Like this:
EDITED WITH CROSS-BROWSER CODE
html, body {
height:100%;
width:auto;
padding:0;
margin:0;
background-color:black;
}
#bar {
width:100%;
height:auto;
padding-top:3px;
padding-left:10px;
border-bottom:2px solid white;
display:block;
}
#picturesmenu {
margin:0;
padding:0;
}
#bar img {
border:3px solid white;
width:40px;
margin:2px;
display:inline-block;
vertical-align:middle;
width:40px;
height:50px;
}
#titlemenu {
margin:0;
padding-left:0px;
display:inline-block;
vertical-align:middle;
font-size:20pt;
font-weight:bold;
color:white;
}
.item {
float:left;
width:120px;
height:120px;
border:2px solid white;
text-align:center;
margin:20px;
padding:20px;
}
.picitem {
height:70%;
margin-bottom:25px;
border:2px solid white;
}
.textitem {
underline:none;
color:black;
font-size:16pt;
color:white;
}
I have forked your CodePen
However, a way better approach would be to give #bar a display:block property and then add inline-block to everything inside, but if you want it to work as in your description, there you go
Add these lines to the #titlemenu in CSS
padding:10px;
display:inline-block;
vertical-align:top;
By vertical-align:top, the block gets aligned to the top of the parentdiv and you set padding to fit the height of the block to the height of the parent div
Demo
Related
I have the following HTML:
<div class="flag_container">
<div class="flag_1">
<img class="flag_img_1" src="../images/gb.png"></img>
<div class="speaker_1">
</div>
</div>
<div class="flag_2">
<img class="flag_img_2" src="../images/at.png"></img>
<div class="speaker_2">
</div>
</div>
<div class="flag_3">
<img class="flag_img_3" src="../images/de.png"></img>
<div class="speaker_3">
</div>
</div>
<div class="flag_4">
<img class="flag_img_4" src="../images/nl.png"></img>
<div class="speaker_4">
</div>
</div>
</div>
and CSS:
.flag_img_1{
width:160px;
height:80px;
cursor:pointer;
}
.flag_img_1:hover+.speaker_1{
display:block;
}
.speaker_1{
width:100px;
height:100px;
background-color:red;
display:none;
position:absolute;
margin-left:170px;
margin-top:-90px;
}
.flag_img_2{
width:160px;
height:80px;
cursor:pointer;
}
.flag_img_2:hover+.speaker_2{
display:block;
}
.speaker_2{
width:100px;
height:100px;
background-color:green;
display:none;
position:absolute;
margin-left:170px;
margin-top:-90px;
}
.flag_img_3{
width:160px;
height:80px;
cursor:pointer;
}
.flag_img_3:hover+.speaker_3{
display:block;
}
.speaker_3{
width:100px;
height:100px;
background-color:blue;
display:none;
position:absolute;
margin-left:170px;
margin-top:-90px;
}
.flag_img_4{
width:160px;
height:80px;
cursor:pointer;
}
.flag_img_4:hover+.speaker_4{
display:block;
}
.speaker_4{
width:100px;
height:100px;
background-color:orange;
display:none;
position:absolute;
margin-left:170px;
margin-top:-90px;
}
.flag_container{
padding:80px 0;
}
.flag_1{
padding-left:406px;
}
.flag_2{
float:left;
padding-left:163px;
padding-top:40px;
}
.flag_3{
float:right;
padding-right:163px;
padding-top:40px;
}
.flag_4{
padding-top:160px;
padding-left:406px;
}
Which creates the following display:
and on hover:
Where the blue square is a placeholder for an image.
This all works fine.
I want to make the display responsive, so when the screen gets smaller, the flags take a central formation like:
My problem is, it will not stay central, but will keep a fixed position in relation to the left. Here is my CSS:
.flag_container{
width:80%;
margin:auto;
}
.flag_1{
width:auto;
padding:0;
margin-bottom:20px;
margin-left:20px;
margin-right:20px;
}
.flag_2{
width:auto;
padding:0;
margin-bottom:20px;
margin-left:20px;
margin-right:20px;
}
.flag_3{
width:auto;
padding:0;
margin-bottom:20px;
margin-left:20px;
margin-right:20px;
}
.flag_4{
width:auto;
padding:0;
margin-bottom:20px;
margin-left:20px;
margin-right:20px;
}
.agendaHeading{
float:left;
font-size:120%;
}
.flag_img_1:hover+.speaker_1{
display:none;
}
.flag_img_2:hover+.speaker_2{
display:none;
}
.flag_img_3:hover+.speaker_3{
display:none;
}
.flag_img_4:hover+.speaker_4{
display:none;
}
I have tried every combination I can think of, and read many posts but it does not work. I suspect it is something to do with the structure of my divs preventing it from working as I want?
An example of CSS where I have managed to centre a div in the way I am trying to here is:
.box1{
width:85%;
margin:auto;
border:1px solid #ffffff;
float:none;
height:50px;
}
But this does not work.
Apologies for the long post/amount of code, but to demonstrate my problem I have to include it all.
I think the problem is that you are using pixels and no % in your paddings.
Did you tried to use % instead of fixed pixels in your padding-left,top and right on you css of .flag_*? I've bee playing a little bit with your code and using % gives you a more efficient way of organize the divs on a resized screen.
As you can see by my code, I am creating several different links in the shape of a circle, these links have an image, however when you hover the image, I want it to change the image to something else.
However when I try to hover it will not work? :S
CSS:
.Row {
width:16%;
height:250px;
text-align:center;
margin-top:25px;
margin-left:130px;
float:left;
display:block;
border:0px solid red;
overflow:hidden;
}
.Google {
width:240px;
height:240px;
text-align:center;
border:5px solid white;
border-radius:300px;
margin:auto;
background-image:url("img/googlet.png");
}
.Google:hover {
background-image:url("img/outlook.png");
}
HTML:
<div class="Row">
<div class="Google"></div>
</div>
You can block a tag with a {display:block;}
than write css for hover like following.
a:hover .Google {background-image:url("img/outlook.png");}
I'm trying to follow this tutorial, but I'm hitting a strange css issue. I am getting a text overflow issue, and I don't know why. Also the last span element is not being shown. I am not a web designer, so any information why this is happening and how to fix it would be awesome.
Thanks!
Image of the Problem
HTML
<div id="suggestions" style="display: block; ">
<p id="searchresults">
<a href="/benefits/1" id="1">
<img src="/system/images/benefits/images/1/thumb_download.png?1309194040">
<span class="searchheading">Eric's Awesome Gym</span>
<span>
At this great gym we strive to make friends. Located in the middle of the grenage village, we are a great location woth tons of resutarnts near by.
</span>
</a>
<span class="seperator">Load More Results</span>
</p>
</div>
CSS
#suggestions{ position: absolute; right:73px; width:320px; display:none; }
#searchresults { border-width:1px; border-color:#919191; border-style:solid; width:320px; background-color:#a0a0a0; font-size:10px; line-height:14px; margin: 0;}
#searchresults a { display:block; background-color:#e4e4e4; clear:left; height:56px; text-decoration:none; }
#searchresults a:hover { background-color:#b7b7b7; color:#ffffff; }
#searchresults a img { float:left; padding:5px 10px; }
#searchresults a span.searchheading { display:block; font-weight:bold; padding-top:5px; color:#191919; }
#searchresults a:hover span.searchheading { color:#ffffff; }
#searchresults a span { color:#555555; }
#searchresults a:hover span { color:#f1f1f1; }
#searchresults span.seperator { float:right; padding-right:15px; margin-right:5px; }
#searchresults span.seperator a { background-color:transparent; display:block; margin:5px; height:auto; color:#ffffff; }
Remove height from your a element and clear your floats:
http://jsfiddle.net/CQzMF/4/
All code in sample.
#suggestions{ position: absolute; right:73px; width:320px; display:none; }
#searchresults { border-width:1px; border-color:#919191; border-style:solid; width:320px; background-color:#a0a0a0; font-size:10px; line-height:14px; margin: 0;}
#searchresults a { display:block; background-color:#e4e4e4; clear:left;text-decoration:none; }
#searchresults a:hover { background-color:#b7b7b7; color:#ffffff; }
#searchresults a img { float:left; padding:5px 10px; }
#searchresults a span.searchheading { display:block; font-weight:bold; padding-top:5px; color:#191919; }
#searchresults a:hover span.searchheading { color:#ffffff; }
#searchresults a span { color:#555555; }
#searchresults a:hover span { color:#f1f1f1; }
#searchresults span.seperator { float:right; padding-right:15px; margin-right:5px; }
#searchresults span.seperator a { background-color:transparent; display:block; margin:5px; height:auto; color:#ffffff; }
.clear {clear:both;height:1px;font-size:1px;line-height:1px;}
<div id="suggestions" style="display: block; ">
<p id="searchresults">
<a href="/benefits/1" id="1" class="clearme">
<img src="/system/images/benefits/images/1/thumb_download.png?1309194040" width="50" height="100">
<span class="searchheading">Eric's Awesome Gym</span>
<span>
At this great gym we strive to make friends. Located in the middle of the grenage village, we are a great location woth tons of resutarnts near by.
</span>
<div class="clear"></div>
</a>
<span class="seperator">Load More Results</span>
</p>
</div>
Alternatively you can also use overflow:hidden on a - just remove height from it and you don't need a anymore in the code.
I fixed you a little more solid solution using overflow:hidden and a little bit more validator friendly.: http://jsfiddle.net/CQzMF/19/ check it out also.
#searchresults a img { float:left; padding:5px 10px; }
its because of that. the element is floating. add a clear:both div underneath the span.seperator to expand the containing div container:
<div style="clear:both">&nspb;</div>
or remove the float right from the text. Or better wrap it into a span which you style with display:block and float:right.
your image link is too long try shortening it and I would have to agree with the guy above try a step by step code refactoring
CSS stylesheet
div.Header
{
background-color:#999999;
text-transform:capitalize;
text-align:center;
}
div.leftdiv
{
float:left;
height:200px;
width:15%;
position:fixed;
background-color:#FFFF66;
text-transform:uppercase;
text-align:justify;
}
div.rightdiv
{ margin-left:15px;
margin-top:25px;
float:left;
position:fixed;
background-color:#FFFF99;
width:50%
height:200px;
left: 438px;
top: 39px;
}
div.footer
{
clear:both;
margin-left:20px;
margin-top:20px;
margin-right:20px;
margin-right:20px;
padding-bottom:10px;
padding-left:10px;
padding-right:10px;
padding-right:10px;
border-color:#000066
border:thick;
text-align:center;
background-color:#FFCCFF;
}
Upon further review, it looks like you have some fixed position attributes that are tripping you up. If you remove them, everything displays fine:
http://jsbin.com/emona3/3/edit
put float:left for footer its essential to move footer after all other div .
I am trying to create a little growl like div for a site. It works great in Firefox, but not IE6 (haven't tried IE7, but I still need to support IE6).
In Firefox: Centered text with image floated to right side of div
In IE6: Centered text with image to the left of text.
I've tried switching the img and span tag order, but that causes a line break in FF between the two, and IE renders the image on the right of the text, but not docked to the right side of the div.
HTML
<div id="growl">
<img src="close.gif" class="action" title="hide" />
<span class="text">Grrrrrr.......</span>
</div>
In css:
#growl {
background-color:yellow;
text-align:center;
position:absolute;
top:0; left:0;
width:98%;
padding:10px 0;
margin-left:1%;
z-index:10;
border:1px solid #CCCCCC;
}
#growl > .text {
font-size:120%;
font-weight:bold;
}
#growl > .action {
float:right;
cursor:pointer;
}
The > selector does not work on IE 6.
Just get rid of it:
#growl .text {
font-size:120%;
font-weight:bold;
}
#growl .action {
float:right;
cursor:pointer;
}
The > css selectors are not supported by IE6, try just removing them.
No point in adding a class to each elements in the div when you only have one img and span. Do this instead for cleaner code.
<div id="growl">
<img src="close.gif" title="hide" />
<span>Grrrrrr.......</span>
</div>
-
#growl {
background-color:yellow;
text-align:center;
position:absolute;
top:0; left:0;
width:98%;
padding:10px 0;
margin-left:1%;
z-index:10;
border:1px solid #CCCCCC;
}
#growl span {
font-size:120%;
font-weight:bold;
}
#growl img {
float:right;
cursor:pointer;
}