I'm trying to create the layout shown in the image. With the help of a partial answer, the last problem seems to be "items in a column". The block is in position, however the list of items does not start from the top. And removing margin-top from the ul doesn't help. I think it is affected by the paragraph with "title" "user".
See the latest results in the fiddle https://jsfiddle.net/L0rzj4t8/2 for this HTML content.
So, how can I achieve the layout in the image?
<div id="banner" style="background:grey">
<div id="left_block" style="float:left;width:140px">
<ul style="list-style:none">
<li><img border="0" alt="a logo" style="height:60px;width:60px"></li>
<li>A logo</li>
<li><input id="find" type="text" size="12"></li>
</ul>
</div>
<div id="center_block" style="margin-left:150px;width:400px;">
<p id="center_top">
<span style="float:left">A Title</span>
<span style="float:right">user name</span>
</p>
<ul id="center_bottom" style="list-style:none; float:left; width:100%">
<li class="option">Option 1<li>
<li class="option">Option 2<li>
<li class="option">Option 3<li>
<li class="option">Option 4<li>
<li class="option">Option 5<li>
</ul>
</div>
<div id="rigth_block" style="margin-left:550px;width:150px;">
<ul id="items" style="list-style:none;padding-top:0px">
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
<li>item 4</li>
</ul>
</div>
</div>
Using display table property you can achieve this structure. Please find the below code and the demo link.
Note : your center bottom LI is not closed proper.
CSS
#banner{
background:#696969;
display: table;
margin: 0 auto;
border-spacing: 10px;
border-collapse: separate;
}
#left_block{
width:140px;
display: table-cell;
vertical-align: top;
border: 2px solid #000;
padding: 10px;
}
#left_block ul{
padding: 0;
margin: 0;
}
#center_block{
width:400px;
display: table-cell;
vertical-align: top;
border: 2px solid #000;
padding: 10px;
}
#rigth_block{
width:150px;
display: table-cell;
vertical-align: top;
border: 2px solid #000;
padding: 10px;
}
#center_bottom{
list-style:none;
width:100%;
padding: 0;
margin: 0;
display: inline-block;
text-align: center;
}
.option {
display:inline;
padding-left:4px;
padding-right:4px;
}
.clear{
clear:both;
}
#items{
list-style:none;
padding: 0;
margin: 0;
}
HTML
<div id="banner">
<div id="left_block">
<ul style="list-style:none">
<li><img border="0" alt="a logo" style="height:60px;width:60px"></li>
<li>A logo</li>
<li><input id="find" type="text" size="12"></li>
</ul>
</div>
<div id="center_block">
<p id="center_top">
<span style="float:left">A Title</span>
<span style="float:right">user name</span>
</p>
<ul id="center_bottom">
<li class="option">Option 1</li>
<li class="option">Option 2</li>
<li class="option">Option 3</li>
<li class="option">Option 4</li>
<li class="option">Option 5</li>
</ul>
</div>
<div id="rigth_block">
<ul id="items">
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
<li>item 4</li>
</ul>
</div>
</div>
DEMO
(updated the jsfiddle link to a recent version.koriander)
you can increase #center_bottom width by percentage or px
Related
In bootstrap, it is as simple as:
<ul class="list-inline">
<li>...</li>
</ul>
I'm wondering how can it be done materializecss without using <nav> ?
Alternativey, you can just copy the bootstrap style:
.list-inline {
padding-left: 0;
margin-left: -5px;
list-style: none;
}
.list-inline > li {
display: inline-block;
padding-right: 5px;
padding-left: 5px;
}
<ul class="list-inline">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
<div class="categories-container pin-top" style="top: 0px;">
<ul class="categories db">
<li class="k">All</li>
<li>Polygon</li>
<li>Big Bang</li>
<li>Sacred Geometry</li>
</ul>
</div>
here you go -> https://themes.materializecss.com/pages/demo
also you can use class .row
How do I center an unordered list that is divided with an image inside?
I want to achieve that the unordered list is one row, centered and also the image inside is centered so that the image divides the rest of the list in two halves (topnav-left and topnav-right).
My HTML:
<ul class="nav">
<div class="topnav-left">
<li class="">
<a class="toggle-nav" data-no-turbolink="true" href="Women">Women</a>
</li>
<li class="">
<a class="toggle-nav" data-no-turbolink="true" href="Men">Men</a>
</li>
<li class="">
Stores
</li>
<li class="">
Lifestyle
</li>
</div>
<div class="nile-logo" style="">
<li>
<img alt="Logo" src="http://img.logospectrum.com/dec/dummy-logo.jpg">
</li>
</div>
<div class="topnav-right">
<li class="">
<a class="toggle-account-nav" data-no-turbolink="true" href="/de/account">My Account</a>
</li>
<li>
<div class="cart">
<a href="/de/cart">
Warenkorb
</a> </div>
</li>
<li>
<a html="{:class=>"open-wishlist"}" href="/de/wishlist">WUNSCHLISTE</a>
</li>
<li class="language">
<a class="language" href="/en/pages/imprint">EN</a>
<a class="language" href="/fr/pages/imprint">FR</a>
</li>
</div>
</ul>
My CSS:
ul.nav { text-align: center; }
ul.nav li { display: inline-block; }
Here a codepen: demo
Try to use display:flex; add this to add this,
ul {display:flex;justify-content: space-around;list-style-type: none;}
ul.nav li { flex:1; text-align: center; } /* Edit from comment by Paulie_D
Working DEMO
You mean like this?:
http://codepen.io/anon/pen/pENYLZ
ul.nav li {
display: block;
}
Or like this?:
http://codepen.io/anon/pen/mAOoKN
ul.nav {
margin: 0 auto;
width: 200px;
position: relative;
}
ul.nav li {
display: block;
}
this code below works fine if I have 1 collapsable sidemenu item, but when I add another the upper item doesn't work right. It's all badly highlighted.
The bottom one works still fine. What's wrong here thanks. Here is bootply:
http://www.bootply.com/IABXgPMp5S
<div class="container body-content">
<div class="row row-offcanvas row-offcanvas-left">
<!-- sidebar -->
<div class="col-xs-6 col-sm-3 sidebar-offcanvas" id="sidebar" role="navigation">
<ul class="nav">
<li>
Sector One
<ul class="nav collapse pull-right" id="sub1">
<li>List 1</li>
<li>List 2</li>
</ul>
</li>
<li>
Sector Two
<ul class="nav collapse pull-right" id="sub2">
<li>List 1</li>
<li>List 2</li>
</ul>
</li>
</ul>
</div>
</div><!--/.row-->
</div><!--/.container-->
and css file:
body {
padding-top: 51px;
}
.text-center {
padding-top: 20px;
}
.col-xs-12 {
background-color: #fff;
}
#sidebar {
height: 100%;
padding-right: 0;
padding-top: 20px;
}
#sidebar .nav {
width: 95%;
}
#sidebar li {
border:0 #f2f2f2 solid;
border-bottom-width:1px;
}
/* collapsed sidebar styles */
#media screen and (max-width: 767px) {
.row-offcanvas {
position: relative;
-webkit-transition: all 0.25s ease-out;
-moz-transition: all 0.25s ease-out;
transition: all 0.25s ease-out;
}
.row-offcanvas-right
.sidebar-offcanvas {
right: -41.6%;
}
.row-offcanvas-left
.sidebar-offcanvas {
left: -41.6%;
}
.row-offcanvas-right.active {
right: 41.6%;
}
.row-offcanvas-left.active {
left: 41.6%;
}
.sidebar-offcanvas {
position: absolute;
top: 0;
width: 41.6%;
}
#sidebar {
padding-top:0;
}
}
You are not closing the first "ul" before starting the second one, so bootstrap thinks you have one big unordered list.
here is a link to the fix and here:
<div class="container body-content">
<div class="row row-offcanvas row-offcanvas-left">
<!-- sidebar -->
<div class="col-xs-6 col-sm-3 sidebar-offcanvas" id="sidebar" role="navigation">
<ul class="nav">
<li>
Sector One <span class="glyphicon glyphicon-arrow-down pull-right"></span>
<ul class="nav collapse pull-right" id="sub1">
<li>List 1</li>
<li>List 2</li>
</ul>
</li>
</ul>
<ul class="nav">
<li>
Sector Two <span class="glyphicon glyphicon-arrow-down pull-right"></span>
<ul class="nav collapse pull-right" id="sub2">
<li>List 1</li>
<li>List 2</li>
</ul>
</li>
</ul>
</div>
</div><!--/.row-->
</div><!--/.container-->
is the corrected html
I am creating a topmenu for a webpage, and with scripting, the sub menus pops up on hover. I have also taken measures to not let the menu grow too far to the right, by if needed let it grow in the other direction. This picture clarifies:
I do this by adding the class "to-the-left" to the sub sub menu.
Now, why is some menu items of the parent on top of my sub sub menu? You can read "Item 3" below "Sub sub item 2" which should not be possible.
I have tried to add z-index to the sub sub menu without succeeding.
http://jsfiddle.net/VK7Mt/
<!doctype html>
<html>
<head>
<style type="text/css">
div.top-menu
{
width: 920px;
margin: 0 auto;
}
div.top-menu ul.topmenu
{
margin: 0;
height: 41px;
background: #ccc;
padding: 0;
position: relative;
}
ul.topmenu li
{
list-style: none;
float: left;
padding: 12px 19px;
min-height: 17px;
position: relative;
}
ul.topmenu ul
{
width: 190px;
position: absolute;
top: 41px;
left: 0;
margin: 0;
padding: 0;
background: #dddddd;
border: #c4c4c4 1px solid;
}
ul.topmenu ul li
{
float: none;
padding: 3px 6px 3px 13px;
}
ul.topmenu a
{
color: #333;
text-decoration: none;
}
ul.topmenu ul li a
{
display: inline-block;
font-weight: normal;
width: 90%;
}
ul.topmenu ul li:hover
{
background: #3399cc;
}
ul.topmenu ul ul
{
left: 100%;
top: 0;
}
ul.topmenu div
{
cursor: pointer;
}
.topmenu-sub-item > .item
{
padding-left: 6px;
}
.topmenu-sub-item > .item > a
{
margin-top: 3px;
margin-bottom: 3px;
}
ul.topmenu ul ul.to-the-left
{
left: -100.5%;
}
</style>
</head>
<body>
<div class="top-menu">
<ul class="topmenu">
<li class="topmenu-root-node">
root item
<ul class="topmenu-submenu-container">
<li class="topmenu-sub-item">
<div class="item">
item 1
</div>
</li>
<li class="topmenu-sub-item nonempty">
<div class="item has-submenu">
<a class="topmenu-hassubmenu" href="/item2">item 2</a>
</div>
<ul class="topmenu-submenu-container to-the-right">
<li class="topmenu-sub-item nonempty">
<div class="item has-submenu">
<a class="topmenu-hassubmenu" href="/subitem1">Sub item 1</a>
</div>
<ul class="topmenu-submenu-container to-the-right">
<li class="topmenu-sub-item nonempty">
<div class="item has-submenu">
<a class="topmenu-hassubmenu" href="/subsubitem1">Sub sub item 1</a>
</div>
</li>
<li class="topmenu-sub-item">
<div class="item">
Sub sub item 2
</div>
</li>
<li class="topmenu-sub-item">
<div class="item">
Sub sub item 3
</div>
</li>
</ul>
</li>
</ul>
</li>
<li class="topmenu-sub-item">
<div class="item">
Item 3
</div>
</li>
</ul>
</li>
</ul>
</div>
<div class="top-menu" style="margin-top: 170px">
<ul class="topmenu">
<li class="topmenu-root-node">
root item
<ul class="topmenu-submenu-container">
<li class="topmenu-sub-item">
<div class="item">
item 1
</div>
</li>
<li class="topmenu-sub-item nonempty">
<div class="item has-submenu">
<a class="topmenu-hassubmenu" href="/item2">item 2</a>
</div>
<ul class="topmenu-submenu-container to-the-right">
<li class="topmenu-sub-item nonempty">
<div class="item has-submenu">
<a class="topmenu-hassubmenu" href="/subitem1">Sub item 1</a>
</div>
<ul class="topmenu-submenu-container to-the-left">
<li class="topmenu-sub-item nonempty">
<div class="item has-submenu">
<a class="topmenu-hassubmenu" href="/subsubitem1">Sub sub item 1</a>
</div>
</li>
<li class="topmenu-sub-item">
<div class="item">
Sub sub item 2
</div>
</li>
<li class="topmenu-sub-item">
<div class="item">
Sub sub item 3
</div>
</li>
</ul>
</li>
</ul>
</li>
<li class="topmenu-sub-item">
<div class="item">
Item 3
</div>
</li>
</ul>
</li>
</ul>
</div>
</body>
</html>
This is because the order of the elements matters: elements that come later in code, are on top of the previous elements.
In your case, the subsubs are a part of the main Item 2 >> are BELOW the afterwards following Item 3.
You can override this using z-index for the sub-menu (not the subsub):
ul.topmenu ul {
...
position:absolute;
z-index:999;
...
}
updated fiddle: http://jsfiddle.net/VK7Mt/3/
Add z-index to:
ul.topmenu ul ul.to-the-left {
z-index: 100;
}
That way you are saying that you want that ul to be in front of other elements. It had position absolute so it needed some z-index.
JSFIDDLE
<div id="header">
</div>
<div id="nav_cont">
<ul id="nav">
<li id="main_btn"><a class="mainlink" href="#">Parent 01</a></li>
<li id="communities_btn"><a class="mainlink" href="#" class="selected">Parent 02</a>
<ul>
<li>Item 01</li>
<li>Item 02</li>
<li>Item 03</li>
</ul>
<div class="clear"></div>
</li>
<li id="occupancy_btn"><a class="mainlink" href="#">Parent 03</a>
<ul>
<li>Item 04</li>
<li>Item 05</li>
<li>Item 06</li>
<li>Item 07</li>
</ul>
<div class="clear"></div>
</li>
<li id="resources_btn"><a class="mainlink" href="#">Parent 04</a></li>
<li id="about_btn"><a class="mainlink" href="#">Parent 04</a></li>
<li id="newsletter_btn"><a class="mainlink" href="#">Parent 04</a></li>
<li id="contact_btn"><a class="mainlink" href="#">Parent 04</a></li>
</ul>
<div class="clear"></div>
</div>
<div id="content">
</div>
#header{
border: 0px solid;
width:1024px;
margin: 0 auto;
}
#content{
border: 1px solid;
width:1024px;
height:400px;
margin: 0 auto;
}
#nav_cont{
position: absolute;
top:20px;
border:1px solid;
width:1024px;
left:50%;
margin-left:-512px;
}
I'll try to explain the best I can. I have a header div tag that holds the logo. Next, I have the nav_cont that is a menu with hidden drop down menus. Lastly, the rest of the content is in the content div tags.
I've aligned the menu to appear to the user that it is level and within by centering it using absolute, thus not pushing content down when the dropdowns appear.
However when I shrink the browser the nav_cont continues to move off screen even though header and content have stopped. If I use relative or just margin: 0 auto; it minimizes fine, but again my problem is that it pushes the content down when the dropdowns are shown.
I hope im making sense. Thanks.
Try setting position:absolute to inner dropdowns, so when you show them does not push content down