How to make a split left-right text on two lines? - html

Need to center this text in this way:
Basically, the top part to the left and the bottom part to the right, but with a bit of overlap.
How can I do that in HTML/CSS?

You can center the text vertically by using the centering with transform technique. Then the text should be separated into two lines and aligned to left/right plus a small negative margin so it overflows outside of the circle.
div {
height: 130px;
width: 130px;
background: lightblue;
position: relative;
border-radius: 50%;
}
p {
position: absolute;
top: 50%;
transform: translateY(-50%);
margin: 0;
width: 100%;
}
span {
display: block;
}
span:first-of-type {
text-align: left;
margin-left: -7px;
}
span:last-of-type {
text-align: right;
margin-right: -7px;
}
<div>
<p>
<span>La crèativitè</span>
<span>est contagieuse</span>
</p>
</div>

Simply use 2 elements for those 2 lines and add a margin-left to the second element:
.logo p {
margin: 0;
}
.logo p:nth-of-type(2) {
margin-left: 3.5em;
}
/* for demonstration purpose only */
html {
font-size: 40px;
font-family: Arial;
}
<div class="logo">
<p>La crèativitè</p>
<p>est contagieuse</p>
</div>

Another entirely different (and more complicated) approach is to use flex-box. It requires you to use containers and to know the principles of flex-box. But once you know what you're doing, it becomes fairly simple to center things inside of other things.
If you need somewhere to practice flex-box with simple games, you can visit https://flexboxfroggy.com/.
.container {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
background-color: gray;
}
.logo {
width: 200px;
height: 200px;
background-color: maroon;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
p {
font-size: 20px;
}
#p1 {
align-self: flex-start;
}
#p2 {
align-self: flex-end;
}
<div class="container">
<div class="logo">
<p id="p1">La crèativitè</p>
<p id="p2"> est contagieuse</p>
</div>
</div>
Bonne Chance!

Related

Stuck. Trying to use CSS to left, center, and right text within a Header tag [duplicate]

This question already has answers here:
Stuck. How do I center and space out these 3 texts? [duplicate]
(3 answers)
Closed 8 months ago.
Trying to left/center/right these 3 spans of text within a HEADER tag? No luck, please see picture.
<body>
<header>
<span>503.984.9317</span>
<span>beller.jeff#gmail.com</span>
<span>portland, or</span>
</header>
body {
background-color: pink;
}
header {
background-color: green;
width: 600px;
height: 40px;
margin: auto;
}
span {
background-color: yellow;
}
Using flexbox should do the work quite efficiently but in case you don't want to use it and rely on positioning only.
body {
background-color: pink;
}
header {
background-color: green;
width: 600px;
height: 40px;
margin: auto;
}
span {
background-color: yellow;
}
.info {
position: relative;
}
.info>* {
position: absolute;
display: inline-block;
}
.info span:nth-child(3) {
right: 0;
}
.info span:nth-child(2) {
left: 50%;
-webkit-transform: translateX(-50%);
transform: translateX(-50%)
}
.info span:nth-child(1) {
left: 0;
}
<header>
<div class="info">
<span>503.984.9317</span>
<span>beller.jeff#gmail.com</span>
<span>portland, or</span>
</div>
</header>
I would suggest you to use flexbox as it is the optimum way to position items.
But as you don't want to use flexbox, I found an alternative way to position your elements using floats. NOTE: this is not recommended to use.
I am just showing an alternative way just for you.
body {
background-color:pink;
}
header{
background-color:yellow;
padding:5px;
text-align:center;
}
span{
display:inline-block;
padding:0px 20px;
}
.span1{
float:left;
}
.span3{
float:right;
}
<header>
<span class="span1"><p>503.984.9317</p></span>
<span class="span2"><p>beller.jeff#gmail.com</p></span>
<span class="span3"><p>portland, or</p></span>
</header>
Add this style to your header class and check the output.
header {
display: flex;
align-items: center;
justify-content: space-between;
}
Best ally for these cases in CSS can certainly be the flexbox and its amazing properties. Go ahead and take a look at this approach playing with the flex container (header) and its children(spans) known as flex items in FlexBox. Read more on Flexbox in this article.
body {
background-color: pink;
}
header {
background-color: green;
width: 600px;
height: 40px;
display: flex;
justify-content: space-between;
align-items: center;
margin: 0 auto;
}
span {
background-color: yellow;
width: 33.33%;
height: 100%;
justify-content: center;
display: inline-flex;
align-items: center;
padding: 0px 10px 0px;
}
span:first-child {
justify-content: flex-start;
}
span:last-child{
justify-content: flex-end;
}
<header>
<span>503.984.9317</span>
<span>beller.jeff#gmail.com</span>
<span>portland, or</span>
</header>

