I am using ngFor for displaying a list of items which are separated by a horizontal dashed line as follows:
<div *ngFor="let comment of comments;let lastItem = last;">
<div class="comment-box">
<div class="comment-author">{{comment.createdBy}}</div>
<div class="creation-date">{{comment.createdOn}}</div>
<div class="comment-text">{{comment.text}}</div>
</div>
<div class="dashed-line-box" *ngIf="!lastItem">
<hr class="new1">
</div>
</div>
.dashed-line-box {
position: relative;
background-color: #ffffff;
width: 320px;
height: 16px;
border-style: solid;// to outline the container box
border-width: thin;
}
hr.new1 {
position: absolute;
margin-top: 8px;
border-top: 1px dashed;
}
I can see rectangles for each dashed-line-box entry, but they dont contain horizontal like I am expecting.
What am I missing here?
I think you want a dashed border style in <hr>
hr.new1 {
position: absolute;
margin-top: 8px;
border-top: 1px dashed blue;
width: 100%;
}
or if you want a dashed border on outer div try below code
.dashed-line-box {
position: relative;
background-color: #ffffff;
width: 320px;
height: 16px;
border-bottom: 1px dashed green;
}
css property border-style: solid; from class .dashed-line-box is putting the box in the last line;To get a horizontal bar, you need to remove position:absolute from the class hr.new1;
relevant css:
p {
font-family: Lato;
}
.dashed-line-box {
position: relative;
background-color: #ffffff;
width: 320px;
height: 16px;
/* border-style: solid;*/
border-width: thin;
}
hr.new1 {
margin-top: 8px;
border-top: 1px dashed;
}
working stackblitz here
Why you need hr when you can achieve this using border bottom property. Just add one class to parent div and use border bottom.
.box {
border-bottom: 1px dashed;
}
<div class="box" *ngFor="let comment of comments;let lastItem = last;">
<div class="comment-box">
<div class="comment-author">{{comment.createdBy}}</div>
<div class="creation-date">{{comment.createdOn}}</div>
<div class="comment-text">{{comment.text}}</div>
</div>
</div>
Related
I need to display a border around a div tag with a title in the border itself. In order to do this, this is what I have come up with so far
.componentWrapper {
border: solid cadetblue;
border-radius: 40px;
padding: 10px;
width: 95%;
}
.componentTitle {
font-size: 18px;
width: 15%;
background-color: white;
margin-top: -25px;
}
<div class='componentWraper'><p class='componentTitle'>This is the title</p>This is the component body text</div>
As you can see I am using margin property to push the title up on top of the border. I am not sure if this is the proper approach to do this and I have the following questions.
I am positioning the title using pixels (margin) and a fixed value (-25px). This is a site that has to work on mobile phones, tablets as well. Is this an acceptable approach?
I am setting the background-color to white so that the border does not appear behind the text, is this an ok approach?
Is there a better and more acceptable way to do this, I do not want to use fieldset because we have little control over the border (border-radius).
There are three logical ways you can use to achieve this.
You can use a <fieldset> with a legend which is the basic HTML way of doing this. You can find more information about this here.
Use custom CSS with positioning, not negative margins or etc.:
body {
background: #fff;
}
.componentWraper {
margin: 40px; /* just for contrast */
position: relative;
border: 2px solid tomato;
border-radius: 12px;
padding: 20px;
}
.componentWraper .componentTitle {
position: absolute;
top: -25px;
background: #fff;
padding: 0 10px;
}
<div class='componentWraper'>
<p class='componentTitle'>This is the title</p>This is the component body text</div>
Use custom CSS with pseudo-elements:
body {
background: #fff;
}
.componentWraper {
margin: 40px; /* just for contrast */
position: relative;
border: 2px solid tomato;
border-radius: 12px;
padding: 20px;
}
.componentWraper::before {
content: 'This is the title';
position: absolute;
top: -10px;
padding: 0 10px;
background: #fff;
}
<div class='componentWraper'>This is the component body text</div>
I think you're on the right track. I'd make a few changes to have more control over the styling. You can use ems or pixels.
Wrap the title and content in a new div and give that a negative margin:
<div class='componentWrapper'>
<div>
<div class='componentTitle'>This is the title</div>
<div class='componentContent'>
<p>This is the component body text</p>
</div>
</div>
.componentWrapper div {
margin-top: -1em;
}
Set your title to display: inline-block and use padding to control the white space around it (instead of using width)
.componentTitle {
font-size: 18px;
background-color: white;
display: inline-block;
padding: .5em;
}
codepen
snippet:
.componentWrapper {
border: solid cadetblue;
border-radius: 40px;
padding: 10px;
width: 95%;
margin-top: 1em;
}
.componentWrapper div {
margin-top: -1.2em;
}
.componentTitle {
font-size: 18px;
background-color: white;
display: inline-block;
padding: .5em .3em;
}
<div class='componentWrapper'>
<div>
<div class='componentTitle'>This is the title</div>
<div class='componentContent'>
<p>This is the component body text</p>
</div>
</div>
This is what I came up with. I wanted to get rid of the negative margin, but couldn't figure out a way to do that.
See the Pen offset title by Yvonne Aburrow (#vogelbeere) on CodePen.
HTML
<div class="componentWrapper">This is the component body text</div>
CSS
.componentWrapper {
border: 1px solid blue;
border-radius: 40px;
padding: 16px;
width: 95%;
margin: 3em;
}
.componentWrapper:before {
content: "this is the title";
font-size: 18px;
width: 10%;
background-color: white;
border: 1px solid blue;
border-radius: 12px;
display: block;
margin-top: -29px;
padding: 3px;
}
I am not sure how a screen reader would deal with the title text being in the CSS (or how you would scale that up if you have a lot of different titles.
I have button and text on the same line. They have different font size. Button has padding. In browser it seems that text is on the same line, but the padding goes below the big text. I want the bottom button padding be on the same line as the big text. In other words, shift text a bit down or button a bit up.
Here's my CSS
.bigtext {
font-size: 200%;
border-bottom: 1px solid #999;
}
.button-container {
display: inline-block;
}
.button-container button {
font-size: 40%;
padding: 5px;
border-radius: 5px;
border: 1px solid #d3d3d3;
}
Fiddle: http://jsfiddle.net/7ydtgb7x/
If you want a really simple way to do this you can just add "position: relative;" and "bottom: 5px;" to your button.
If you need any help let me know by adding a comment. There are three kind of positions:
Relative which follows the flow.
Absolute that almost follows the flow.
And Fixed which gets completely out of any flow.
.bigtext {
font-size: 200%;
border-bottom: 1px solid #999;
}
.button-container {
display: inline-block;
}
.button-container button {
font-size: 40%;
padding: 5px;
border-radius: 5px;
border: 1px solid #d3d3d3;
position: relative;
bottom: 5px;
}
<div class="bigtext">
Test
<div class="button-container">
<button>Button</button>
</div>
</div>
for a quick fix:
transform:translateY(-5px);
fiddle
Here is a possible solution for you:
wrap your Test with a div, then both child's of .bigtext are (already) displayed inline-block, just make sure they are vertical-align:top.
Align vertical as well the button like this:
.button-container button { vertical-align:top}
Finally "reset" the line-height for your container .bigtext with: line-height:1
Here is a snippet with full code:
.bigtext {
font-size: 200%;
border-bottom: 1px solid #999;
line-height: 1
}
.bigtext > div {
display: inline-block;
vertical-align: top;
}
.button-container button {
font-size: 40%;
padding: 5px;
border-radius: 5px;
border: 1px solid #d3d3d3;
vertical-align: top
}
<div class="bigtext">
<div class="text-container">Test</div>
<div class="button-container">
<button>Button</button>
</div>
</div>
Use either transform: translateY(-10px); or margin-bottom: 10px;
hey i have a user info div that have user pic ,user name , user bio divs , now i want to user pic to left side and Name & bio is other side ,
Html
<div class="user-info">
<div class="user-pic">
<img src="" class="u-pic"/>
</div>
<div class="user-name">Jon Doe</div>
<div class="user-bio">I am a english teacher</div></div>
Jsfiddle
After doing this all divs have same height but i want name div to be in top and bio div should in bottom of name div .
thanks
Remove float property from user-name class
.user-info {
width: 500px;
height: 100px;
border: 1px solid #DFDFDF;
box-shadow: 0px 1px 1px #aaa;
float: left;
padding:15px
}
.user-pic {
float: left;
width: 80px;
height: 80px;
border: 1px solid #DFDFDF;
margin-right:15px;
background:blue;
}
.user-name {
//float: left;
font-size: 19px;
color: #333;
margin-right:15px;
}
.user-bio{
float: left;
font-size: 19px;
color: #333;
}
I am making a little layout width exactly 6 divs, and I tried various times to align it with float align, clear:both and changing height/width, but without success. I want something like this image: http://i.stack.imgur.com/j1jxX.png
HTML source:
<div id="description">
<div class="itemDescription"><!--Item 1-->
<div class="imageDescription"></div>
<div class="textDescription">
<div class="titleDescription">Encontre pessoas</div>
<div class="detailDescription">Encontre facilmente pessoas com um buscador inteligente</div>
</div>
</div>
<div class="itemDescription"><!--Item 2-->
<div class="imageDescription"></div>
<div class="textDescription">
<div class="titleDescription">Encontre pessoas</div>
<div class="detailDescription">Encontre facilmente pessoas com um buscador inteligente</div>
</div>
</div>
CSS source:
#description {
width: 96%;
background: rgb(244, 244, 0);
}
.itemDescription {
padding: 8px;
border: solid 1px red;
}
.imageDescription {
float: left;
height: 72px;
width: 20%;
background-image: url(http://addons.opera.com/media/extensions/75/86675/1.0-rev2/icons/icon_64x64.png);
background-position: center center;
background-repeat: no-repeat;
border-right: solid 3px black;
}
.textDescription {
float: left;
width: 70%;
border: solid 3px blue;
}
.titleDescription {
border: solid 3px brown;
}
.detailDescription {
border: solid 3px black;
padding: 10px;
}
here is my JSFiddle: http://jsfiddle.net/5xhQk/
Thanks too all you
You could also use table to get what you want but if you really want to use div, you need to use float in every div. Something like this: http://jsfiddle.net/5xhQk/1/
#description{
float: left;
width: 100%;
}
.itemDescription{
float: left;
width: 100%;
height: 72px;
}
.imageDescription{
background: blue;
float: left;
width: 20%;
height: 100%;
border: 1px solid black;
}
.textDescription{
float: left;
width: 70%;
height: 100%;
border: 1px solid black;
border-left: 0;
}
.titleDescription{
float: left;
width: 100%;
border-bottom: 1px solid black;
}
.detailDescription{
float: left;
width: 100%;
}
Oh and I dont understand why in your picture it is width 20% and 70%, what are u going to do with the rest 10%?
Let me see if i got it, u want to align the imageDescription and textDescription in the itemDescription
Try somethign like:
HTML:
<div class="itemDescription">
<div class="imageDescription ">
Your image
</div>
<div class="cl"> </div>
<div class="textDescription">
some header
some paragraph
</div>
</div>
CSS:
.cl{
clear:both;
}
.itemDescription {
width: something;
}
.imageDescription {
float: left;
width: something;
}
.textDescription {
float: right;
width: something;
}
this is small code for side menu of my page
<div style="display: block;" id="overlay" class="overlay">
<div id="sideMenuGroups">
<div id="sideMenuGroupHeader" class="mSideMenuSeparator">GROUPS</div>
<div id="sideMenuGroupContent" class="mSideMenuContent">
<div id="teacherGroup">As Teacher
<a onclick="groupFeeds();" href="#">Data Mining</a>
<a onclick="groupFeeds();" href="#">Data Structures</a>
<a onclick="groupFeeds();" href="#">C Language</a>
//**display anchor tag to full width of overlay**
<a onclick="groupFeeds();" href="#">Introduction to IT</a>
</div>
</div>
</div>
</div><!--overlay ends here-->
the css for the styles used is
*mSideMenuConten*t has no style defined
mSideMenuContent a- tells how each anchor tag would be visible, i have tried display:table-cell property, but it is not effective for me
overlay tells how the side menu would be
.mSideMenuContent
{
}
.mSideMenuContent a
{
display: table-cell;
height: 37px;
color: #c4ccda;
padding: 3px 0 3px 8px;
font-size: small;
}
.mSideMenuContent a:hover
{
background:#262c3a;
color: #c4ccda;
}
.mSideMenuSeparator
{
background: #434b5c;
border-top: 1px solid #242a37;
border-bottom: 1px solid #242a37;
font-family:Helvetica, sans-serif;
font-size:x-small;
color: #7a8292;
height:17px;
padding-top:4px;
padding-left: 10px;
text-shadow: 0 1px 0 rgba(0, 0, 0, .6)
}
.overlay {
z-index: 1000;
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 50%;
height: 100%;
background:#31394a;;
color: #c4ccda;
display: none;
}
i want to display the anchor tag to full width of the side menu, how do i do that??
Use this:
display:inline-block;
width: 100%;
By saying inline block, you allow yourself to define a width for the element. Inline elements can't do this be default.
I found display block more convenient. I applied some margin and padding and i got cool/desired output.
display:block;
padding: some padding;
margin: some margin;