Making an arrow and a column using Css [duplicate] - css

This question already has answers here:
How do CSS triangles work?
(23 answers)
Closed 11 months ago.
I have a task to do the following figure. but I don't know how to design the arrow alongside the column.
my code:
p {
background-color: #eee;
padding: 20px;
margin-left: 110px;
width: 400px;
}
p::before {
content: attr(data-person);
background-color: #ddd;
position: absolute;
left: 5px;
margin-top: -15px;
padding: 15px;
display: inline-block;
width: 45px;
text-align: center;
}
p::after {
content: "";
background-color: #e84747;
padding: 5px;
height: 48.56px;
position: absolute;
left: 108px;
margin-top: -20px;
}
<p class="one" data-person="Osama">This Is Very Very Long Comment Number One</p>
<p class="two" data-person="Ahmed">This Is Very Very Long Comment Number Two</p>
<p class="three" data-person="Sayed">This Is Very Very Long Comment Number Three</p>
I used my before and after properties, if I do the arrow I won't do the column and vice versa.

Easiest way is to put a left border on the p and that frees up the ::after pseudo element for the triangle. Make sure you put position: relative on the p and then all the position: absolutes are based on that.
The actual triangle is created by making a series of borders transparent and one colors, and with the same size (to make a square).
The way this all works is that the borders meet at the corners as mitres (like a picture frame) and so when all of them are the same - its as if there is a square with 4 inward facing trangles and only one of the m has the color - hence the colored triangle.
p{
background-color: #eee;
padding: 20px;
margin-left: 110px;
width: 400px;
border-left: solid 5px #e84747;
position: relative;
}
p::before{
content:attr(data-person);
background-color: #ddd;
position: absolute;
left: -110px;
margin-top: -15px;
padding: 15px;
display: inline-block;
width: 45px;
text-align: center;
}
p::after{
content: "";
position: absolute;
left: -15px;
top: calc(50% - 10px);
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-right:10px solid #e84747;
}
<p class="one" data-person="Osama">This Is Very Very Long Comment Number One</p>
<p class="two" data-person="Ahmed">This Is Very Very Long Comment Number Two</p>
<p class="three" data-person="Sayed">This Is Very Very Long Comment Number Three</p>

Related

Using CSS only to position 3 elements equally around a circle [duplicate]

This question already exists:
Calculate position of 3 absolutely positioned elements [duplicate]
Closed 2 years ago.
I am trying to position 3 elements around a circle using CSS only. I have nudged the elements into position by eye, but I am assuming there is a mathematical (PLEASE NOTE: mathematical, NOT programatic) way to determine the top and left numbers for each of the three elements.
The motive here is that I will be rotating the entire block, and the elements should be in the same position after each rotation.
#rotator {
position: relative;
border: 1px solid red;
width: 100px;
height: 100px;
border-radius: 50px;
margin-top: 20px;
}
#rotator div {
position: absolute;
border: 1px solid blue;
width: 24px;
height: 24px;
border-radius: 12px;
text-align: center;
background: rgba(255, 255, 255, 0.75);
}
#rotator div#a {
top: -12px;
left: 38px;
}
#rotator div#b {
bottom: 0;
right: 0;
}
#rotator div#c {
bottom: 0;
left: 0;
}
<div id="rotator">
<div id="a">a</div>
<div id="b">b</div>
<div id="c">c</div>
</div>
Unfortunately, you cannot do this without a preprocessor, for example SCSS. Thanks #Stef for the formula for the vertices of a regular triangle.
[CODE][1]
[1]: https://codepen.io/BlackStar1991/pen/xxVLMVG

How can I create a horizontal line with centered text and capped ends with CSS? [duplicate]

This question already has answers here:
Create a horizontal rule with text in the middle? [duplicate]
(5 answers)
Closed 3 years ago.
There are many questions (and answers) about how to create a heading with centered text and a horizontal line either side, but what I'd like to achieve is slightly different.
I'd like to add vertical lines to the left and right end of the lines:
I have got close to what I'd like using this code:
body {
padding: 50px;
}
div.outer {
width: 100%;
height: 15px;
border-top: 1px solid black;
border-right: 1px solid black;
border-left: 1px solid black;
text-align: center;
margin: auto;
position: relative;
}
div.outer>span {
font-size: 16px;
background-color: #FFF;
padding: 0 10px;
position: absolute;
top: -10px;
left: 47%;
}
<div class="outer">
<span>A Heading</span>
</div>
pen
Can anyone please point me in the right direction?
UPDATE
Thank you #nvioli for pointing me in the right direction. I ended up using a combination of your answer and flex based on this post
Here’s what worked for me: pen
I would suggest adding another div outside what you have there. You've done a nice job making the horizontal line and centering the text (which is the hard part IMO), so wrapping the whole thing in a bigger div (twice as tall) and moving the inner div down half the height seems to work.
Note I've renamed your outer div to inner and added a new outer.
body {
padding: 50px;
}
div.outer {
border-right: 1px solid black;
border-left: 1px solid black;
height:30px;
}
div.inner {
width: 100%;
height: 15px;
border-top: 1px solid black;
text-align: center;
margin: auto;
position: relative;
top:15px;
}
div.inner > span {
font-size: 16px;
background-color: #FFF;
padding: 0 10px;
position: absolute;
top: -10px;
left: 47%;
}
<div class="outer">
<div class="inner">
<span>A Heading</span>
</div>
</div>

How to vertical align element relative other element with pseudo-class? [duplicate]

