How to make table by CSS? - html

I try to use CSS display:table instead HTML table tags.
My HTML:
<div class="c_result">
<div class="rp-row">
<ul class="rp-first">
<li>London</li>
</ul>
<ul class="rp-second">
<li>Male</li>
<li>Female</li>
</ul>
<ul class="rp-result">
<li>result1</li>
<li>result2</li>
<li>result3</li>
</ul>
</div>
<div class="rp-row">
<ul class="rp-first">
<li>Paris</li>
</ul>
<ul class="rp-second">
<li>Male</li>
<li>Female</li>
</ul>
<ul class="rp-result">
<li>result4</li>
<li>result5</li>
<li>result6</li>
</ul>
</div>
</div>
My CSS:
.c_result {
border: 1px solid red;
display: table;
width: 100%;
}
.c_result .rp-row {
display: table-row;
border: 1px solid #000;
}
.c_result ul {
display: table-row;
}
.c_result .rp-row li {
display: table-row;
}
The result:
But my desired result is :
The border styles didn't apply too and when I try to use border it doesn't appear in the result , How can I do that ?
Best regards.

Is this already looking better ??
edit: colspan & rowspan not possible in css or with a trick
.c_result {
border: 1px solid red;
display: table;
width: 100%;
}
.rp-row {
display: table-row;
}
.cell {
display: table-cell;
}
<div class="c_result">
<div class="rp-row">
<ul class="cell rp-first">
<li>London</li>
</ul>
<ul class="cell rp-second">
<li>Male</li>
<li>Female</li>
</ul>
<ul class="cell rp-result">
<li>result1</li>
<li>result2</li>
<li>result3</li>
</ul>
</div>
<div class="rp-row">
<ul class="rp-first">
<li>Paris</li>
</ul>
<ul class="cell rp-second">
<li>Male</li>
<li>Female</li>
</ul>
<ul class="cell rp-result">
<li>result4</li>
<li>result5</li>
<li>result6</li>
</ul>
</div>
</div>
Edit:
.c_result {
width: 600px;
/* total width */
}
.c_result * {
display: block;
/* remove list items and so..*/
text-align: center;
/*center text*/
padding: 0;
/* reset */
margin: 0;
/* reset */
}
li {
outline: 1px solid black;
/*border is calculated in element width, outline not.*/
}
.rp-row > * {
float: right; /*floats bases to right*/
}
.rp-first {
width: 12.5%;
/* 1/8 width */
}
.rp-first li {
line-height: 198px;
/* base = floor ( 200 / 3 (max split) ) * 3 (max split) = 198 */
}
.rp-second {
width: 25%;
/* 2/8 width */
}
.rp-second li {
line-height: 99px;
/* base / 2 = 99; */
}
.rp-result {
width: 62.5%;
/* 6/8 width */
}
.rp-result li {
line-height: 66px;
/* base / 3 = 66; */
}
<div class="c_result">
<div class="rp-row">
<ul class="rp-first">
<li>London</li>
</ul>
<ul class="rp-second">
<li>Male</li>
<li>Female</li>
</ul>
<ul class="rp-result">
<li>result1</li>
<li>result2</li>
<li>result3</li>
</ul>
</div>
<div class="rp-row">
<ul class="rp-first">
<li>Paris</li>
</ul>
<ul class="rp-second">
<li>Male</li>
<li>Female</li>
</ul>
<ul class="rp-result">
<li>result4</li>
<li>result5</li>
<li>result6</li>
</ul>
</div>
</div>

Related

How i can bring second "navbar" div inline with first "navbar" div?

