Vertically align header elements - html

I know this question has been asked a lot but I can't find any fix working for my sample.
I read and tried solutions stated in alignment tutorial.
I tried playing with display: inline-block; and vertial-align: middle; as much as I could.
My HTML:
<div id="header_container">
<div id="logo"></div>
<div id="menu_and_social_icons_container">
<div id="menu_container">
<ul>
<li>Portfolio</li>
<li>About</li>
<li>Contact</li>
</ul>
</div><!--//menu_container-->
<div id="social_icons_container">
<div id="twitter_icon"></div>
<div id="pinterest_icon"></div>
</div><!--//social_icons_container-->
</div><!--//menu_and_social_icons_container-->
</div><!--//header_container-->
My CSS:
/* Header */
#header_container { padding: 10px 0 30px; width: 100%; height: auto; padding-top: 3%; border-bottom: 1px solid #CBCBCB; display: inline-block; }
#logo { background: #aaa; width: 200px; height: 100px; float: left; vertical-align: middle; }
#menu_and_social_icons_container { float: right; display: inline-block; vertical-align: middle; }
#menu_container { text-transform: uppercase; font-size: 1.3em; font-style: bold; float: left; font-family: 'Lato', sans-serif; vertical-align: middle; }
#menu_container ul { list-style-type: none; }
#menu_container ul li { display: inline-block; margin-left: 20px; text-decoration: none; color: #4e918b; }
#menu_container ul li:hover { font-weight: 900; }
#social_icons_container { float: right; vertical-align: middle; }
#social_icons_container div { width: 50px; height: 50px; float: left; margin-left: 25px; }
#twitter_icon { background: #555; }
#pinterest_icon { background: #888; }
Here is a JSFiddle to make things easier.

Vertical-align won't work with Floated elements.
Remove float and try to do it with inline-block alone.
Here is the solution fiddle. http://jsfiddle.net/yvxb1os1/11/
/* Header */
#header_container { padding: 10px 0 30px; width: 100%; height: auto; padding-top: 3%; border-bottom: 1px solid #CBCBCB; display: inline-block; }
#logo { background: #aaa; width: 200px; height: 100px; display: inline-block; vertical-align: middle; }
#menu_and_social_icons_container { display: inline-block; vertical-align: middle; width: calc(100% - 204px); }
#menu_container { text-transform: uppercase; font-size: 1.3em; font-style: bold; font-family: 'Lato', sans-serif; vertical-align: middle; display: inline-block;}
#menu_container ul { list-style-type: none; }
#menu_container ul li { display: inline-block; margin-left: 20px; text-decoration: none; color: #4e918b; }
#menu_container ul li:hover { font-weight: 900; }
#social_icons_container { float: right; vertical-align: middle;}
#social_icons_container div { display: inline-block; width: 50px; height: 50px; float: left; margin-left: 25px; }
#twitter_icon { background: #555; }
#pinterest_icon { background: #888; }

Thanks to "Vertical-align won't work with Floated elements." from #user387249, I found the best solution in my case. See Justin Drury's answer for more details.
Most important change:
#logo_container:after, #menu_container:before, #social_icons_container:before { height: 100%; content: ''; font-size: 0; vertical-align: middle; display: inline-block; }
And height: 100% on my 3 floated div.
Here is the updated JSFiddle.

Related

image overlapping border in safari