This question already has answers here:
Vertically center two divs inside a wrapper (with dynamic content and content below the wrapper)
(4 answers)
Closed 7 years ago.
I have multiple boxes (items) with an item number and a description. I want to vertical align my item number regardless of the description height (using only HTML and CSS).
See this image for more info:
<div class="item">
<div class="item-number">1</div>
<div class="item-description">Text placeholder</div>
</div>
As you can see I have multiple boxes and the description text can have different lengths, so I can't absolute position my item number relative to the top.
Any one got any suggestions on how to achieve this?
you should position your number absolutely in order to achieve this. You could also minimalize markup by using a pseudo element, allowing you to do this with a single element.
I have also used a data-attr in order to allow you to dynamically alter the number within the div if you so wish.
Something like:
div {
width: 200px;
border: 5px solid lightgray;
box-shadow: 5px 5px 10px dimgray;
margin: 20px;
padding: 20px;
padding-left: 30px;
position: relative;
}
div:before {
content: attr(data-pointNum);
position: absolute;
top: 50%;
left: -5px;
box-sizing: border-box;
height: 40px;
width: 40px;
transform: translate(-50%, -50%);
text-align: center;
line-height: 30px;
border-radius: 50%;
border: 5px solid tomato;
background: white;
box-shadow: 5px 5px 10px dimgray;
}
<div data-pointNum="1">some text</div>
<div data-pointNum="2">some moretext
<br/>spanning multiple
<br/>lines</div>
Demo: http://jsfiddle.net/UI_Designer/xzmzpL4g/1/
.item{
border:1px solid #000;
padding:20px;
margin-left:20px;
position:relative;
margin-bottom:20px;
}
.item-number{
position: absolute;
left:-10px;
width:20px;
height:20px;
border:1px solid #ccc;
border-radius:50%;
text-align:center;
background:#FFF;
top: 40%;
transform: translate(-20%,0);
}
you can try this
$(document).ready(function() {
$('.item-number').css('top', ($('.item').height() / 2) + 'px');
});
.item-description {} .item {
border: 1px solid #000;
width: 150px;
padding-left: 20px;
}
.item-number {
position: absolute;
left: 5px;
width: 20px;
height: 20px;
border: 1px solid #ccc;
border-radius: 50%;
text-align: center;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="item">
<div class="item-number">1</div>
<div class="item-description">Text placeholder Text placeholder Text placeholder Text placeholder</div>
</div>
and this is demo
https://jsfiddle.net/0xf5hvej/
of course you will need more styling to achieve what you need but this is the basic

Underline heading - narrower line

I want to create something like this.
I'm realy tired, cuz i can create only line with similar width like heading. I have to create "smaller" line then heading. Tried done it with ::before, but it doesn't work for me. Is there any possible way to create it.
<h1>Some heading here</h1>
http://jsfiddle.net/53zxor2k/
h1 {
display: inline-block;
position: relative;
}
h1::after {
content: '';
position: absolute;
left: 10%;
display: inline-block;
height: 1em;
width: 70%;
border-bottom: 1px solid;
margin-top: 5px;
}
Change the width to how long you would like it to be, and the "left" to where the line is located, and increase the "margin-top" to make it farther away from the text.
http://jsfiddle.net/53zxor2k/1/
h1 {
position: relative;
text-align: center
}
h1:before{
content: '';
position: absolute;
left: 50%;
bottom: -6px;
width: 130px;
height: 2px;
background: red;
transform:translateX(-65px) /* width/2 */
}
<h1>some heading here</h1>
<h1>some <span style="border-bottom: 2px solid red;">heading</span> here</h1>
You can simply put a border under a specific word if that is what you are attempting to do.

DIV moves when I put text in it [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I spent some time creating a pedigree out of div layers on this site and I got it all nicely aligned.
But when I put text in it, whether just in the div or in p tags, it moves the div layer down significantly.
It doesn't seem to add any margin or padding or anything else I can see while inspecting the element, and it doesn't seem to be affecting the grandchild div layers.
JSFiddle
HTML:
<div id="pedigree">
<div id="parentwrap">
<div class="parent">test</div>
</div>
<div id="childwrap">
<div class="child">
<p>Am. Ch. Kenai's Aldebaran</p>
</div>
<div class="child">
<p>pAm. Ch. Santa Clara Del Viento</p>
</div>
</div>
<div id="grandchildwrap">
<div class="grandchild">Am. Can. Ch. Ryzann's Eclipse at Kenai</div>
<div class="grandchild">Am. Ch. Timber Ridge's Abi of Kenai</div>
<div class="grandchild">Am. Ch. Sky Run Gavril Virtual Zip JC</div>
<div class="grandchild">Am. Can. Ch. Tazeb's Zena</div>
</div>
</div>
CSS:
#pedigree {
position: relative;
width: 584px;
height: 204px;
margin: 0 auto;
margin-top: 15px;
padding-bottom: 15px;
border-bottom: 1px dotted black;
}
#parentwrap {
position: relative;
display: inline-block;
margin: 0;
width:auto;
height: 205px;
}
.parent {
position: relative;
width: 190px;
height: 202px;
margin: 0px;
padding: 0px;
border: 1px solid black;
}
#childwrap {
position: relative;
display: inline-block;
margin: 0;
width: auto;
height: 205px;
}
.child {
position: relative;
width: 190px;
height: 95px;
margin: 0px;
padding: 0px;
border: 1px solid black;
margin-bottom: 10px;
}
#grandchildwrap {
position: relative;
display: inline-block;
width: auto;
height: 205px;
}
.grandchild {
position: relative;
width: 190px;
height: 46px;
margin: 0px;
padding: 0px;
border: 1px solid black;
margin-bottom: 4px;
}
.parent, .child, .grandchild {
-moz-border-radius: 35px;
border-radius: 35px;
Adding the text creates a baseline for the #parentwrap div, so the div gets aligned to that. Without the text, there's no baseline so the div takes a fallback layout mode.
To fix, set add #parentwrap { vertical-align:top; }

Resources