I am try to put the div nav2 on the same line as nav 1 but it just not going up what is the problem i even try float but it not working also
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
width: 100%;
height: 100vh;
}
#navbar {
position: fixed;
width: 100%;
display:
}
#navbar ul {
list-style: none;
}
#navbar ul li {
display: inline-block;
padding: 10px 5px 0px 20px;
}
#nav2 {
float: right;
}
<div id="main">
<div id="navbar">
<div id="nav1">
<ul>
<li>How it works</li>
<li>Why Company?</li>
<li>Pricing</li>
<li>About us</li>
<li>Resource center</li>
</ul>
</div>
<div id="nav2">
<ul>
<li>Get stated</li>
<li>Log in</li>
</ul>
</div>
</div>
<div id="head">
<div>
<h3>Company</h3>
</div>
<div>
<h1>Invert Like a idiot</h1>
</div>
<div>
<p>because money is lame</p>
</div>
</div>
</div>
I expect that Both "nav1" and "nav2" on the name line just like normal navbar but i want "nav2" on the right side that why i make it div "nav2"
This is probably what you want to do :
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body, html {
width: 100%;
height: 100vh;
}
#navbar {
position: fixed;
width: 100%;
display: grid;
grid-template-columns: auto auto;
height: 50px;
}
#nav1 ul, #nav2 ul {
display: grid;
grid-gap: 20px;
grid-auto-columns: minmax(min-contant, max-content);
grid-auto-flow: column;
height: 100%;
align-items: center;
list-style: none;
}
#nav1 ul {
padding-left: 20px;
justify-content: left;
}
#nav2 ul {
padding-right: 20px;
justify-content: right;
}
#head {
padding: 50px 20px 0 20px;
}
<html>
<head></head>
<body>
<div id="main">
<div id="navbar">
<div id="nav1">
<ul>
<li>How it works</li>
<li>Why Company?</li>
<li>Pricing</li>
<li>About us</li>
<li>Resource center</li>
</ul>
</div>
<div id="nav2">
<ul>
<li>Get stated</li>
<li>Log in</li>
</ul>
</div>
</div>
</div>
</body>
</html>

How to work with float left right and vertical align middle?

