I don't understand why vertical-align: middle makes an icon not being centered, but a little lower.
HTML:
<ul class="operatorscreen__buttons">
<li class="operatorscreen__single-button">
<a class="operatorscreen__link button-link button-block button-link_outline" href="#">First icon</a>
</li>
<li class="operatorscreen__single-button">
<a class="operatorscreen__link button-link button-block button-link_outline" href="#">Second</a>
</li>
</ul>
scss:
.operatorscreen {
&__single-button {
&:first-child {
margin-bottom: 10px;
}
}
&__link {
color: black;
text-decoration: none;
font-size: 18px;
&:before {
content: "";
display: inline-block;
width: 16px;
height: 20px;
font-size: 100px;
margin-right: 12px;
vertical-align: middle;
background-color: red;
}
}
}
As you can see, a red background is little lower than text, though it should be right in the center vertically.
Try it:
li:not(:last-child) {
margin-bottom: 10px;
}
li::before {
content: '';
width: 16px;
height: 20px;
display: inline-block;
vertical-align: sub;
background-color: red;
}
<ul>
<li>First icon</li>
<li>Second icon</li>
</ul>
When I use a ruler to measure, it looks like vertical-align: middle is behaving correctly: it is in the middle of the lower case letters.
If you want it to be "perfect" then you may need to be more precise. There are many ideas, one quick one being:
position: relative;
top: -1px; // adjust to your desire
More on vertical-align of inline elements here: https://css-tricks.com/almanac/properties/v/vertical-align/
It's actually in the middle but you need to know what is the middle.
Aligns the middle of the element with the baseline plus half the x-height of the parent.ref
Here is an illustration to show the middle of the element aligned with the baseline plus half the x-height.
.operatorscreen__single-button:first-child {
margin-bottom: 10px;
}
.operatorscreen__link {
color: black;
text-decoration: none;
font-size: 18px;
background:
/*plus half x-height*/
linear-gradient(green,green) 0 calc(16px - 0.5ex)/100% 1px no-repeat,
/*the baseline*/
linear-gradient(#000,#000)0 16px/100% 1px no-repeat;
}
.operatorscreen__link:before {
content: "";
display: inline-block;
width: 16px;
height: 20px;
font-size: 100px;
margin-right: 12px;
vertical-align: middle;
background:
linear-gradient(#000,#000) center/100% 1px no-repeat;
background-color: red;
}
<ul class="operatorscreen__buttons">
<li class="operatorscreen__single-button">
<a class="operatorscreen__link button-link button-block button-link_outline" href="#">First icon</a>
</li>
<li class="operatorscreen__single-button">
<a class="operatorscreen__link button-link button-block button-link_outline" href="#">Second</a>
</li>
</ul>
In your particular case, use top (or text-top, text-bottom, sub) instead of middle and you will be closer to the middle you expect:
.operatorscreen__single-button:first-child {
margin-bottom: 10px;
}
.operatorscreen__link {
color: black;
text-decoration: none;
font-size: 18px;
background: linear-gradient(#000,#000)center/100% 1px no-repeat;
}
.operatorscreen__link:before {
content: "";
display: inline-block;
width: 16px;
height: 20px;
font-size: 100px;
margin-right: 12px;
vertical-align: top;
background:linear-gradient(#000,#000) center/100% 1px no-repeat;
background-color: red;
}
<ul class="operatorscreen__buttons">
<li class="operatorscreen__single-button">
<a class="operatorscreen__link button-link button-block button-link_outline" href="#">First icon</a>
</li>
<li class="operatorscreen__single-button">
<a class="operatorscreen__link button-link button-block button-link_outline" href="#">Second</a>
</li>
</ul>
Related
this might be an easy one.
This is how my pure css menu currently looks like:
html, body {
margin:0;
padding: 0;
font-family: arial;
}
/* Menu */
.menu__wrapper {
background: #fff;
z-index: 8000;
min-height: 30px;
box-shadow: 0px 1px 5px 0px rgba(0,0,0,0.75);
}
/* The dropdown container */
.dropdown {
float: left;
overflow: hidden;
}
/* Main links */
.menu__mainlink {
cursor: pointer;
border: none;
color: $dark-color;
padding: 5px 16px;
display: inline-block;
}
/* Sublinks */
.menu__sublink {
font-size: 16px;
padding: 5px 16px;
text-decoration: none;
display: block;
}
.menu__mainlink, .menu__sublink:hover {
color: red;
text-decoration: none;
}
/* Dropdown content (hidden by default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #fff;
width: 100%;
left: 0;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
/* Sticky header */
.menu__wrapper.sticky {
position: fixed;
background-color: #fff;
width: 100%;
top: 0px;
}
/* Dropdown button */
.sticky .dropdown .dropbtn, .sticky a {
color: #000;
}
<div class="menu__wrapper padding-left-large sticky">
<div class="dropdown no-padding-left">
<a class="menu__mainlink" href="#">Main</a>
<i class="fa fa-caret-down"></i>
<div class="dropdown-content">
<a class="menu__sublink" href="#">Information</a>
<a class="menu__sublink" href="#">Archiv</a>
<a class="menu__sublink" href="#">Kontakt</a>
<a class="menu__sublink" href="#">Impressum</a></div>
</div>
<div class="dropdown no-padding-left">
<a class="menu__mainlink" href="#">Program</a>
<i class="fa fa-caret-down"></i>
<div class="dropdown-content show">
<a class="menu__sublink" href="#">This</a>
<a class="menu__sublink" href="#">That</a>
<a class="menu__sublink" href="#">Really_long_menu_item</a>
<a class="menu__sublink" href="#">Calendar</a></div>
</div>
<div class="dropdown no-padding-left">
<a class="menu__mainlink" href="#">Found</a>
<i class="fa fa-caret-down"></i>
<div class="dropdown-content">
<a class="menu__sublink" href="#">Videos</a>
<a class="menu__sublink" href="#">Image</a>
<a class="menu__sublink" href="#">Sound</a>
<a class="menu__sublink" href="#">Text</a>
</div>
</div>
</div>
Pen: https://codepen.io/t-book/pen/yLNwRba?editors=1100
Question 1: How can I color red the parent menu item like "main" when hovering over its subitems (like Archiv or Kontakt)?
Question 2: How could I push the absolute positioned submenu left to align it under its parent? The moment I position the submenu relative it will keep the x of its parent but unfortunately, in case of really long submenu names, it pushes the next floated parent item right.
Answer 1:
.dropdown:hover> a{color:red;}
Answer 2:
remove overflow:hidden; to .dropdown
add position:relative; to .dropdown
remove width: 100%; from .dropdown-content
I am having trouble with using margin-left with safari
here's my css
<style>
.profile___options {
position: absolute; width: 828px; height: 45px; border-top: 1.1px solid #eee; margin-top: 97px; margin-left: 282px;
}
.profile___options ul {
float: right;
margin-right: 329px;
}
.profile___options ul li {
border-right: 1px solid #e9eaed;
float: left;
font-size: 15px;
font-weight: 600;
height: 43px;
position: relative;
list-style: none;
vertical-align: middle;
white-space: nowrap;
cursor: pointer;
padding: 16px;
color: #365899;
padding: -1px;
}
</style>
and here's my html code
<div class="profile___options">
<div class="fsaafFDSA__">
<div class="223__adAas">
<div class="profile___options_inner">
<ul class="user_ul">
<li>
<a class="questions_link">Questions</a>
</li>
<div class="user_bookmark" style="
position: absolute;
margin-left: -121px;">
</div>
<li style="width: 136px;" class="followerLink">
<!--<span class="badge badge-danger" style="color: #fff;background-color: #dc3545;width: 19px;margin-top: 5px;position: absolute;margin-left: -7px;">3</span>-->
Followers
</li>
<li style="width: 136px;" class="followingLink">
<!--<span class="badge badge-danger" style="color: #fff;background-color: #dc3545;width: 19px;margin-top: 5px;position: absolute;margin-left: -7px;">3</span>-->
Following
</li>
</ul>
</div>
</div>
</div>
</div>
and here's the result on chrome
result on chrome
and here's the result on safari
Result on safari
what I am trying to accomplish is to keep the bottom navbar with the black outline to be aligned at the same place on both browsers
Thanks,
Arnav
Try this:
-webkit-margin-start (left)
-webkit-margin-end (right)
https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariCSSRef/Articles/StandardCSSProperties.html
Hope I helped.
When the menu "product" is clicked or mouse over, the another list of menus appear.. but the image block which is below the menu bar, moves away from the position. if i use css [ position:absolute;], then the image box remains static and the product's sub-menu overlaps the image block, which is what i wanted. but the image blocks width & height settings change drastically, thereby spoiling the alignment.
pls chk the codings in jsFiddle
.home_menu {
border: 1px solid black;
width: 98%;
height: 3.3%;
margin-right: auto;
margin-left: auto;
}
div#menuDemo {
clear: both;
//border:1px solid black;
height: 78%;
width: 100%;
position: relative;
left: 0;
top: 0;
background-color: #A55927;
/*Remove this next one in production - Used for demo purpose only*/
margin-bottom: 0.1%;
padding-top: 0.7%;
z-index: 4;
}
div#menuDemo ul {
list-style: none;
margin: 0;
padding: 0;
background-color: #A55927;
}
div#menuDemo > ul > li {
float: left;
text-align: center;
}
div#menuDemo ul li {
width: 25%;
//border: 5px solid purple;
}
div#menuDemo ul li a {
text-decoration: none;
font-weight: bolder;
text-align: center;
}
div#menuDemo > ul > li > ul {
display: none;
text-align: center;
}
div#menuDemo > ul > li:hover > ul {
display: block;
text-align: center;
}
.sub1 {
width: 100%;
//border:1px solid green;
}
.colouring {
color: black;
font-weight: bolder;
}
.colour {
//border:1px solid blue;
color: black;
text-align: center;
//width:100%;
}
.wrapper {
border: 5px solid pink;
width: 98.8%;
height: 82%;
margin-top: 1%;
z-index: 2;
}
.uniform_block {
border: 5px solid green;
width: 100%;
height: 40%;
cursor: pointer;
}
.uniform_block img {
width: 100%;
height: 100%;
}
<body>
<div class="home_menu">
<div id="menuDemo">
<ul>
<li id="homeMenu">About Us
</li>
<!-- <li >About Us</li> -->
<li>Products
<ul class="sub1">
<li> Uniforms
<ul>
<li>  
</li>
<li> Automobile Industry Uniforms
</li>
<li> Pharmaceutical Uniforms
</li>
<li> Food Industry Uniforms
</li>
<li> Government Sector Uniforms
</li>
<li> School/College Uniforms
</li>
<li>  
</li>
</ul>
</li>
<li>Shoes
<ul>
<li>  
</li>
<li> Industrial Shoes
</li>
<li> Safety & Security Shoes
</li>
<li> Executive Shoes
</li>
<li>  
</li>
</ul>
</li>
</ul>
</li>
<li>Contact Us
</li>
</ul>
</div>
</div>
<div class="wrapper">
<div class="uniform_block">
<img src=" http://t0.gstatic.com/images?q=tbn:ANd9GcSH-kRi3rkVciPcH_c6dDJJI6C1ntzwcKl9MoVQIyuKk8F7unpf" />
</div>
<div class="home_footer">
<div class="footer_contents"></div>
</div>
</div>
</body>
kindly help. My requirement is, when i mouse over the "product menu", the drop down menu should be viewed above the image block which is below the menu bar.
Add position:absolute to the css of your ul menu (in your case, the sub1 class), and remove the width:100% so it can inherit the default width of its parent. Absolute positioning will prevent your browser from trying to put your ul element after the previous element on the page.
ul.sub1 {
position:absolute;
}
http://jsfiddle.net/C2YXp/2/
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I am newbie in css and javasript ,
I use default twitter bootsrap navbar drop down, I want my navbar content to occupy the full width of the entire space of navbar,
I use the example at http://twitter.github.com/bootstrap/examples/justified-nav.html
but doesnt work
here is my html code
<div class="row-fluid">
<div class="span12">
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<ul class="nav">
<li>About</li>
<li class="divider-vertical"></li>
<li class="span3">Portfolio</li>
<li class="divider-vertical"></li>
<li>Contact</li>
<li class="divider-vertical"></li>
</ul>
<ul class="nav">
<li class="dropdown">
<a href="#"
class="dropdown-toggle"
data-toggle="dropdown">
Services
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li>Web Design</li>
<li>Web development</li>
<li>Wordpress Theme development</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
please help
DEMO
Modified CSS:
body {
padding-top: 20px;
padding-bottom: 60px;
}
/* Custom container */
.container {
margin: 0 auto;
max-width: 1000px;
}
.container > hr {
margin: 60px 0;
}
/* Main marketing message and sign up button */
.jumbotron {
margin: 80px 0;
text-align: center;
}
.jumbotron h1 {
font-size: 100px;
line-height: 1;
}
.jumbotron .lead {
font-size: 24px;
line-height: 1.25;
}
.jumbotron .btn {
font-size: 21px;
padding: 14px 24px;
}
/* Supporting marketing content */
.marketing {
margin: 60px 0;
}
.marketing p + h4 {
margin-top: 28px;
}
/* Customize the navbar links to be fill the entire space of the .navbar */
.navbar .navbar-inner {
padding: 0;
}
.navbar .nav {
margin: 0;
display: table;
width: 100%;
}
.navbar .nav li {
display: table-cell;
width: 1%;
float: none;
}
.navbar .nav li a {
font-weight: bold;
text-align: center;
border-left: 1px solid rgba(255,255,255,.75);
border-right: 1px solid rgba(0,0,0,.1);
}
.navbar .nav li:first-child a {
border-left: 0;
border-radius: 3px 0 0 3px;
}
.navbar .nav li:last-child a {
border-right: 0;
border-radius: 0 3px 3px 0;
}
It would appear that I am suffering from a new bug in IE7, as I can't seem to find any reference to it anywhere else. It is best explained using screenshots, so here are a couple of links (and as a note, it's not a requirement for it to work in IE6, so I don't even want to know what it looks like under that!):
How it should be displayed (using Safari 4):
http://dl-client.getdropbox.com/u/45961/safari4.png
How IE7 is displaying it:
http://dl-client.getdropbox.com/u/45961/ie7.png
Here's the CSS for that menu chunk:
#mm #leftNav .navigation {
width: 100%;
margin-bottom: 0;
float: left;
}
#mm #leftNav li {
list-style: none;
display: inline;
margin: 0;
}
#mm #leftNav .navigation li ul {
display: none;
}
#mm #leftNav .navigation li a {
text-decoration: none;
color: #ffffff;
font-size: 11pt;
padding-left: 20px;
}
#mm #leftNav .navigation li {
cursor: pointer;
margin-right: 4px;
padding-left: 8px;
padding-right: 8px;
padding-top: 10px;
padding-bottom: 8px;
overflow: visible;
}
.menu_item {
background: #419185;
}
.menu_item:hover {
background: #48a093;
}
.currentcat {
background-color: #4aa8a6;
}
.currentcat:hover {
background: #4aa8a6;
}
And here is the HTML:
<div id="mm">
<div id="leftNav">
<ul class="navigation">
<li class="menu_item">
<a class="icon icon-base">Base</a>
</li>
<li class="menu_item">
<a class="icon icon-devices">Devices</a>
</li>
<li class="menu_item">
<a class="icon icon-management">Management</a>
</li>
<li class="menu_item">
<a class="icon icon-iptools">IP Tools</a>
</li>
<li class="menu_item">
<a class="icon icon-config">Configuration</a>
</li>
<li class="menu_item">
<a class="icon icon-admin">Administration</a>
</li>
</ul>
<div id="subnav"></div>
</div>
</div>
Any ideas?
top and bottom padding are not supported on inline elements (some browsers will render it, others won't)
Here's a good article on the problem:
http://www.maxdesign.com.au/presentation/inline/
If you really need correct padding, you should change the menu items to "display:block" and "float:left"
Hehe, activa beat me to it.
Indeed, move your margin/padding to the A element, kinda like so:
mm #leftNav .navigation li a {
text-decoration: none;
color: #ffffff;
font-size: 11pt;
display:block;
float:left;
background: #419185;
margin-right: 4px;
padding-left: 20px;
padding-right: 8px;
padding-top: 10px;
padding-bottom: 8px;
}
mm #leftNav .navigation li {
cursor: pointer;
}
.menu_item {
}