I have a pagination with numbers in circles, when you hover on circle corresponding image will display, but in safari the image is overlapping the circle's border..
Fiddle:-
http://jsfiddle.net/2yx5e3w1/
CSS and HTML
* {
margin: 0;
padding: 0;
}
ul li {
list-style: none;
}
a {
text-decoration: none;
}
.pagination_wrap * {
box-sizing: border-box;
}
.pagination_wrap {
float: left;
width: 680px;
box-sizing: border-box;
position: relative;
}
.pagination_wrap ul {
display: table;
text-align: center;
width: 620px;
margin: auto;
}
.pagination_wrap li {
display: table-cell;
vertical-align: middle;
}
.pagination_wrap li a {
display: block;
width: 51px;
height: 51px;
border-radius: 50%;
border: 2px solid #dadada;
background: #e2e2e2;
margin: auto;
overflow: hidden;
}
.pagination_wrap li a:after {
content: "";
display: inline-block;
height: 100%;
margin-left: -4px;
vertical-align: middle;
width: 0;
}
.pagination_wrap li img {
display: none;
margin-left: -4px;
vertical-align: middle;
}
.pagination_wrap li span {
vertical-align: middle;
display: inline-block;
font-family: Arial, Helvetica, sans-serif;
color: #000;
font-size: 19px;
line-height: 47px;
}
.pagination_wrap li a:hover img, .pagination_wrap li.current img {
display: inline-block;
}
.pagination_wrap li a:hover span, .pagination_wrap li.current span {
display: none;
}
a.prev_arrow, a.next_arrow {
height: 25px;
width: 15px;
background-image: url("http://i9.dainikbhaskar.com/dainikbhaskar2010/images/pagination/slide_nav.jpg");
position: absolute;
}
a.prev_arrow.disabled {
background-position: left -28px;
cursor: default;
}
a.next_arrow.disabled {
background-position: right -28px;
cursor: default;
}
a.prev_arrow {
float: left;
background-position: left top;
left: 0;
top: 12px;
}
a.next_arrow {
float: right;
background-position: right top;
right: 0;
top: 13px;
}
<div class="pagination_wrap">
<ul>
<li class="current"><img src="http://i9.dainikbhaskar.com/thumbnail/51x51/web2images/www.bhaskar.com/2015/04/07/players_1428406480.jpg" alt="" /><span>1</span></li>
<li><span>2</span> <img src="http://i9.dainikbhaskar.com/thumbnail/51x51/web2images/www.bhaskar.com/2015/04/07/players_1428406480.jpg" alt="" /></li>
<li><span>3</span> <img src="http://i9.dainikbhaskar.com/thumbnail/51x51/web2images/www.bhaskar.com/2015/04/07/players_1428406480.jpg" alt="" /></li>
</ul>
</div>
Give a border radius of 100% to both the image and container
.pagination_wrap li a,
.pagination_wrap li a img {
-webkit-border-radius: 100%;
border-radius: 100%;
}
also note that Safari for Windows has been discontinued since May 9, 2012.

How to display (<li>) menu items over divs - z-index not working