I need to align logo to left and navigation to right and the text in logo and navigation must be aligned bottom of the logo-nav div.
Note: Without flex box
.logo {
float: left;
}
.navigation {
float: right;
}
.clear {
clear: both;
}
<div class="logo-nav">
<div class="logo">Partners</div>
<div class="navigation">
<ul class="nav-ul">
<li class="nav-li">OUR SPIRIT</li>
<li class="nav-li">OUR OFFER</li>
<li class="nav-li">OUR VISIONARY</li>
<li class="nav-li">CONTACT</li>
</ul>
</div>
<div class="clear"></div>
</div>
You can use Flexbox for this. You just need to set margin-left: auto on navigation and align-items: flex-end for vertical-align.
.logo img {
vertical-align: top;
}
.logo-nav, .nav-ul {
display: flex;
align-items: flex-end;
list-style: none;
margin: 0;
}
.navigation {
margin-left: auto;
}
<div class="logo-nav">
<div class="logo"><img src="http://placehold.it/100x50"></div>
<div class="navigation">
<ul class="nav-ul">
<li class="nav-li">OUR SPIRIT</li>
<li class="nav-li">OUR OFFER</li>
<li class="nav-li">OUR VISIONARY</li>
<li class="nav-li">CONTACT</li>
</ul>
</div>
<div class="clear"></div>
</div>
You can also use CSS tables.
.logo img {
vertical-align: top;
}
.logo-nav {
display: table;
width: 100%;
border-bottom: 1px solid black;
}
ul {
margin: 0;
}
.logo,
.navigation {
display: table-cell;
vertical-align: bottom;
}
.navigation {
text-align: right;
}
li {
display: inline-block;
}
<div class="logo-nav">
<div class="logo">
<img src="http://placehold.it/100x50">
</div>
<div class="navigation">
<ul class="nav-ul">
<li class="nav-li">OUR SPIRIT</li>
<li class="nav-li">OUR OFFER</li>
<li class="nav-li">OUR VISIONARY</li>
<li class="nav-li">CONTACT</li>
</ul>
</div>
<div class="clear"></div>
</div>
.logo-nav{
height:40px;
border-bottom:1px solid black;
width:100%;
margin:0;
padding:0;
}
.navigation{
float:right;
margin:0;
padding:0;
height:100%;
}
.navigation ul{
margin:0;
padding:0;
height:100%;
}
.navigation ul li{
margin:0;
padding:0;
float:left;
margin:0 5px;
list-style-type:none;
display:flex;
align-items:flex-end;
height:100%;
}
.logo{
float:left;
margin:0;
padding:0;
height:100%;
display:flex;
align-items:flex-end;
}
<div class="logo-nav">
<div class="logo">+CoPartners</div>
<div class="navigation">
<ul class="nav-ul">
<li class="nav-li">OUR SPIRIT</li>
<li class="nav-li">OUR OFFER</li>
<li class="nav-li">OUR VISIONARY</li>
<li class="nav-li">CONTACT</li>
</ul>
</div>
<div class="clear"></div>
</div>
Add the following css
.nav-ul li{float:left; list-style:none;padding:0 5px;}
.nav-ul{padding:0;margin:0;}
Since this is not possible with floats, you can use display: inline-block instead. It works like a poor man's flex.
.logo-nav {
text-align: justify;
}
.logo-nav::after {
/* you can omit this by using `text-align-last` */
content: '';
width: 100%;
display: inline-block;
}
.logo {
display: inline-block;
vertical-align: middle;
text-align: left;
width: 50%;
}
.navigation {
display: inline-block;
vertical-align: bottom;
text-align: right;
width: 50%;
}
.clear {
/* this element is obsolete now */
}
Note: there must be no space between .logoand .navigation in your markup.
Are you allowed to use position absolute?
li{
float: left;
padding: 0 5px;
}
ul{
list-style: none;
position: absolute;
right: 0;
margin: 0;
bottom: 0;
}
img{
display: block;
}
.logo{
float: left;
}
.logo-nav{
background: lightblue;
position: relative;
}
.logo-nav:after{
display: block;
clear: both;
content: "";
}
<div class="logo-nav">
<div class="logo"><img src="http://placehold.it/100x50"></div>
<div class="navigation">
<ul class="nav-ul">
<li class="nav-li">OUR SPIRIT</li>
<li class="nav-li">OUR OFFER</li>
<li class="nav-li">OUR VISIONARY</li>
<li class="nav-li">CONTACT</li>
</ul>
</div>
<div class="clear"></div>
</div>

fixed div is getting margin top

Fixed div is getting down when I give margin-top to the div below it...why?
* {
margin: 0;
padding: 0;
}
.header_bg {
width: 100%;
height: 100px;
position: fixed;
background: black
}
.container {
width: 960px;
height: auto;
margin: 0 auto
}
ul.menu {
list-style: none;
}
ul.menu li {
display: inline-block
}
ul.menu li a {
text-decoration: none;
color: white
}
.content {
margin-top: 140px
}
<div class="header_bg">
<div class="container">
<ul class="menu">
<li>Home
</li>
<li>About
</li>
<li>Service
</li>
<li>Contact
</li>
</ul>
</div>
</div>
<div class="container">
<div class="content">
/* Content Goes here*/
</div>
</div>
you need to add top:0 to your .header_bg, see more about position
* {
margin: 0;
padding: 0;
}
.header_bg {
width: 100%;
height: 100px;
position: fixed;
background: black;
top:0
}
.container {
width: 960px;
height: auto;
margin: 0 auto
}
ul.menu {
list-style: none;
}
ul.menu li {
display: inline-block
}
ul.menu li a {
text-decoration: none;
color: white
}
.content {
margin-top: 140px
}
<div class="header_bg">
<div class="container">
<ul class="menu">
<li>Home
</li>
<li>About
</li>
<li>Service
</li>
<li>Contact
</li>
</ul>
</div>
</div>
<div class="container">
<div class="content">
/* Content Goes here*/
</div>
</div>