Any way for leader dots to extend from inside the text?

I think it's best to explain with the image above, is there a way to make the dots extend all the way to the volume? Whatever I try the text on the left is inside a block with a set width so the dots are contained inside of it and I can't use a white background to only cover the text area.
Codepen
.two-line-menu-item {
width: 100%;
text-align: left;
}
.two-line-menu-item__title {
color: #4ca099;
}
.two-line-menu-item-info {
display: flex;
justify-content: space-between;
align-items: flex-end;
}
.two-line-menu-item-info__type-vol {
max-width: 70%;
padding-right: 0.33rem;
background-color: white;
}
.two-line-menu-item-info__price {
padding-left: 0.33rem;
background-color: white;
}
.dots {
position: relative;
z-index: -1;
top: -9px;
height: 3px;
border-top: 3px dotted;
}
<div class="two-line-menu-item">
<div class="title-text two-line-menu-item__title">Cappy Juices</div>
<div class="two-line-menu-item-info">
<span class="two-line-menu-item-info__type-vol">orange, apple, apricot, peach, black currant, smoothie 0.2 l</span>
<span class="two-line-menu-item-info__price">16 kn</span>
</div>
<div class="dots"></div>
</div>

Best way to arrange elements in div

So I want to build a simple event box, to replace the default one in a calendar (react-big-calendar for reference, but I don't think it matters)
I would like to make it as responsive as possible, but I have started with a very static box, which corresponds to what I would like to see on a big screen.
Simple fiddle
.container {
width: 200px;
height: 200px;
background-color: #dddddd;
margin: 20px;
padding: 5px;
}
.event-slot-component {
width: 100%;
min-height: 30px;
position: relative;
background-color: #64a7DD;
border: 5px;
border-radius: 3px;
padding: 2px;
}
.event-slot-start-time {
font-size: 0.75em;
vertical-align: top;
position: absolute;
top: 0;
left: 0;
}
.event-slot-end-time {
font-size: 0.75em;
float: left;
vertical-align: bottom;
position: absolute;
bottom: 0;
left: 0;
}
.event-slot-label {
font-size: 1em;
top: 8px;
right: 5px;
position: absolute;
}
<div class="container">
<div class="event-slot-component">
<div class="event-slot-start-time">17h</div>
<div class="event-slot-end-time">21h</div>
<div class="event-slot-label">Occupied Slot</div>
</div>
</div>
My goal is to have a 'centered, eventually slightly to the right' label,
and two small indications on the left that correspond to the start and end of the event.
I have tried using flexbox, coming from other StackOverflow answers, and it does seem to be able to do that somehow, but I have not managed to display the three elements properly. Any insight on a clean solution to achieve this result?
The simplest with the existing markup is to use Flexbox with column direction on the 2 date values and then position the label absolute using transform
.container {
width: 200px;
height:200px;
background-color: #dddddd;
margin: 20px;
padding: 5px;
}
.event-slot-component {
width: 100%;
min-height: 30px;
position: relative;
background-color: #64a7DD;
border: 5px;
border-radius: 3px;
padding:2px;
display: flex;
flex-direction: column;
}
.event-slot-start-time,
.event-slot-end-time {
font-size: 0.75em;
flex-grow: 1; /* share the vertical space equal */
}
.event-slot-label {
position:absolute;
font-size: 1em;
top: 50%;
left: calc(50% + 10px); /* adjust px value for horiz. offset */
transform: translate(-50%,-50%); /* vert./hor. center the label */
}
<div class="container">
<div class="event-slot-component">
<div class="event-slot-start-time">17h</div>
<div class="event-slot-end-time">21h</div>
<div class="event-slot-label">Occupied Slot</div>
</div>
</div>
If you want a good responsive solution, use Flexbox all the way, here with a wrapper for the date's
.container {
width: 200px;
height:200px;
background-color: #dddddd;
margin: 20px;
padding: 5px;
}
.event-slot-component {
width: 100%;
min-height: 30px;
position: relative;
background-color: #64a7DD;
border: 5px;
border-radius: 3px;
padding:2px;
display: flex;
}
.event-slot-time {
display: flex;
flex-direction: column;
}
.event-slot-start-time,
.event-slot-end-time {
font-size: 0.75em;
flex-grow: 1; /* share the vertical space equal */
}
.event-slot-label {
flex-grow: 1; /* fill the remaining horizontal space */
font-size: 1em;
display: flex;
align-items: center; /* vertical center the label text */
justify-content: center; /* horizontal center the label text */
}
<div class="container">
<div class="event-slot-component">
<div class="event-slot-time">
<div class="event-slot-start-time">17h</div>
<div class="event-slot-end-time">21h</div>
</div>
<div class="event-slot-label">Occupied Slot</div>
</div>
</div>
You would need to nest your flexboxes. That's what's so wonderful about it!
To explain, what I did was created three wrappers.
One to hold the entire event.
One to hold your event times.
One to hold the status.
We used flex box to butt the event times and status-wrapper against each other. The event times only take up as much space as the text utilizes (plus a little padding). The status wrapper takes up 100% of its usable space.
Then status wrapper is set to flex box using the justify-content and align-items properties. This centers the status.
The status text container is used in the same way to center the status text itself.
.event-wrapper {
background-color: #eee;
display: flex;
}
.event-times-wrapper {
background-color: skyblue;
padding-left: 0.5rem;
padding-right: 0.5rem;
}
.status-wrapper {
width:100%;
display: flex;
align-items:center;
justify-content: center;
}
.status-text {
height: 100%;
display:flex;
align-items: center;
padding-left: 1rem;
padding-right: 1rem;
background-color: tomato;
}
<article class="event-wrapper">
<div class="event-times-wrapper">
<p class="event-start">9:00a</p>
<p class="event-end">10:00a</p>
</div>
<div class="status-wrapper">
<div class="status-text">Busy</div>
</div>
</article>
As OP requested later, a sample without special containers.
.container {
background-color: #eee;
position: relative;
width: 100vw;
height:6rem;
}
.event-slot-component div {
font-family: sans-serif;
color: white;
background-color: skyblue;
height:3rem;
float:left;
padding-left: 1rem;
padding-right: 1rem;
width:10%;
display:flex;
align-items:center;
justify-content:center;
}
.event-slot-component div:nth-child(2) {
background-color:red;
position:absolute;
bottom:0;
left: 0;
}
.event-slot-component div:last-of-type {
margin-left:25%;
background-color: tomato;
float:left;
height: 6rem;
}
<div class="container">
<div class="event-slot-component">
<div class="event-slot-start-time">17h</div>
<div class="event-slot-end-time">21h</div>
<div class="event-slot-label">Occupied Slot</div>
</div>
</div>

I want to align a logo at the center of the screen and display few lines right after the image.But the text is coinciding with the image

This is my HTML code:
<img class="centeredimage" src="BLACK.jpg"><br><br>
<p align="center" class="new"><b><span class="main_text">This is regarding....</span></b><br><br>
<span class = "a2017">Welcome to 2017</span><br><br>
<span class="coming_soon">Coming Soon</span></p><br><br>
This is my CSS code:
.centeredimage {
position: absolute;
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -100px;
width: 200px;
height: 200px;
}
.new{
color:#FFFFFF;
}
.main_text{
font-size:20px;
letter-spacing: 8px;
}
.a2017{
font-size:15px ;
letter-spacing:2px ;
}
.coming_soon{
letter-spacing: 1px;
}
The image is aligned at center of the screen but the text instead of getting displayed after the image is displayed coinciding with the image.How do I make it come after the image so that both are aligned at middle of the screen at center?
Try this
.centeredimage {
display : block;
width: 200px;
margin: auto;
...
I use this code to center things in the middle of the screen, for example, a loader. It can have multiple parts, it doesn't matter. You just put all the parts into one div. I used to use the "margin" trick, and still do here and there, but these days I'm using the table/tablecell thing to get the job done. It works everywhere, phones etc. (note I don't deal with 10-year-old browsers). Below is some code straight from an instructional sample:
<style>
.app_style {
width: 100%;
height: 100%;
display: table;
}
.loader_style {
display: table-cell;
text-align: center;
vertical-align: middle;
}
.loader_icon_style {
border: 2px solid lightgray;
border-radius: 5px 5px 5px 5px;
}
.loader_bar_padding {
padding-top: 10px;
}
.loader_blurb {
width: inherit;
text-align: center;
font-size: 14px;
font-weight: bold;
color: yellow;
font-style: italic;
}
</style>
</head>
<body>
<sample-app class="app_style">
<div class="loader_style">
<img class="loader_icon_style" src="assets/images/r2-d2.jpg" />
<div class="loader_blurb loader_bar_padding">
May the force be with you...
</div>
<img class="loader_bar_padding" src="assets/images/loader-bar.gif" />
</div>
</sample-app>
</body>
If you want center the image and the text, not align only the image otherwise the text follow an other logic on the DOM, mostly if you use the absolute position for the image and not for the text.
You can use a wrapper div aligned to the center and put all content in it.
body {
background-color:#ff00ff;
}
.wrapper {
position: absolute;
top: 50%;
left: 50%;
margin-top: -150px;
margin-left: -100px;
width: 200px;
height: 300px;
}
.your_image {
width: 200px;
height: 200px;
}
.new {
color: #FFFFFF;
}
.main_text {
font-size: 20px;
letter-spacing: 8px;
}
.a2017 {
font-size: 15px;
letter-spacing: 2px;
}
.coming_soon {
letter-spacing: 1px;
}
<div class="wrapper">
<img class="your_image" src="https://upload.wikimedia.org/wikipedia/en/thumb/8/80/Wikipedia-logo-v2.svg/1122px-Wikipedia-logo-v2.svg.png"><br><br>
<p align="center" class="new"><b><span class="main_text">This is regarding....</span></b><br><br>
<span class="a2017">Welcome to 2017</span><br><br>
<span class="coming_soon">Coming Soon</span></p><br><br>
</div>
I prefer to use Flexbox. It simplifies a lot of the coding you need to do.
In your situation, just wrap your HTMl code in a div and make this your CSS:
div{
display: flex;
flex-direction: column;
justify-content: center;
}
.centeredimage {
display: block;
margin: 0 auto;
width: 200px;
height: 200px;
}

How do I responsively center text inside of a <div>

I have a <div> that contains three <div>s.
In each of those <div> elements is a <p> element with text and 2 nested elements to make a radial progress bar. What I need is to put the text in the middle of the circles, and do it responsively using pure CSS. I need something like this:
The code has flaws, like that <p> inside of a <span> but I am fixing it in the new version with the help you guys provide.
.radius-container div {
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
}
.radius-container div:first-child {
margin-right: 1%;
}
.radius {
padding-top: 11em;
height: 30em;
text-align: center;
border: 1px solid #858280;
display: block;
border-radius: 50%;
width: 100%;
}
.radius3 {
position: relative;
padding-top: 10%;
height: 15em;
width: 50%;
text-align: center;
border: 1px solid #858280;
border-left: 0;
border-bottom: 0;
border-top-right-radius: 100%;
display: block;
margin-left: 15em;
}
.radius3 p {
position: absolute;
right: 50%;
top: 65%;
}
<div class="radius-container">
<div><span class="radius"><p>SERBIAN<br>100%</p></span></div>
<div><span class="radius"><p>ENGLISH<br>100%</p></span></div>
<div><span class="radius3"><p>GERMAN<br>25%</p></span></div>
</div>
See also this jsFiddle
After researching for long time for this issue, I found an generic solution which solves this kind of requeriments. I am proud of it, simple and elegant :)
.center-element{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
Hoping it helps, any doubt let me know. Cheers mate :)
This code might help you.
.innerDiv {
height: 100px;
width: 100px;
display: table-cell;
text-align: center;
vertical-align: middle;
border-radius: 50%;
}
You can make a div with a border-radius to 50%. After, you can use the flex display to center verticaly and horizontaly.
html
div {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
div div {
display: inline-flex;
flex-direction: column;
width: 31%;
margin: 1%;
border-radius: 50%;
border: 1px solid #999;
align-items: center;
justify-content: center;
}
div div span {
text-align: center;
color: #999;
}
<div>
<div><span>Serbian</span><span>100%</span>
</div>
<div><span>Serbian</span><span>50%</span>
</div>
<div><span>Serbian</span><span>25%</span>
</div>
</div>