I am using a ul & li a bit like a select dropdown to trigger a JS function (not shown).
It's working fine - except the menu items appear BEHIND divs that are shown below them.
I've mocked up the problem here: http://jsfiddle.net/bf8ugef7/1/
I'm fiddling with z-index and position:absolute but can't see how to make it work.
Can anyone help?
Here is the HTML and CSS:
body {
font-family: sans-serif;
color: gray;
font-weight: 100;
}
div, li {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
-ms-box-sizing: border-box;
box-sizing: border-box;
}
li {
color: #333333;
text-decoration: none;
/* background-image: url("images/mullion.gif"); */
}
div.images {
border: 1px solid #555555;
/* padding-left: 5px; */
width: 100%;
float: left;
clear: left;
margin-bottom: 20px;
/*
background-image: url("images/iMullion.gif");
background-repeat: no-repeat;
*/
}
div.lowerText {
width: 100%;
}
div.btn {/* +filter */
float: right;
width: 195px;
cursor: default;
text-align: right;
/* margin-left: 1px; */
display: inline-block;
}
div.btn1 {
float: left;
width: 153px;
cursor: default;
text-align: center;
margin-left: 1px;
display: inline-block;
position: absolute;
color: black;
background-color: #79c1ee;
left: 182px;
}
div.btn2 {
float: left;
width: 20px;
display: inline-block;
color: white;
font-weight: 100;
text-align: center;
background-color: white;
cursor: default;
position: absolute;
left: 162px;
z-index: 100;
}
div.btn2 ul {
list-style: none;
position: absolute;
display: block;
margin: 0px;
padding: 0px;
z-index: 100;
}
div.btn2 ul li {
display: none;
cursor: pointer;
color: white;
height: 25px;
background-color: #79c1ee;
margin-top: 1px;
z-index: 100;
}
div.btn2 ul li:first-child {
margin-top: 0px;
display: inline-block;
width: 20px;
z-index: 100;
}
div.btn2 ul:hover {
height: 200px;
}
div.btn2 ul:hover li {
display: block;
z-index: 100;
}
div.btn2 ul li:hover {
background-color: #13A3E2;
z-index: 100;
}
/*
div.btn2 ul li:hover {
display: block;
width: 20px;
height: 100px;
}
*/
div.btn3 {
margin-left: 1px;
float: left;
width: 20px;
display: inline-block;
vertical-align: top;
text-align: center;
font-weight: 400;
color: white;
background-color: #13A3E2;
position: absolute;
left: 336px;
cursor: pointer;
}
div.btn3:hover {
background-color: red;
}
div.btn4 {
/* border: 1px solid black; */
padding-left: 5px;
float: left;
width: 153px;
display: inline-block;
color: #444444;
cursor: default;
background-color: white;
}
div.attr {
padding-left: 5px;
color: #444444;
background-color: #79C1ED;
float: right;
clear: none;
display: inline-block;
text-align: left;
}
div.filters {
width: 100%;
line-height: 1.8;
overflow: hidden;
display: block;
font-size: 14px;
text-decoration: none;
float: left;
}
div.toptext {
line-height: 2.2;
display: block;
max-height: 35px;
color: #444444;
background-color: #555555;/* matches border color */
color: white;
width: 100%;
padding-left: 5px;
cursor: not-allowed;
/* border: 1px solid pink; */
}
div.leftnav {
width: 350px;
float: left;
clear: left;
}
div#container {
padding: 0px;
margin: 0px;
}
<div class="leftnav">
<div class="images">
<div class="toptext">Filters
<div class="btn">+ filter</div>
</div>
<div id="container">
<div class="filters rem" id="f12">
<div class="btn4" id="b4f12">Pupil name</div>
<div class="btn2" id="b2f12">
<ul>
<li id="ddf_12_0">=</li>
<li id="ddf_12_1">></li>
</ul>
</div>
<div class="btn1" id="b1f12">Joe Bloggs</div>
<div class="btn3" id="if12">x</div>
</div>
<div class="filters rem" id="f13">
<div class="btn4" id="b4f13">Pupil name</div>
<div class="btn2" id="b2f13">
<ul>
<li id="ddf_13_0">=</li>
<li id="ddf_13_1">></li>
</ul>
</div>
<div class="btn1" id="b1f13">Bill Clinton</div>
<div class="btn3" id="if13">x</div>
</div>
</div>
</div>
</div>
Thanks
Emma
Try this code:
div.btn2 {
float: left;
width: 20px;
display: inline-block;
color: white;
font-weight: 100;
text-align: center;
background-color: white;
cursor: default;
left: 162px;
}
div.btn2 ul {
display: block;
margin: 0;
padding: 0;
}
div.btn2 ul li {
display: none;
cursor: pointer;
color: white;
height: 25px;
background-color: #79c1ee;
}
div.btn2 ul li:first-child {
display: inline-block;
border-top: none;
width: 20px;
}
div.btn2:hover li {
display: block;
position: absolute;
width: 20px;
border-top: 1px solid #fff;
}
div.btn2:hover li:first-child {
position: relative;
}
div.btn2 ul li:hover {
background-color: #13A3E2;
}
# Claudiu Yes it should be comment, but i dont have enough points to add comments
div.btn2 {
width: 20px;
display: inline-block;
color: white;
font-weight: 100;
text-align: center;
cursor: pointer;
left: 162px;
}
div.btn2 ul {
display: block;
margin: 0;
padding: 0;
}
div.btn2 ul li {
display: none;
cursor: pointer;
color: white;
height: 25px;
background-color: #79c1ee;
}
div.btn2 ul li:first-child {
display: inline-block;
width: 20px;
}
div.btn2:hover li {
display: block;
position: absolute;
width: 20px;
background: #000;
}
div.btn2:hover li:first-child {
position: relative;
}
div.btn2 ul li:hover {
background-color: #13A3E2;
}
i have updated the fiddle