Fixed height border

Hello I have three columns that need a right border with a fixed height, not depending on the number of items in the column.
My code
html
<div class="col-sm-2">
<div class="footer-col">
<ul>
<li class="footer-title hidden-xs">Customer Care</li>
<li>Contact us</li>
<li>Help</li>
<li>Shipping</li>
<li>Returns</li>
<li>Size Guide</li>
</ul>
</div>
</div>
<div class="col-sm-2 hidden-xs">
<div class="footer-col">
<ul>
<li class="footer-title">About Us</li>
<li>Our Story</li>
<li>Careers</li>
</ul>
</div>
</div>
<div class="col-sm-2 hidden-xs">
<div class="footer-col">
<ul>
<li class="footer-title">Shortcuts</li>
<li>My Account</li>
<li>Store Locator</li>
<li>Gift Cards</li>
<li>Payment</li>
</ul>
</div>
</div>
.wrapper {
display: inline-block;
background-color: #000000;
width: 100%;
height: 150px;
color: #999999;
}
.col-sm-2 {
float: right;
margin: 0;
width: 32%;
display: inline-block;
height: 90%;
}
.footer-col {
float: right;
margin: 0;
width: 90%;
padding-left: 10px;
display: inline-block;
height: 90%;
}
ul {
display: inline-block;
width: 90%;
height: 100%;
border-right: 1px solid #999999;
list-style: none;
}
li a {
color: #FFFFFF;
}
https://jsfiddle.net/michaelyuen/72dc7xrd/
There are two things:
1) Set ul height to 100%
2) Set height to parent or parent's parent. In this case, it's the wrapper.
OR use table, then you have to fix width instead of height.
https://jsfiddle.net/michaelyuen/72dc7xrd/1/
.wrapper {
display: table-row;
background-color: #000000;
color: #999999;
}
.col-sm-2 {
margin: 0;
padding-left: 10px;
width: 150px;
display: table-cell;
height: 90%;
border-right: 1px solid #999999;
vertical-align: top;
}
.footer-col {
margin: 0;
width: 90%;
display: inline-block;
height: 90%;
}
ul {
display: block;
margin: 0;
padding: 0;
width: 90%;
height: 100%;
list-style: none;
}
li a {
color: #FFFFFF;
}
Try this:
<style>
.verticalLine {
border-left: thick solid #E2C4C4;
margin-top:6px;
width:5px;
height:50px;
left: 408px;
position: absolute;
}
.pull_left {
float:left;
}
.clear {
clear: both;
}
</style>
<div class="col-sm-2">
<div class="footer-col pull_left">
<ul>
<li class="footer-title hidden-xs">Customer Care</li>
<li>Contact us</li>
<li>Help</li>
<li>Shipping</li>
<li>Returns</li>
<li>Size Guide</li>
</ul>
</div>
<div class="verticalLine pull_left"></div>
</div>
<div class="clear"></div>
<div class="col-sm-2 hidden-xs">
<div class="footer-col pull_left">
<ul>
<li class="footer-title">About Us</li>
<li>Our Story</li>
<li>Careers</li>
</ul>
</div>
<div class="verticalLine pull_left"></div>
</div>
<div class="clear"></div>
<div class="col-sm-2 hidden-xs">
<div class="footer-col pull_left">
<ul>
<li class="footer-title">Shortcuts</li>
<li>My Account</li>
<li>Store Locator</li>
<li>Gift Cards</li>
<li>Payment</li>
</ul>
</div>
<div class="verticalLine"></div>
</div>
Try like this: Demo
.col .well {
margin-bottom: -99999px;
padding-bottom: 99999px;
border-right:1px solid #ddd !important;
}
.col-wrap {
overflow: hidden;
}
.well {
min-height:20px;
padding:19px;
margin-bottom:20px;
background:transparent !important;
border-right:1px solid #e3e3e3 !important;
border:none !important;
box-shadow:none !important;
}
HTML:
<div class="container">
<div class="row col-wrap">
<div class="col-sm-2 col">
<div class="footer-col well">
....
</div>
</div>
<div class="col-sm-2 hidden-xs col">
<div class="footer-col well">
....
</div>
</div>
<div class="col-sm-2 hidden-xs col">
<div class="footer-col well">
....
</div>
</div>
</div>
</div>
Try this Create a outer container and apply overflow: hidden and apply margin and padding to the bottom
http://www.bootply.com/YNUeK8I29h
You can use after/before pseudo selectors.
http://jsfiddle.net/s7w4sqLd/
.footer-col ul:after {
position:absolute;
content:" ";
left:0;
top:0;
width:100%;
height:50px;
border-right: solid 1px #2a343f;
}
.footer-col ul{
position:relative;
float:left;
padding-right:10px;
}
.footer-col ul li {
list-style:none;
}

