I'm building a simple pricing table and would like to place a "most popular" circle in it like in this mockup image I have created.
This is how I've created the pricing table.
.columns {
float: left;
width: 30%;
padding: 8px;
}
.table {
list-style-type: none;
border: 1px solid #eee;
margin: 0;
padding: 0;
}
.table .header {
background-color: #333;
color: #fff;
}
.table li {
padding: 20px;
text-align: center;
}
.table .top {
background-color: #eee;
}
<div class="columns">
<ul class="table">
<li class="header">First Product</li>
<li class="top">$100.00</li>
<li>First feature</li>
<li>Second feature</li>
<li>Buy</li>
</ul>
</div>
<div class="columns">
<ul class="table">
<li class="header">Second Product</li>
<li class="top">$100.00</li>
<li>First feature</li>
<li>Second feature</li>
<li>Buy</li>
</ul>
</div>
<div class="columns">
<ul class="table">
<li class="header">Third Product</li>
<li class="top">$100.00</li>
<li>First feature</li>
<li>Second feature</li>
<li>Buy</li>
</ul>
</div>
I then found a way to create a circle with "most popular" in it (not sure if this is the best way to do it though), like this. I reversed the colors so it can be seen on a white background.
.dot {
height: 55px;
width: 70px;
background-color: #fff;
border-radius: 50%;
border: 3px solid #eee;
display: inline-block;
padding-top: 15px;
}
<div style="text-align:center">
<span class="dot">Most<br>Popular</span>
</div>
I'm just not sure how to bring these concepts together to create something like in the mockup shot where the circle sits on an angle off to the side of the price like that and have it cut off on the edges.
You can take your .dot class and make it a pseudo element instead, meaning you wouldn't have to add it to your HTML.
With the code below, if you add the class most-popular to a top element, it will show the "Most Popular" badge. You may need to take a few minutes and style it to get it to match your image perfectly, but the difficult part should be out of the way.
Changes:
To position the "most popular" to the left, I've set it to position: absolute;, and its parent to display: relative;. Using the top and left properties, I've positioned it to the left of its parent and vertically-centered.
I've put overflow: hidden; on the parent so that anything outside of its boundaries will be hidden.
Applied transform: rotate(-15deg) to the badge to give it a slight rotation.
.columns {
float: left;
width: 30%;
padding: 8px;
}
.table {
list-style-type: none;
border: 1px solid #eee;
margin: 0;
padding: 0;
}
.table .header {
background-color: #333;
color: #fff;
}
.table li {
padding: 20px;
text-align: center;
}
.table .top {
background-color: #eee;
position: relative;
overflow: hidden;
}
.most-popular::after {
content: 'Most Popular';
display: block;
height: 55px;
width: 70px;
border-radius: 50%;
border: 3px solid #fff;
padding-top: 15px;
position: absolute;
transform: rotate(-20deg);
left: -5px;
top: -5px;
}
<div class="columns">
<ul class="table">
<li class="header">First Product</li>
<li class="top">$100.00</li>
<li>First feature</li>
<li>Second feature</li>
<li>Buy</li>
</ul>
</div>
<div class="columns ">
<ul class="table ">
<li class="header ">Second Product</li>
<li class="top ">$100.00</li>
<li>First feature</li>
<li>Second feature</li>
<li>Buy
</li>
</ul>
</div>
<div class="columns ">
<ul class="table ">
<li class="header ">Third Product</li>
<li class="top most-popular">$100.00
</li>
<li>First feature</li>
<li>Second feature</li>
<li>
Buy
</li>
</ul>
</div>
Related
I have created a bubble conversation html.
Now I am trying to add a footer to it.
(Footer similar code in https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_fixed_footer)
ul {
list-style: none;
margin: 0;
padding: 0;
}
ul li {
display: inline-block;
clear: both;
padding: 5px;
border-radius: 20px;
margin-bottom: 2px;
width: 80%;
background: #eee;
}
.him {
float: left;
border: 1px solid #000000;
}
.me {
float: right;
}
#footer {
height: 30px;
position: fixed;
left: 0;
bottom: 0;
width: 100%;
background-color: red;
color: white;
text-align: center;
}
body {
padding-bottom: 30px;
}
<div>
<div>
<ul>
<li class="me">N-19</li>
<li class="me">N-18</li>
<li class="him">N-17</li>
<li class="me">N-16</li>
<li class="me">N-15</li>
<li class="me">N-14</li>
<li class="him">N-13</li>
<li class="me">N-12</li>
<li class="me">N-11</li>
<li class="me">N-10</li>
<li class="me">N-9</li>
<li class="me">N-8</li>
<li class="him">N-7</li>
<li class="me">N-6</li>
<li class="me">N-5</li>
<li class="me">N-4</li>
<li class="me">N-3</li>
<li class="me">N-2</li>
<li class="me">N-1</li>
<li class="him">N</li>
</ul>
</div>
<div id="footer">
Footer
</div>
</div>
But I am not seeing the last lines of the conversation. The problem is that the footer is overlaping them because of the float property of the < li > elements.
How can I avoid it?
check this out: css grid is a very good property of css.
we can divide screen into number of columns and rows . i used here css-grid.
for more info on css-grid read
https://css-tricks.com/snippets/css/complete-guide-grid/
ul {
list-style: none;
margin: 0;
padding: 0;
display:grid;
grid-template-columns:33% 33% 34%;
}
ul li {
display: block;
clear: both;
padding: 5px;
border-radius: 20px;
margin-bottom: 2px;
background: #eee;
}
.him {
grid-column:1/3;
border: 1px solid #000000;
}
.me {
grid-column:2/4
}
#footer {
height: 30px;
position: fixed;
bottom:0;
width: 100%;
background-color: red;
color: white;
text-align: center;
}
body {
padding-bottom: 30px;
}
<div>
<div>
<ul>
<li class="me">N-19</li>
<li class="me">N-18</li>
<li class="him">N-17</li>
<li class="me">N-16</li>
<li class="me">N-15</li>
<li class="me">N-14</li>
<li class="him">N-13</li>
<li class="me">N-12</li>
<li class="me">N-11</li>
<li class="me">N-10</li>
<li class="me">N-9</li>
<li class="me">N-8</li>
<li class="him">N-7</li>
<li class="me">N-6</li>
<li class="me">N-5</li>
<li class="me">N-4</li>
<li class="me">N-3</li>
<li class="me">N-2</li>
<li class="me">N-1</li>
<li class="him">N</li>
</ul>
</div>
<div id="footer">
Footer
</div>
</div>
Due to padding-bottom could not be applied here, my answer didn't fit in the case, therefore I've done a research on the alternatives for a grid layout proposed and, surprisingly, for the fixed positioning of the footer block.
In this example I've decided to leave the code without the <ul> which has quite a big list of default element css values. I supposed that the first message always comes from the user, and used :not() CSS selector to style the replies blocks. You can change .user and :not(user) to any classes like .me and .him according to your HTML.
section {display:flex;flex-direction:column}
section * {
width: 75%;
border: 1px solid #757575;
border-radius:20px;
padding:2px 10px;
margin-bottom:2px
}
.user {
background:#ccc;
margin-left: auto
}
section :not(.user) {
background:#eee
}
section :not(.user) + .user, .user + :not(.user) {
margin-top:5px
}
footer {
height: 30px;
position: sticky; /* Yes. It works now */
bottom: 0;
background: #000;
color: white;
text-align: center;
line-height: 28px
}
<section>
<div class="user">Need some help with HTML</div>
<div class="user">And CSS maybe</div>
<div class="user">Want it to work with long-lenth messages as well, you know. And in all the browsers, even IE...</div>
<div>Sure</div>
<div>Lets test this one</div>
<div>Quite a good in terms of browser support in 2019</div>
<div class="user">Awsome!</div>
<div class="user">Thank you so much</div>
<div>You are welcome</div>
<div class="user">Goodbye</div>
</section>
<footer>
<p>Sticky Footer</p>
</footer>
I have two lists sitting side-by-side. In the full code there will be the ability to select one of the list items from the MainList which will show the relevant list items from the SubList. What I would like is for the border-right of the MainList to overlap the border-left of the SubList to make it look like the SubList items are being shown as a result of the selection in the MainList.
ul {
list-style: none;
}
.BigContainer {
border: 2px solid #d50f67;
border-radius: 5px;
margin: 10px 0;
padding: 5px;
overflow: auto;
}
.MainListContainer {
width: 50%;
float: left;
}
.MainListItem {
border-bottom: 1px solid #ddd;
border-right: 1px solid white;
padding: 5px;
z-index: 2;
}
.MainListItem:last-of-type {
border: none;
}
.SubListContainer {
width: 45%;
float: left;
border: 1px solid #ddd;
border-radius: 5px;
}
.SubListItem {
padding: 5px;
z-index: 1;
}
<div class="BigContainer">
<div class="MainListContainer">
<ul class="MainList">
<li class="MainListItem">List Option A</li>
<li class="MainListItem">List Option B</li>
<li class="MainListItem">List Option C</li>
</ul>
</div>
<div class="SubListContainer">
<ul class="SubList">
<li class="SubListItem">Sub-Option 1</li>
<li class="SubListItem">Sub-Option 2</li>
<li class="SubListItem">Sub-Option 3</li>
<li class="SubListItem">Sub-Option 4</li>
<li class="SubListItem">Sub-Option 5</li>
</ul>
</div>
</div>
So, the border-right of the MainList would be white/transparent to basically erase a portion of the SubList border. I appreciate that, at the moment, making this happen would remove more of the SubList border than desired, but I will code the selection process properly to ensure only the selected item has the relevant border styling applied.
Add selected class to the selected item, then add
.selected:after{
content:"";
position: absolute;
right:-2px;
top:0;
width: 1px;
height: 100%;
background-color: white;
}
This will be placed right where you want it to. Note that MainListItem needs to have a position: relative; for the position to work.
.selected:after{
content:"";
position: absolute;
right:-2px;
top:0;
width: 1px;
height: 100%;
background-color: white;
}
ul {
list-style: none;
}
.BigContainer {
border: 2px solid #d50f67;
border-radius: 5px;
margin: 10px 0;
padding: 5px;
overflow: auto;
}
.MainListContainer {
width: 50%;
float: left;
}
.MainListItem {
border-bottom: 1px solid #ddd;
border-right: 1px solid white;
padding: 5px;
z-index: 2;
position: relative;
}
.MainListItem:last-of-type {
border: none;
}
.SubListContainer {
width: 45%;
float: left;
border: 1px solid #ddd;
border-radius: 5px;
}
.SubListItem {
padding: 5px;
z-index: 1;
}
<div class="BigContainer">
<div class="MainListContainer">
<ul class="MainList">
<li class="MainListItem">List Option A</li>
<li class="MainListItem selected">List Option B</li>
<li class="MainListItem">List Option C</li>
</ul>
</div>
<div class="SubListContainer">
<ul class="SubList">
<li class="SubListItem">Sub-Option 1</li>
<li class="SubListItem">Sub-Option 2</li>
<li class="SubListItem">Sub-Option 3</li>
<li class="SubListItem">Sub-Option 4</li>
<li class="SubListItem">Sub-Option 5</li>
</ul>
</div>
</div>
I am working on a segmented control with 3 different "categories". When a certain category is "active", I want their background to be entirely blue. This is the case for "tab1" but unfortunately, something goes wrong when "tab2" or "tab3" is active, because their background is not entirely blue. The background also contains small grey strips and I have no idea how to get rid of those.
I put this code in a jsfiddle here: http://jsfiddle.net/vooj53xt/1/
The jsfiddle contains the same exact components three times. The only difference between the three components is which element is activated. As you can see, when "tab2" or "tab3" is activated, their background is not entirely blue. There is also a small strip that is grey. These grey strips, however, are unwanted. Can anyone tell me how to fix this?
The HTML looks like this:
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-6 col-sm-offset-3 col-lg-4 col-lg-offset-4" style="padding-bottom:20px;">
<ul class="segmented-control">
<li class="active">Tab 1</li>
<li class="">Tab 2</li>
<li class=""><a href="#tab3" >Tab 3</a></li>
</ul>
</div>
</div>
The accompanying CSS looks like this:
body {
background-color: #f8f4f0;
padding-bottom: 70px;
padding-top: 70px;
}
.segmented-control {
border: 2px solid #51cbeb;
border-radius: 5px;
list-style: none;
padding: 0;
margin: 0;
}
.segmented-control li {
border-right: 2px solid #51cbeb;
display: inline-block;
padding: 0;
text-align: center;
width: 32%;
}
.segmented-control li:last-child {
border-right: none;
}
.segmented-control .active {
background-color: #51cbeb;
}
.segmented-control li a {
display: block;
font-weight: bold;
text-transform: uppercase;
padding: 5px 0;
}
.demo-page {
margin: 120px 0;
}
You can change display property, like this:
.segmented-control {
display:table;
}
.segmented-control li {
display:table-cell;
}
DEMO: http://jsfiddle.net/vooj53xt/9/
Problem is caused by using of inline-block...https://css-tricks.com/fighting-the-space-between-inline-block-elements/
You can set font-size: 0; to the ul and reset it on li, to fix the white space bug on inline block.
.segmented-control {
font-size: 0;
}
.segmented-control li {
font-size: 16px;
}
Here's a fiddle. I just changed display:block to float:left - and added clearfix class to the ul tag classes and changed width to 33.34% for the li tag.
HTML:
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-6 col-sm-offset-3 col-lg-4 col-lg-offset-4" style="padding-bottom:20px;">
<ul class="segmented-control clearfix">
<li class="active">Tab 1
</li>
<li class="">Tab 2
</li>
<li class="">Tab 3
</li>
</ul>
</div>
<div class="col-xs-12 col-sm-6 col-sm-offset-3 col-lg-4 col-lg-offset-4" style="padding-bottom:20px;">
<ul class="segmented-control clearfix">
<li class="">Tab 1
</li>
<li class="active">Tab 2
</li>
<li class="">Tab 3
</li>
</ul>
</div>
<div class="col-xs-12 col-sm-6 col-sm-offset-3 col-lg-4 col-lg-offset-4" style="padding-bottom:20px;">
<ul class="segmented-control clearfix">
<li class="">Tab 1
</li>
<li class="">Tab 2
</li>
<li class="active"><a ref="#tab3">Tab 3</a>
</li>
</ul>
</div>
</div>
</div>
CSS:
body {
background-color: #f8f4f0;
padding-bottom: 70px;
padding-top: 70px;
}
/* Segmented control */
.segmented-control {
border: 2px solid #51cbeb;
border-radius: 5px;
list-style: none;
padding: 0;
margin: 0;
}
.segmented-control li {
border-right: 2px solid #51cbeb;
float:left;
padding: 0;
text-align: center;
width: 33.3333334%;
}
.segmented-control li:last-child {
border-right: none;
}
.segmented-control .active {
background-color: #51cbeb;
}
.segmented-control li a {
display: block;
font-weight: bold;
text-transform: uppercase;
padding: 5px 0;
}
.demo-page {
margin: 120px 0;
}
I have the following HTML:
#main-menu {
background-color: blue;
border: 1px solid black;
width: 600px;
}
.menu {
list-style: none outside none;
text-align: center;
}
.menu-item {
float: left;
}
.menu-item a {
border: 1px solid red;
}
<div id="main-menu">
<ul class="menu">
<li class="menu-item">Item #1</li>
<li class="menu-item">Item #2</li>
<li class="menu-item">Item #3</li>
<li class="menu-item">Item #4</li>
</ul>
</div>
How do I make the li elements automatically expand euqally to the fixed width of the container?
Thanks in advance! :-)
CodePen link: http://codepen.io/anon/pen/JoKgXz
I've updated you codepen codes..
CSS
#main-menu {
background-color: blue;
border: 1px solid black;
width: 600px;
overflow: hidden;
}
ul, li{
margin:0;
padding:0;
}
.menu {
list-style: none outside none;
text-align: center;
}
.menu-item {
float: left;
width:25%;
}
.menu-item a {
border: 1px solid red;
}
Demo
Ensure you have a proper CSS reset and use the box-sizing:border-box property.
This option has the virtue of not requiring set widths on the li
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
#main-menu {
background-color: blue;
border: 1px solid black;
width: 600px;
}
.menu {
list-style: none outside none;
text-align: center;
display: table;
width: 100%;
}
.menu-item {
display: table-cell;
}
.menu-item a {
border: 1px solid red;
color: white;
display: block;
}
<div id="main-menu">
<ul class="menu">
<li class="menu-item">Item #1
</li>
<li class="menu-item">Item #2
</li>
<li class="menu-item">Item #3
</li>
<li class="menu-item">Item #4
</li>
</ul>
</d
First remove all margin and padding from the .menu. As you have four items in the menu, add width: 25% to the .menu-item. I've added a display: block to the <a> tag to make it fill the entire width of the .menu-item. As you use float: left the menu-items won't make the .menu container grow. The .menu:after adds a clearfix to have the menu contain all menu items.
Instead of float: left you could also have opted for a display: inline-block. In this case the clearfix wouldn't be necessary, but you need to make sure that the menu items don't have any whitespace (e.g. a newline) between them. Put them on one line like ...</li><li>... otherwise there will be some space between the menu items.
If you need some padding on the menu item make sure to add box-sizing: border-box as otherwise the width will refer to the content only. This means that after adding the padding the menu item will take up more than 25% of the width, which makes the last menu item wrap to a new line.
#main-menu {
background-color: blue;
border: 1px solid black;
width: 600px;
}
.menu {
list-style: none;
text-align: center;
margin: 0;
padding: 0;
}
.menu:after {
content: '';
display: block;
clear:both;
}
.menu-item {
float: left;
width: 25%;
}
.menu-item a {
display: block;
border: 1px solid red;
}
<div id="main-menu">
<ul class="menu">
<li class="menu-item">Item #1</li>
<li class="menu-item">Item #2</li>
<li class="menu-item">Item #3</li>
<li class="menu-item">Item #4</li>
</ul>
</div>
I would like to have a long border underneath my menu UL, but the "border-bottom" property on the list items does not work well:
#headermenu {
height: 40px;
background: #f47a20;
position: relative;
}
#headermenu .menu {
background: #F47B20;
float: left;
border: 1px solid #D66C1C;
padding: 0.6em 1em;
margin-top: 0.5em;
list-style-type: none;
}
#headermenu-left {
padding: 0;
position: absolute;
top: 0;
left: 0;
width: 70%;
margin: 0;
}
#headermenu-left .menu {
border-bottom: 4px solid #004B8D;
}
<body>
<div id="headermenu">
<ul id="headermenu-left">
<li class="menu">
Link 1
</li>
<li class="menu">
Link 2
</li>
<li class="menu">
Link 3
</li>
<li class="menu">
Link 4
</li>
<li class="menu">
Link 5
</li>
<li class="menu">
Link 6
</li>
</ul>
</div>
</body>
The border is interrupted at the corners by -I guess- the border-left and border-right properties not being there?
I can't put it on the <ul> element, because then the line runs too long.
You can put it on the UL if you get rid of the width on it. Remove your last rule and use this:
#headermenu {
height: 40px;
background: #f47a20;
position: relative;
}
#headermenu .menu {
background: #F47B20;
float: left;
border: 1px solid #D66C1C;
padding: 0.6em 1em;
margin-top: 0.5em;
list-style-type: none;
}
#headermenu-left {
padding: 0;
position: absolute;
top: 0;
left: 0;
margin: 0;
border-bottom: 4px solid #004B8D;
}
<body>
<div id="headermenu">
<ul id="headermenu-left">
<li class="menu">
Link 1
</li>
<li class="menu">
Link 2
</li>
<li class="menu">
Link 3
</li>
<li class="menu">
Link 4
</li>
<li class="menu">
Link 5
</li>
<li class="menu">
Link 6
</li>
</ul>
</div>
</body>
The problem, as you suggest, is the missing left and right borders, which have a width, but no color, so this distorts the appearance of the bottom border with the illusion of a missing notch.
To solve this you can simply define border-width: 0 for the element, and allow the border-bottom property to override that setting.
#headermenu {
height: 40px;
background: #f47a20;
position: relative;
}
#headermenu .menu {
background: #F47B20;
float: left;
border: 1px solid #D66C1C;
padding: 0.6em 1em;
margin-top: 0.5em;
list-style-type: none;
}
#headermenu-left {
padding: 0;
position: absolute;
top: 0;
left: 0;
width: 70%;
margin: 0;
}
#headermenu-left .menu {
border-width: 0;
border-bottom: 4px solid #004B8D;
}
<body>
<div id="headermenu">
<ul id="headermenu-left">
<li class="menu">
Link 1
</li>
<li class="menu">
Link 2
</li>
<li class="menu">
Link 3
</li>
<li class="menu">
Link 4
</li>
<li class="menu">
Link 5
</li>
<li class="menu">
Link 6
</li>
</ul>
</div>
</body>
Unfortunately this is how borders work. Those are the ends of your border-left, and border-right. Here's a work around though, I added a div to the bottom of your list:
(I also removed your width:70%; from your list)
#bluebar {
position:absolute;
bottom:0px;
width:100%;
height:5px;
background-color:blue;
}
http://jsfiddle.net/BjGvp/6/