anchor link is not clickable in full width

I make a list that looks like the picture below. My problem is that not the whole link is clickable, only the text. I can't make a display: block on the anchor and give the link the full width because I already gave the anchor display: table-cell.
Here you can can see my problem and try out your code:
http://jsfiddle.net/kma_999/v0xkk587/
Thanks in advance!
HTML:
<div class="pane-content">
<ul>
<li>Kostenkontrolle (Mobile)</li>
<li>Sunrise Rechnung</li>
<li>Umzug</li>
<li>iPhone</li>
<li>Telefonieren im Ausland (Roaming)</li>
</ul>
</div>
CSS:
ul {
border: 1px solid lightgray;
padding-left: 0px;
}
ul li {
border-bottom: 1px solid lightgray;
list-style: none outside none;
margin-left: 20px;
margin-right: 20px;
vertical-align: middle;
}
ul li:last-child{
border-bottom: 0px solid black;
}
ul li a {
display: table-cell;
height: 75px;
vertical-align: middle;
padding-left: 20px;
color: black;
width: 100%;
}
ul li a:hover{
color: black;
text-decoration: none;
}
ul li a:after {
content: "\25b6";
font-size: 10px;
position: absolute;
right: 33px;
}
ul {
display: table;
border: 1px solid lightgray;
padding-left: 0px;
width: 100%;
}
ul li {
display: table-row;
list-style: none outside none;
margin-left: 20px;
margin-right: 20px;
vertical-align: middle;
}
ul li:last-child a {
border-bottom-width: 0;
}
ul li a {
display: table-cell;
height: 75px;
vertical-align: middle;
padding-left: 20px;
border-bottom: 1px solid lightgray;
color: black;
width: 100%;
}
You can see example
try this
ul li a {
display: inline-table;
height: 75px;
vertical-align:middle;
padding-left: 20px;
color: black;
width: 100%;
line-height:75px;
}
You can try below code:
ul li a {
display: block;
height: 50px;
padding: 25px 0px 0px 20px;
color: black;
width: 100%;
}
Try this:
ul li a {
color: black;
display: inline-block; // changed
height: 75px;
line-height: 75px; // added
padding-left: 20px;
vertical-align: middle;
width: 100%;
}
Try this
ul li a {
display: table-cell;
height: 75px;
vertical-align: middle;
padding-left: 20px;
color: black;
width: 500px;
}
I replace the width of a tag 100% to that of parent (li). Then it seems to work.
You can try this
ul li a {
height: 75px;
line-height: 75px;
padding-left: 20px;
color: black;
width: 100%;
display:block;
}
Instead giving it to vertical align middle you can also use line-height for make it middle.

Can't click on links; Thinking of Overlapping (padding? margin? )