horizontal centering elements in div

I am wondering how to center elements within a div but keep the text left aligned.
Here is a jfiddle of what I have so far. I want the text to be in the middle of the div but to maintain its left justification.
http://jsfiddle.net/MgcDU/5994/
HTML:
<div class="span4" id="middleFooter">
<div class="mcont" >
<div class="mrow"> <h5 class="tcell"><b>Useful Links</b></h5> </div>
<ul>
<div class="mrow"> <li class="tcell">Contact Us</li> </div>
<div class="mrow"> <li class="tcell">About Us</li> </div>
<div class="mrow"> <li class="tcell">Copyright Information</li> </div>
<div class="mrow"> <li class="tcell">Terms & Conditions</li> </div>
</ul>
</div>
</div>
CSS:
#middleFooter {
color: #ccc2a0;
}
.mcont {
background-color: blue;
}
.mrow li {
background-color: red;
margin-left: auto;
margin-right: auto;
}
.mrow h5 {
display: table-row;
background-color: yellow;
}
.tcell {
display: table-cell;
}
You can try something like this - http://jsfiddle.net/GxgrL/
html:
<div class="span4" id="middleFooter">
<div class="mcont" >
<div class="mrow"> <h5 class="tcell"><b>Useful Links</b></h5> </div>
<ul>
<li class="tcell">Contact Us</li>
<li class="tcell">About Us</li>
<li class="tcell">Copyright Information</li>
<li class="tcell">Terms & Conditions</li>
</ul>
</div>
</div>
css:
#middleFooter {
color: #ccc2a0;
}
.mcont {
background-color: blue;
}
li {
background-color: red;
display: block;
text-align: center;
}
li a {
background-color: green;
display: inline-block;
margin: 0 auto;
width: 170px;
text-align: left;
}
.mrow {
text-align: center;
}
.mrow h5 {
display: inline-block;
background-color: yellow;
text-align: left;
width: 170px;
}
You can get this effect by making the container div 50% width then floating it to the right. So in your fiddle add:
.mcont {
width: 50%;
float: right;
}
If you want to keep the blue background you'll need to wrap all the .mrow divs in a wrapper and apply the styles above so like:
<div class="mcont" >
<div class="wrapper">
<div class="mrow"> <h5 class="tcell"><b>Useful Links</b></h5> </div>
<ul>
<div class="mrow"> <li class="tcell">Contact Us</li> </div>
<div class="mrow"> <li class="tcell">About Us</li> </div>
<div class="mrow"> <li class="tcell">Copyright Information</li> </div>
<div class="mrow"> <li class="tcell">Terms & Conditions</li> </div>
</ul>
</div>
</div>
Then:
.wrapper {
width: 50%;
float: right;
}
Just assign your .mrow divs a width and give them margin:0px auto and they will be center aligned.
.mrow{
width:20%;
margin:0px auto;
}
Here's an example of your fiddle with that style added: http://jsfiddle.net/HcQcn/