I'm trying to create a restaurant menu with dot leaders and I'm having trouble with this.
The format I'm looking for is the picture posted below.
Can someone please help me with this ?
HTML
<div class="dotted">
<ol>
<li>
<h2>Test</h2>
<p><span>Test 2</span><span class="price">$3.50(2) - $6.50(4)</span></p>
</li>
</ol>
</div>
CSS
p { margin: 0 0 -5px 0; }
li {
width: 100%;
position: relative;
margin-bottom: 1em;
border-bottom: 1px dotted #000;
list-style-type:none
}
span {
position: relative;
bottom: -1px;
padding: 0 1px;
background: #FFF;
}
span.price {
position: absolute;
right: 0; bottom: -6px;
}
Thanks in advance !
Wrap the first line of each group in a div that you make a flex container and use the following settings. The second line (ingredients) is outside of that container and can be a simple paragraph or DIV that has some bottom margin.
.linewrapper {
display: flex;
align-items: baseline;
}
.middle {
border-bottom: 1px dotted #aaa;
flex-grow: 1;
margin: 0 5px;
}
.ingredients {
color: #bbb;
margin-bottom: 1em;
}
<div class="linewrapper">
<div>
QUAIL
</div>
<div class="middle"></div>
<div>
9.9
</div>
</div>
<div class="ingredients">
stuff, stuff, stuff...
</div>
<div class="linewrapper">
<div>
SEA TROUT
</div>
<div class="middle"></div>
<div>
26.9
</div>
</div>
<div class="ingredients">
stuff, stuff, stuff...
</div>
Use a pseudo element with a dashed (or dotted or whatever) border to draw the dots and position it behind the text using z-index and give the text a background color so that the dots don't bleed through.
li {
display: flex;
justify-content: space-between;
position: relative;
align-items: baseline;
}
li:before {
border-bottom: 1px dashed #333;
content: '';
position: absolute;
bottom: 4px; left: 0; right: 0; top: 0;
z-index: -1;
}
span {
background: #fff;
padding: 0 .5em
}
<ul>
<li><span>Quail</span> <span>9.9</span></li>
<li><span>Quail</span> <span>9.9</span></li>
</ul>
body{
background: #fff;
}
.wrapper{
width:500px;
margin: 10px auto;
}
ul{
list-style:none;
padding: 0;
}
li{
width: 100%;
margin-bottom: 10px;
}
.line {
border-bottom: 1px dashed #000;
}
span{
float: right;
}
span, strong{
position:relative;
background: #fff;
z-index: 1;
top: 5px;
padding: 0 0 1px;
}
.description{
margin-top: 2px;
}
<div class="wrapper">
<ul>
<li><div class="line"><strong>My product</strong><span>Price</span></div><div class="description">My description</div></li>
<li><div class="line"><strong>My product</strong><span>Price</span></div><div class="description">My description</div></li>
<li><div class="line"><strong>My product</strong><span>Price</span></div><div class="description">My description</div></li>
</ul>
</div>
Related
How can I inextend the "MAKE YOU BURP" bottom border on the middle? In the right side of the food on plate, I tried to use margin: px; and it did work, but it affects other elements and the responsiveness of the webpage, is there any other way to do this without using margin: px;.
SCREENSHOT
#Main {
background-image: url('pexels-fwstudio-164005.jpg');
background-size: 1000px 700px;
}
#Main img {
width: 440px;
}
#Main #main-content {
display: inline-block;
}
#h2-last {
border-width: thick;
border-bottom: solid;
/*margin-right: 1097px;*/
}
.main-content li, a {
list-style: none;
text-decoration: none;
display: inline;
padding: 10px;
color: black;
font-weight: bold;
}
.main-content ul {
position: relative;
right: 49px;
}
#main-text {
position: relative;
bottom: 300px;
left: 500px;
}
.main-content button {
border-style: solid;
border-radius: 7px;
background: #F2A65A;
padding: 20px 25px 20px 25px;
}
<div id="children-main">
<div class="main-content">
<img src="Fish-Food-Plate-PNG.png" alt="fish in plate">
<div id="main-text">
<h2>BULALOI FOODS</h2>
<h2 id="h2-last">MAKE PEAOPLE BURP</h2>
<ul>
<li>
<button>ORDER</button>
</li>
<li>
<button>MENU</button>
</li>
</ul>
</div>
</div>
</div>
Just make sure the element width is set to fit content
#h2-last {
border-width: thick;
border-bottom: solid;
width: fit-content;
}
<h2 id="h2-last">MAKE PEAOPLE BURP</h2>
I've played around quite a bit with margins, positions, etc. but can't manage to centre the text on my image where I want it to without roughly manually inputting the position, i.e. left: 10px;. It is probably simple but I cant figure it out as a learner
.container {
position: relative;
}
.text-block-main {
position: absolute;
bottom: 5%;
right: 44%;
background-color: black;
opacity: 75%;
color: white;
padding-left: 20px;
padding-right: 20px;
border-radius: 15px;
border: 2px solid white;
padding: 10px;
}
<div class="container">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/ea/Van_Gogh_-_Starry_Night_-_Google_Art_Project.jpg/1200px-Van_Gogh_-_Starry_Night_-_Google_Art_Project.jpg" alt="vvg" style="height:100%;" class="center">
<div class="text-block-main">
<h2> The Starry Night </h2>
<h3> Vincent van Gogh </h3>
</div>
</div>
Its kind of centred (manually) but not really and depends on the image im using itself, so i'd have to adjust it for every image i want to use. Appreciate some help with this
Solution with flex. Specify display: inline-flex on the container class to take the form of an img tag image.
And also remove bottom and right from the text-block-main class.
I marked all the edits in css.
.container {
position: relative;
display: inline-flex; /*add this it*/
align-items: center; /*add this it*/
justify-content: center; /*add this it*/
}
.text-block-main {
position: absolute;
/*bottom: 5%;*/ /*remove this it*/
/*right: 44%;*/ /*remove this it*/
background-color: black;
opacity: 75%;
color: white;
padding-left: 20px;
padding-right: 20px;
border-radius: 15px;
border: 2px solid white;
padding: 10px;
}
<div class="container">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/ea/Van_Gogh_-_Starry_Night_-_Google_Art_Project.jpg/1200px-Van_Gogh_-_Starry_Night_-_Google_Art_Project.jpg" alt="vvg" style="height:100%;" class="center">
<div class="text-block-main">
<h2> The Starry Night </h2>
<h3> Vincent van Gogh </h3>
</div>
</div>
You can use flexbox for this functionality. The text-block-main is getting the full cover of the image and is centering the inner div in the center with Flexbox.
.container {
position: relative;
}
.container img {
height: 100%;
width: 100%;
}
.text-block-main {
position: absolute;
height: 100%;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
top: 0;
left: 0;
right: 0;
bottom: 0
}
.text-block-main .inner {
background-color: black;
opacity: 75%;
color: white;
padding: 25px;;
border-radius: 15px;
border: 2px solid white;
text-align: center;
}
<div class="container">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/ea/Van_Gogh_-_Starry_Night_-_Google_Art_Project.jpg/1200px-Van_Gogh_-_Starry_Night_-_Google_Art_Project.jpg" alt="vvg" style="height:100%;" class="center">
<div class="text-block-main">
<div class="inner">
<h2> The Starry Night </h2>
<h3> Vincent van Gogh </h3>
</div>
</div>
</div>
You can try to do something like this with the flex attribute
.container {
position: relative;
height:200px;
display: flex;
justify-content: center;
align-items: center;
}
.container img {
width:100%;
position:absolute;
}
.text-block-main {
background-color: black;
opacity: 75%;
color: white;
padding-left: 20px;
padding-right: 20px;
border-radius: 15px;
border: 2px solid white;
padding: 10px;
}
<div class="container">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/ea/Van_Gogh_-_Starry_Night_-_Google_Art_Project.jpg/1200px-Van_Gogh_-_Starry_Night_-_Google_Art_Project.jpg" alt="vvg" style="height:100%;" class="center">
<div class="text-block-main">
<h2> The Starry Night </h2>
<h3> Vincent van Gogh </h3>
</div>
</div>
( Here below i add other solutions by changing only some piece of codes, what you don't see remains as it was )
solution with the image without having the container full width
.container img {
/*width:100%;*/
position:absolute;
}
solution without adding style to the image
/*
.container img {
width:100%;
position:absolute;
}
*/
.text-block-main {
position:absolute; /* add this with the other styles */
}
For my web app's landing page, I'm trying to create a title that appears overlaid on a dotted line (similar to this effect). This is what I currently have:
How do I create this such that the dotted line does not run through the title? I prefer to use the simplest CSS/HTML I possibly can and support the max number of browsers.
My code is pretty rudimentary. So far it is:
<h2>New Account:</h2><br>
<h2 style="margin-top:-0.5em;border:2px dashed #ffffff;border-radius:4px;color:white;display: inline-block;padding:10px 5px 5px 5px;">Choose Nickname:<br>Password:<br></h2>
With the example below you don't need to know the background color, is perfectly scalable, the dots extend to the remaining space of the title.
Actually, the title can wrap on multiple lines.
Feel free to tweak it to your needs and don't forget to prefix.
dotted-container {
border: 2px dotted red;
border-top-width: 0;
margin: 2rem 1rem;
display: block;
}
dotted-container>.content {
padding: 1rem;
}
dotted-title {
display: flex;
align-items: center;
height: 2px;
margin: 0 2px;
}
dotted-title > span {
padding: 0 1rem;
}
dotted-title:after,
dotted-title:before {
border-top: 2px dotted red;
content: '';
display: inline-block;
height: 0;
flex:1;
}
<dotted-container>
<dotted-title>
<span>title</span>
</dotted-title>
<div class="content">
Actual content
</div>
</dotted-container>
<dotted-container>
<dotted-title>
<span>some other title</span>
</dotted-title>
<div class="content">
Some other actual content
</div>
</dotted-container>
<dotted-container>
<dotted-title>
<span>and here's a title<br /> on two lines</span>
</dotted-title>
<div class="content">
Some content for a title on two lines.
</div>
</dotted-container>
Of course, you might want to adjust the margin/padding to your own liking and to accommodate any title wrapping on more than one line.
If you want to replace the "crappy" dotted line with a true dotted one, here's an example. Read the blog post to understand it.
Another good write-up on border-image property here.
Also note you don't have to use custom tags, as I did. It's an example. You may use classes or any other selectors that work for your specific case.
And here's an SCSS script I made you can use to pass in your selectors and desired margin/padding values. Far from perfect, but seems to do the trick:
$border-width: 2px;
$border-style: dotted;
$border-color: red;
$container: 'dotted-container';
$title: 'dotted-title';
$content:'.content';
$padding: 2rem;
$margin: 1rem;
$title-padding-value: 3;
$title-padding-unit:rem;
#{$container} {
border: $border-width $border-style $border-color;
border-top-width: 0;
margin: #{$title-padding-value/2}#{$title-padding-unit} $margin $margin $margin;
display: block;
> #{$content} {
padding: #{$title-padding-value/2}#{$title-padding-unit} $padding $padding $padding;
}
#{$title} {
display: flex;
align-items: center;
height: $border-width;
margin: 0 $border-width;
> span {
padding: 0 $padding;
}
&:after,
&:before {
border-top: $border-width $border-style $border-color;
content: '';
display: inline-block;
height: 0;
flex: 1;
}
}
}
Here's a solution with a combination of pseudo elements, flexbox, and absolute positioning.
* {
margin:0;padding:0;
box-sizing:border-box;
}
body {
background: url('https://s-media-cache-ak0.pinimg.com/originals/33/3b/4f/333b4f22ae39d1aaf8c23d77e759d8e1.jpg') 0 0 no-repeat / cover;
}
h2:before,h2:after {
content: '';
bottom: 50%;
border-top: 3px dotted black;
flex: 1 0 0;
}
h2:before {
margin-right: 1em;
}
h2:after {
margin-left: 1em;
}
h2 {
display: flex;
align-items: center;
font-size: 3em;
position: absolute;
top: 0; left: 0; right: 0;
transform: translateY(calc(-50% + 1px));
text-shadow: 0 3px 0 #fff;
}
section {
border: dotted black;
border-width: 0 3px 3px;
position: relative;
width: 80%;
margin: 3em auto;
padding-top: 3em;
background: rgba(255,255,255,0.5);
}
<section>
<h2>New Account:</h2>
<p>foo</p>
<p>foo</p>
<p>foo</p>
</section>
You can use a combination of z-index and background-color, as shown in the snippet below:
z-index pulls the New Account: title in front, then the background-color hides the border behind the it
body {
background: green;
}
#one {
position: absolute;
left: 35px;
z-index: 1;
background: green;
display: inline-block;
color: white;
}
#two {
position: absolute;
z-index: -1;
top: 55px;
margin-top: -0.5em;
border: 2px dashed white;
border-radius: 4px;
color: white;
display: inline-block;
padding: 10px 5px 5px 5px;
}
<h2 id="one">New Account:</h2><br>
<h2 id="two">Choose Nickname:<br>Password:<br></h2>
Perhaps you can do something like this:
* {
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.box {
background: green;
padding: 15px;
width: 250px;
height: 250px;
}
.inner-box {
border: 1px dotted #ffffff;
height: 100%;
position: relative;
-webkit-border-radius: 7px;
border-radius: 7px;
}
.inner-box p {
position: absolute;
width:70%;
text-align: center;
top: -25px;
left: 50%;
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
color: #ffffff;
display: block;
background: green; /* Make it the same as background color */
}
<div class="box">
<div class="inner-box">
<p>My Awesome Title</p>
</div>
</div>
I would suggest having a background colour on the "New Account" if the background is only one colour, that way the dotted line will not be seen as it is covered by the background colour.
The code snippet shows how this can be adjusted to show more or less of the dotted border either side of the title.
.parent{
background-color: green;
position: relative;
font-size: 14px;
}
.parent h2:first-child{
color: #fff;
text-align: center;
z-index: 1;
background-color: green;
position: absolute;
left: 20px;
padding: 0 5px;
}
.parent h2:last-child{
margin-top: 15px;
z-index: 0;
}
.parent_two h2:first-child{
left: 12px;
padding: 0 17px;
}
<div class='parent'>
<h2>New Account:</h2><br>
<h2 style="border:2px dashed #ffffff;border-radius:4px;color:white;display: inline-block;padding:10px 5px 5px 5px;">Choose Nickname:<br>Password:<br></h2>
</div>
<div class='parent_two parent'>
<h2>New Account:</h2><br>
<h2 style="border:2px dashed #ffffff;border-radius:4px;color:white;display: inline-block;padding:10px 5px 5px 5px;">Choose Nickname:<br>Password:<br></h2>
</div>
I would move the title up with absolute positioning (just make sure the parent is relative positioned), wrap the title text in a <span> and then add padding and matching background color to that <span>.
body {
margin: 0;
background-color: green;
}
.box {
position: relative;
margin: 1rem;
padding: 1rem;
color: white;
box-sizing: border-box;
border: 1px dashed white;
}
.box-title {
position: absolute;
top: -1rem;
left: 0;
margin: 0;
width: 100%;
text-align: center;
font-size: 1.5rem;
}
.box-title>span {
padding: 0 1rem;
background-color: green;
}
<div class="box">
<h2 class="box-title"><span>New Account:</span></h2>
<p>Username:</p>
<p>Password:</p>
</div>
FWIW, I don't typically care for extra markup but if I have to work extra hard to make it work some other way then I find it acceptable. Especially when it's super simple.
body{
background: url('https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=750&h=350') center top 0 no-repeat / cover;
}
.wrapper {
max-width: 400px;
margin: 30px auto 0;
border: 2px dotted red;
height: 200px;
border-top: 0;
text-align: center;
}
.heading {
display: table;
width: 100%;
position: relative;
}
.heading:before {
content: '';
display: table-cell;
border-top: 2px dotted red;
}
.heading:after {
content: '';
display: table-cell;
border-top: 2px dotted red;
}
.txt-wrapper {
display: table-cell;
width: 1%;
white-space: nowrap;
line-height: 0;
padding: 0 10px;
}
<div class="wrapper">
<div class="heading">
<h2 class="txt-wrapper">
This is heading
</h2>
</div>
<P>
This is paragraph.
</P>
<P>
This is another paragraph.
</P>
</div>
I am trying to create a small border under my headlines on a website. I am doing it using before and after pseudo-elements. The code is a bit particular because I am adapting the code of the template I'm using. It is like this see fiddle
The problem is the "left: 48%;" property : I have set it manually, but depending on the size of the screen, it might be centered or not, so it is not responsive. Is there a way to have the border always centered under the text ?
.headline p:before,
.headline p:after {
position: absolute;
left: 48%;
display: block;
width: 70px;
border-bottom: 3px solid black;
content: "";
}
h3 {
text-align: center;
}
<div class="headline">
<h3>
My title
</h3>
<p>
</p>
</div>
use calc() css function as follows:
.headline p:before,
.headline p:after {
position: absolute;
left: calc(50% - 35px);
display: block;
width: 70px;
border-bottom: 3px solid black;
content: "";
}
h3 {
text-align: center;
}
<div class="headline">
<h3>My title</h3>
<p></p>
</div>
Give the pseudoelement a left and right property - and then use margin: auto to center.
.headline p:before,
.headline p:after {
position: absolute;
left: 0;
right: 0;
margin: auto;
display: block;
width: 70px;
border-bottom: 3px solid black;
content: "";
}
h3 {
text-align: center;
}
<div class="headline">
<h3>
My title
</h3>
<p>
</p>
</div>
fiddle
Use margin property
Rewrite your code as
.headline p:before, .headline p:after {
margin: 0 auto;
width: 70px;
border-bottom: 3px solid black;
content: "";
}
.headline p:before,
.headline p:after {
margin: 0 auto;
display: block;
width: 70px;
border-bottom: 3px solid black;
content: "";
}
h3 {
text-align: center;
}
<div class="headline">
<h3>
My title
</h3>
<p>
</p>
</div>
just use margin:auto
.headline p:before,
.headline p:after {
margin: auto;
display: block;
width: 70px;
border-bottom: 1px solid black;
content: "";
}
h3 {
text-align: center;
}
<div class="headline">
<h3>
My title
</h3>
<p>
</p>
</div>
I need to present a header menu with 3 elements:
one is left aligned
one is centered
one is right aligned
I would like a gray background for this menu.
The problem: if I have links in my left or right elements and it is not clickable because of the centered element.
How to prevent this problem? or another way of having this kind of menu?
Any idea is highly appreciated.
jsFiddle: http://jsfiddle.net/sxmf0Lve/
<div class="headerContainer">
<div class="headerLeft">
Left
</div>
<div class="headerTitle">Middle</div>
<div class="headerRight">
Right
</div>
</div>
.headerContainer {
padding-top: 10px;
padding-left: 0px;
padding-right: 5px;
max-width: 100%;
height: 30px;
background-color: #fcfcfc;
border-bottom: 1px solid #f6f6f6;
}
.headerTitle {
position: absolute;
/* z-index: -1; */
top: 10px;
width: 100%;
margin: auto;
text-align: center;
font-size: x-large;
font-weight: bold;
}
.headerLeft {
float: left;
}
.headerRight {
float: right;
}
Updated fiddle: http://jsfiddle.net/7mo7hyza/
Your z-index idea is good, but you didn't perform it well: z-index only works between elements that are both not in the normal workflow of the document (they have position: absolute/relative/..)
So you simply have to position your left/right containers with position: absolute instead of float, and make the big container relative so that you can position the other containers relatively to that one.
.headerContainer {
position: relative;
} .headerTitle {
z-index: 0;
} .headerLeft {
position: absolute;
left: 0;
z-index: 1;
} .headerRight {
position: absolute;
right: 0;
z-index: 1;
}
Make the left and right position relative and give them a higher z-index.
.headerContainer {
padding-top: 10px;
padding-left: 0px;
padding-right: 5px;
max-width: 100%;
height: 30px;
background-color: #fcfcfc;
border-bottom: 1px solid #f6f6f6;
}
.headerTitle {
position: absolute;
/* z-index: -1; */
top: 10px;
width: 100%;
margin: auto;
text-align: center;
font-size: x-large;
font-weight: bold;
}
.headerLeft,
.headerRight {
position: relative;
z-index: 2;
}
.headerLeft {
float: left;
}
.headerRight {
float: right;
}
<div class="headerContainer">
<div class="headerLeft">
Left
</div>
<div class="headerTitle">Middle</div>
<div class="headerRight">
Right
</div>
</div>
Try to avoid using float-ing elements or messing with the z-index. There are two more appropriate methods for what you're trying to achieve:
Method 1: CSS box model
.headerContainer {
padding-top: 10px;
padding-left: 0px;
padding-right: 5px;
max-width: 100%;
height: 30px;
background-color: #fcfcfc;
border-bottom: 1px solid #f6f6f6;
display: flex;
flex-wrap: nowrap;
}
.headerLeft,
.headerTitle,
.headerRight {
display: inline-block;
}
.headerLeft,a
.headerRight {
flex-grow: 0;
}
.headerTitle {
flex-grow: 1;
text-align: center;
font-size: x-large;
font-weight: bold;
}
<div class="headerContainer">
<div class="headerLeft">
Left
</div>
<div class="headerTitle">Middle</div>
<div class="headerRight">
Right
</div>
</div>
See JsFiddle
Method 2: Table layout
.row {
display: table-row;
width: 100%;
background-color: #eee;
}
.cell {
display: table-cell;
}
.middle {
width: 100%;
text-align: center;
}
<div class="headerContainer row">
<div class="cell">
Left
</div>
<div class="cell middle">
<h1>Middle</h1>
</div>
<div class="cell">
Right
</div>
</div>
See JsFiddle