I am working on a website but I've got a problem with making the navbar. I have created a navbar but when I want to click on the left ones they aren't clickable and the right ones are.. my question is: How do I fix it I've tried different methodes but I am a noob and hope/think there's a simple solution for this that I don't know about.
Thanks anyways.
CSS:
.navlay{
background-image: url(./img/noise.png);
position: absolute;
width: 80%;
height: 7%;
margin-top: 19.4%;
margin-right:10%;
margin-left:10%;
}
.left {
position: absolute;
width: 80%;
margin-left: 8%;
margin-top: 20.3%;
text-decoration: none;
display: inline;
list-style: none;
font-size: 100%;
font-family: webbie;
font-weight: bold;
}
.right {
position: absolute;
width: 80%;
margin-top: 20.3%;
list-style: none;
text-decoration: none;
display: inline;
font-size: 100%;
font-family: webbie;
font-weight: bold;
}
.left li {
float: left;
padding-left: 3%;
padding-right: 3%;
}
.right li {
float: left;
padding-left: 3%;
padding-right: 3%;
}
.right li:first-child {
float: left;
padding-left: 80%;
padding-right: 3%;
}
.left li a {
color: #949494;
}
.right li a {
color: #949494;
}
.left li a:hover {
opacity: 0.6;
color: #949494;
cursor: pointer;
}
.right li a:hover {
opacity: 0.6;
color: #949494;
cursor: pointer;
}
Image: http://i.imgur.com/lL6MsgD.png
HTML:
<ul class="left">
<li>Home</li>
<li>About</li>
<li>Apply</li>
<li>Team-Members</li>
</ul>
<ul class="right">
<li>Login</li>
<li>Signup</li>
</ul>
You are not able to click on left because of width of right that you have set. You can try following css.
Here's Demo Fiddle
.left {
position: absolute;
width: 50%;
margin-left: 8%;
margin-top: 20.3%;
text-decoration: none;
display: inline;
list-style: none;
font-size: 100%;
font-family: webbie;
font-weight: bold;
z-index: 1;
}
.right {
position: absolute;
width: 80%;
margin-top: 20.3%;
list-style: none;
text-decoration: none;
display: inline;
font-size: 100%;
font-family: webbie;
font-weight: bold;
}
.right li:first-child {
float: left;
padding-left: 80%;
padding-right: 3%;
z-index: 2;
}

List style menu is not displaying in line

Here you can see the code: http://jsfiddle.net/LQSK3/1/
I can't get display: inline; working there for every li element.
Also got the problem width the line.png image, as it's height is the same as the font height, I want it to has 35px height with margin left and right set to 5px.
Where is the problem?
You need to update your style sheet. Please add this new style:
#menu {
position: relative;
clear: both;
top: -3px;
background-color: coral;
border: 1px solid black;
width: 800px;
height: 35px;
float:left;
}
li { display: inline;float:left; }
#menu ul {
position: absolute;
font-family: Century Gothic, sans-serif;
font-size: 14px;
list-style-type: none;
padding: 0;
margin: 9px 0 0 123px;
width: 649px;
height: 39px;
color: #FFF;
float:left;
}
a { font-weight: bold; color: red; text-decoration: none; }
a:hover { text-decoration: underline; }
#menu a {
background: url('http://i.imgur.com/rzNj0.png') top right no-repeat;
width: 65px;
height: 18px;
float: left;
margin: 0px 5px;
}
You need to add float: left; to menu div,ul,li and a . Also should set width and height and margin of the a tag.
Here is a working sample : http://jsfiddle.net/YjeBs/
Hope this helps :)
EDIT:
If you want your line to extend from top to bottom of the menu div you can change your styles to:
#menu {
position: relative;
clear: both;
top: -3px;
background-color: coral;
border: 1px solid black;
width: 800px;
height: 35px;
float:left;
}
li {
float: left;
height: 35px;
display:inline;
}
#menu ul {
color: #FFFFFF;
float: left;
font-family: Century Gothic,sans-serif;
font-size: 14px;
height: 35px;
list-style-type: none;
margin: 0 0 0 123px;
padding: 0;
position: absolute;
width: 649px;
}
a { font-weight: bold; color: red; text-decoration: none; }
a:hover { text-decoration: underline; }
#menu a {
background: url("http://i.imgur.com/rzNj0.png") no-repeat scroll right top transparent;
float: left;
height: 29px;
margin: 0 5px;
padding-top: 8px;
width: 65px;
}
Hope this is you want :)
just change li { diplay: inline; } with li { display: inline; } it works.