i have piece of code which contain an <ul> element and the <ul> element have a css property display:block by default.here is the code snippet,
ul,li{
list-style-type:none;
padding:0;
/*display:inline;*/
}
#parent{
width:100%;
/*height:50px;*/
background-color:red;
}
#child{
width:50%;
height:100%;
background-color:yellow;
}
#grand-child-1,#grand-child-2 {
width:30%;
height:100%;
float:left;
}
#grand-child-2{
background-color:green;
}
#grand-child-1{
background-color:blue;
}
<div id="parent">
<ul id="child">
<li id="grand-child-1">title 1</li>
<li id="grand-child-2">title-2</li>
<li id="grand-child-3">title-3</li>
</ul>
</div>
but when i added display:inline to the tag to remove it's default display:block property , then the width property of grand-child-1,grand-child-2 is changed.i added the snippet below.how to fix this problem?.thanks is advance.
ul,li{
list-style-type:none;
padding:0;
display:inline;
}
#parent{
width:100%;
/*height:50px;*/
background-color:red;
}
#child{
width:50%;
height:100%;
background-color:yellow;
}
#grand-child-1,#grand-child-2 {
width:30%;
height:100%;
float:left;
}
#grand-child-2{
background-color:green;
}
#grand-child-1{
background-color:blue;
}
<div id="parent">
<ul id="child">
<li id="grand-child-1">title 1</li>
<li id="grand-child-2">title-2</li>
<li id="grand-child-3">title-3</li>
</ul>
</div>
Make the li display: inline (or display: inline-block) but NOT the ul. Like this:
li {
list-style-type:none;
padding:0;
display:inline; /* or inline block */
}
The entire code:
ul {
margin: 0;
padding: 0;
}
li {
list-style-type: none;
padding: 0;
display: inline;
}
#parent {
width: 100%;
/*height:50px;*/
background-color: red;
}
#child {
width: 50%;
height: 100%;
background-color: yellow;
}
#grand-child-1,
#grand-child-2 {
width: 30%;
height: 100%;
float: left;
}
#grand-child-2 {
background-color: green;
}
#grand-child-1 {
background-color: blue;
}
<div id="parent">
<ul id="child">
<li id="grand-child-1">title 1</li>
<li id="grand-child-2">title-2</li>
<li id="grand-child-3">title-3</li>
</ul>
</div>
Related
I've created simple responsive navigation menu with media queries. I faced the weird situation. After applying text-align:center to center text in blocks, the first li element is moved slightly to left, others are centered fine. I can't figure out what's the issue. I tried margin: 0 auto, it doesn't work for me.
This is what's happening:
Here's the code:
<header>
<div class="logo">Logo</div>
<div class="menu" role="button">
<span></span>
<span></span>
<span></span>
</div>
<nav class="navigation">
<ul>
<li>home</li>
<li>blog</li>
<li>team</li>
<li>contact</li>
</ul>
</nav>
</header>
CSS:
header{
background:grey;
.logo{
font-size:40px;
color:white;
background:blue;
width:200px;
display:inline-block;
}
.menu{
display:inline-block;
float:right;
}
nav{
display:inline-block;
ul{
margin:0;
padding:0;
li{
display:inline-block;
margin: 0 20px;
background:orange;
}
}
}
}
#media screen and(max-width:600px){
header{
.menu{
display:inline-block;
height: 40px;
width: 40px;
margin:10px;
span{
border-top: 5px solid #fff;
display: block;
margin: 5px 0;
}
}
.navigation{
display:block;
ul{
margin:0;
padding:0;
text-align: center;
li{
width:100%;
display:block;
background:orange;
margin:0;
}
}
}
}
}
I am new to css my dropdown menu is hiding behind the div please help me to find out the problem. my HTML and CSS code is:
<style>
*
{
margin:0px;
padding:0px;
}
body
{
background-color:mintcream;
}
#header
{
height:260px;
width:auto;
margin:5px;
}
#headerimg
{
height: 260px;
width:100%;
}
#wrap #menu
{
width:550px;
margin:0 auto;
padding:10px;
}
#wrap
{
height:50px;
background-color:lightsalmon;
border:1px solid white;
border-radius:5px;
}
#wrap #menu ul li
{
background-color:black;
border-radius:5px;
width: 120px;
height: 30px;
line-height: 30px;
float: left;
text-align: center;
list-style-type:none;
margin-left: 3px;
}
#wrap #menu ul li a{
color:white;
text-decoration:none;
display:block;
}
#wrap #menu ul li a:hover
{
background-color:mistyrose;
color:orangered;
border-radius:5px;
}
#wrap #menu ul li ul li
{
display:none;
}
#wrap #menu ul li:hover ul li
{
display:block;
}
#content
{
width:100%;
height:500px;
background-color: teal;
margin:5px;
}
#content1
{
width:50%;
height:500px;
background-color: yellow;
float:left;
}
#content2
{
width:50%;
height:500px;
background-color:red;
float:left;
}
</style>
<body>
<div id="header">
<img id="headerimg" src="doc.jpg" />
</div>
<div id="wrap">
<div id="menu">
<ul>
<li>Home</li>
<li>About Us</li>
<li>Contact Us</li>
<li>Services
<ul>
<li>Food</li>
<li>Hospital</li>
<li>Medical</li>
</ul>
</li>
</ul>
</div>
</div>
<div id="content">
<div id="content1"> </div>
<div id="content2"> </div>
</div>
</body>
I am new to css. My dropdown menu is hiding behind the div. Please help me to find the problem.
Please add below css
ul {position: relative; z-index: 99999; }
Just add position:relative in "#wrap #menu ul li" . I think your problem was solved. If you have any other problem then put it here.
Thanks for asking.
I currently have a Header in my HTML which is a Unordered List with List Items display = inline. What I am try to accomplish is to spread each of the 5 items into an equaled space (20% Width for each) and step them centered in their respective spaces. I was able to accomplish this with a lot of ease on the Footer, but instead of List Items, I used Divs for each of the Options. Can anyone help me do the same with list? I can redo it as Divs, but I'd like to at least know how to make the list work.
How it should be
html, body {
margin:0;
padding:0;
height:100%;
}
a:link {
text-decoration:none;
}
#page {
position:relative;
background:#E9EAEE;
min-height:100%;
}
#header {
position:fixed;
left:0px;
top:0px;
z-index:1;
width:100%;
background-color:#3f5c99;
padding-top:10px;
}
#header .holder {
width:100%;
float:left;
}
#header a {
color:#ffffff;
font-size:11px;
font-weight: bold;
padding:0px 10px 0 0;
text-transform:uppercase;
}
#header li {
display:inline;
margin-left:-10px;
padding:0 4px 0 6px;
border-left: 1px solid #2F477A;
}
.logo {
border-radius:2px;
}
<body>
<div id="page">
<div id="header">
<div class="holder">
<ul>
<li style="border-left:0px;"><img class="logo" src="../img/logo.png"/></li>
<li>Comics</li>
<li><img src="../img/friendOff.png"/></li>
<li><img src="../img/mailChatOff.png"/></li>
<li><img src="../img/globeOff.png"/></li>
</ul>
</div>
</div>
...
</div>
</body>
I hope I was able to illustrate what I am trying to accomplish, but if it is still unclear please let me know. Thanks in advance for any help.
You can try like this ,I hope it will helps you.
html, body {
margin:0;
padding:0;
height:100%;
}
a:link {
text-decoration:none;
}
#page {
position:relative;
background:#E9EAEE;
min-height:100%;
}
#header {
position:fixed;
left:0px;
top:0px;
z-index:1;
width:100%;
background-color:#3f5c99;
}
#header .holder {
width:100%;
float:left;
}
#header ul {
display: table;
margin: 0;
padding: 0;
width: 100%;
}
#header a {
color: #ffffff;
display: inline-block;
font-size: 11px;
font-weight: bold;
text-transform: uppercase;
}
#header li {
display: table-cell;
padding: 5px 0;
position: relative;
text-align: center;
vertical-align: middle;
width: 20%;
}
#header li:after {
border-left: 1px solid #2f477a;
content: "";
height: 20px;
position: absolute;
right: 0;
top: 8px;
}
.logo {
border-radius:2px;
}
<body>
<div id="page">
<div id="header">
<div class="holder">
<ul>
<li style="border-left:0px;"><img class="logo" src="../img/logo.png"/></li>
<li>Comics</li>
<li><img src="../img/friendOff.png"/></li>
<li><img src="../img/mailChatOff.png"/></li>
<li><img src="../img/globeOff.png"/></li>
</ul>
</div>
</div>
...
</div>
</body>
ul {
display: flex;
}
#header li {
...
flex: 1;
display: flex;
align-items: center;
justify-content: center;
...
}
https://jsfiddle.net/234zzgn7/
Add this css. Ofcourse this is using flexbox which is something that I found to be extremely awesome. But you should investigate whether your users support it or not.
http://caniuse.com/#search=flexbox
Here try this. Changes are on #header li and #header a
html, body {
margin:0;
padding:0;
height:100%;
}
a:link {
text-decoration:none;
}
#page {
position:relative;
background:#E9EAEE;
min-height:100%;
}
#header {
position:fixed;
left:0px;
top:0px;
z-index:1;
width:100%;
background-color:#3f5c99;
padding-top:10px;
}
#header .holder {
width:100%;
float:left;
}
#header a {
color:#ffffff;
font-size:11px;
font-weight: bold;
padding:0px 10px 0 0;
text-transform:uppercase;
display:block;
width:100%;
box-sizing:border-box;
}
#header li {
display:inline-block;
box-sizing:border-box;
width:20%;
margin-left:-10px;
padding:0 4px 0 6px;
border-left: 1px solid #2F477A;
}
.logo {
border-radius:2px;
}
<body>
<div id="page">
<div id="header">
<div class="holder">
<ul>
<li style="border-left:0px;"><img class="logo" src="../img/logo.png"/></li>
<li>Comics</li>
<li><img src="../img/friendOff.png"/></li>
<li><img src="../img/mailChatOff.png"/></li>
<li><img src="../img/globeOff.png"/></li>
</ul>
</div>
</div>
...
</div>
</body>
I have a simple problem with a menu, its a 2 part menu : on the left, a traditional UL. On the right, a link contained in a div.
The right div has fixed width. The left div must take all remaining space.
I tried the overflow:hidden technique, to no avail
https://coderwall.com/p/0ph8lg/overflow-hidden-trick-to-fill-remaining-width
https://jsfiddle.net/3gfqyux4/
.container {
width:800px;
height:50px;
}
.left-menu {
background-color:red;
width:auto;
height:50px;
overflow:hidden;
}
.left-menu ul li {
display:inline;
}
.right-menu {
background-color:blue;
float:right;
width:100px;
height:50px;
}
Use calc
.container {
width:800px;
height:50px;
}
.left-menu {
background-color:red;
width:150px;
height:50px;
float:left;
}
.left-menu ul li {
display:inline;
}
.right-menu {
background-color:blue;
width:calc(100% - 150px);
height:50px;
}
Updated your fiddle: https://jsfiddle.net/3gfqyux4/3/
I assume you mean your "right" div has a fixed width (as indicated in your code) and that the left div should take up the remaining width.
flexbox can do that.
.container {
width: 80%;
height: 50px;
display: flex;
}
.left-menu {
background-color: red;
flex: 1 0 auto;
}
.left-menu ul li {
display: inline;
}
.right-menu {
background: green;
flex: 0 1 100px;
}
<div class="container">
<div class="left-menu">
<ul>
<li>menu</li>
<li>menu</li>
<li>menu</li>
</ul>
</div>
<div class="right-menu">
<a href="xyz.com">
xyz.com
</a>
</div>
</div>
JSfiddle Demo
CSS-Tricks: Complete Guide
if you don't change the order: remember display:inline-block;
.container {
width:800px;
height:50px;
}
.left-menu {
background-color:red;
width:calc(100% - 100px);
height:50px;
/*overflow:hidden;*/
display:inline-block;
}
.left-menu ul li {
display:inline;
}
.right-menu {
background-color:blue;
float:right;
width:100px;
height:50px;
display:inline-block;
}
Change an order of this two lists ;)
<div class="container">
<div class="right-menu">
<a href="xyz.com">
xyz.com
</a>
</div>
<div class="left-menu">
<ul>
<li>menu</li>
<li>menu</li>
<li>menu</li>
</ul>
</div>
https://jsfiddle.net/3gfqyux4/2/
HTML:
<div id="navbar">
<div id="container">
<ul style="height:40px">
<li><p id="navtext">Home</p></li>
</ul>
</div>
</div>
CSS:
ul {
list-style-type:none;
margin:0;
padding:0;
overflow:hidden;
}
li {
float:left;
}
#navtext {
color:#FFFFFF;
padding-bottom:-50px;
}
#navbar {
width:100%;
height:40px;
background-color:#3498db;
}
#container {
margin-right:15%;
margin-left:15%;
vertical-align: middle;
}
I would like to have the "Home" text centered within the <ul> tag that is 40px tall. I have tried looking around for an answer but nothing I try seems to work. I'm trying to make a navbar for my site.
Add in your css:
#container ul li {line-height:10px;}
http://jsfiddle.net/PWTcL/
Try:
li {
float:left;
height:100%;
display:table;
}
#navtext {
color:#FFFFFF;
padding-bottom:-50px;
display:table-cell;
vertical-align:middle;
}
Fiddle here.
If you only have a single line, use line-height: 40px, and remove margin on <p> :
ul {
list-style-type:none;
margin:0;
padding:0;
overflow:hidden;
}
li {
float:left;
line-height: 40px;
margin: 0 5px;
}
.navtext {
color:#FFFFFF;
margin: 0;
padding-bottom:-50px;
}
#navbar {
width:100%;
height:40px;
background-color:#3498db;
}
#container {
margin-right:15%;
margin-left:15%;
vertical-align: middle;
}
<div id="navbar">
<div id="container">
<ul style="height:40px">
<li><p class="navtext">Home</p></li>
<li><p class="navtext">Link</p></li>
<li><p class="navtext">Contact</p></li>
</ul>
</div>
</div>