How to horizontally align pseudo element with element and its container - html

I've been through some CSS practice lately. Let's say I have the following HTML/CSS code of a calendar web app you can see in my Codepen.
What I need is to have the ".day_body" element and the "+" pseudo element along with its white circle container horizontally aligned. Furthermore, I need that "+" to fit in the centre of the white circle. Unfortunately editing the HTML or using flexbox is not an option for now.
Any ideas on how to accomplish that?
<div class="calendar_plan">
<div class="day_title">Today</div>
<div class="day_body">19 May 2020</div>
<div class="day_add">
<span class="plus_sign"></span>
</div>
<div>
.calendar_plan {
background-color: teal;
color: #fff;
margin-top: 2rem;
margin-bottom: 4rem;
padding: 3rem;
clear: both;
overflow: hidden;
}
.day_title {
font-size: 2.2em;
font-weight: 800;
}
.day_body {
font-size: 2em;
float: left;
}
.day_add {
margin-left: 20px;
float: left;
}
.day_add:after {
display: block;
width: 4rem;
height: 4rem;
content: "\002B";
font-size: 4rem;
color: #999;
background-color: #fff;
border-radius: 50%;
line-height: 4rem;
}
.day_add:hover:after {
cursor: pointer;
}

Like already mentioned in the comment, adding text-align: center; to .day-add helps to align the plus sign.
To horizontally align the the date with the circle, you could increase the line-height of the .day_body to the half of the line-height of the circle (4em): line-height: 2em;. Nevertheless this moves the date a little bit 'down'. Is that fine?
Alternatively you could use absolute positioning of the circle.
.calendar_plan {
background-color: teal;
color: #fff;
margin-top: 2rem;
margin-bottom: 4rem;
padding: 3rem;
clear: both;
overflow: hidden;
}
.day_title {
font-size: 2.2em;
font-weight: 800;
}
.day_body {
font-size: 2em;
float: left;
line-height: 2em;
}
.day_add {
margin-left: 20px;
float: left;
text-align: center;
}
.day_add:after {
display: block;
width: 4rem;
height: 4rem;
content: "\002B";
font-size: 4rem;
color: #999;
background-color: #fff;
border-radius: 50%;
line-height: 4rem;
}
.day_add:hover:after {
cursor: pointer;
}
<div class="calendar_plan">
<div class="day_title">Today</div>
<div class="day_body">19 May 2020</div>
<div class="day_add">
<span class="plus_sign"></span>
</div>
<div>

Related

How can I center text just above the corresponding image?

I have two images and two links. The problem is that the links come down of image. Like in the pictures
.motto {
font-size: 25px;
font-weight: bold;
line-height: 30px;
color: red;
text-align: center;
}
/*
.choiceImage a {
display: contents;
}*/
.choiceImage {
margin: 10px;
width: 790px;
height: 600px;
}
.choiceImage img {
width: 350px;
height: 350px;
margin: 20px;
border-radius: 2px;
display: inline-block;
}
.choiceImage div {
display: flex;
justify-content: space-around;
}
.choiceImage p {
background-color: beige;
border-radius: 10px;
color: black;
width: 270px;
font-size: 25px;
font-weight: bold;
text-align: center;
}
.choiceImage img:hover {
opacity: 0.5;
}
<div class="choiceImage">
<div>
<p>I'm looking for..</p>
<p>I offer something..</p>
</div>
<img alt="want something" src="image/want-something.jpg">
<img alt="offer something" src="image/offer-something.jpg">
</div>
I can fix that with display:context; for the link, but I want another answer for this problem.
The display: contents is expected to inherit from its grandparent choiceimage which is not set here so by default it is set to display: block.
Set the styles for the links like this:
.choiceImage a {
display: inline-block;
}
But I highly recommend using FlexBox, it is really efficient for lay-outing and also for responsive development.

Inline display of div tags

I am trying to get 2 div tags to be inline with each other. When I did use display: inline-block it doesn't format correctly.
What I am trying to achieve see image
Code:
.packaging_details {
display: block;
border: solid 1px #000;
padding: 10px;
width: 95%;
margin-left: auto;
margin-right: auto;
margin-top: 30px;
margin-bottom: 30px;
}
.heading_texts {
text-transform: uppercase;
font-weight: bold;
font-size: 14px;
text-align: center;
display:inline-block;
}
.Subheading2 {
text-align: center;
font-size: 14px;
text-transform: uppercase;
}
.Subheading1 {
font-weight: bold;
text-transform: uppercase;
text-align: right;
display:inline-block;
}
<div class="packaging_details">
<div class="heading_texts">Company Name</div>
<div class="Subheading1">LABEL</div>
<div class="Subheading2">
<span class="logids">Name:</span> ###
</div>
</div>
It is always good to wrap parts that are supposed to look differently into seperat containers so you can position them differently. Your Problem here is most likely, that "heading_texts", "Subheading1" and "Subheading2" are on the same Layer / in the same position so they will behave similar in the parent Container.
I can offer you one solution: CSS Flex.
The code for that:
.packaging_details {
display: block;
border: solid 1px #000;
padding: 10px;
width: 95%;
margin-left: auto;
margin-right: auto;
margin-top: 30px;
margin-bottom: 30px;
}
.heading_texts {
text-transform: uppercase;
font-weight: bold;
font-size: 14px;
text-align: end;
width: 55%;
}
.Subheading2 {
text-align: center;
font-size: 14px;
text-transform: uppercase;
}
.Subheading1 {
font-weight: bold;
text-transform: uppercase;
text-align: end;
width: 45%;
}
.inline-container{
display: flex;
flex-direction: row;
text-align: center;
justify-content: center;
}
<div class="packaging_details">
<div class="inline-container">
<div class="heading_texts">Company Name</div>
<div class="Subheading1">LABEL</div>
</div>
<div class="Subheading2">
<span class="logids">Name:</span> ###
</div>
</div>
The Only thing you have to be aware of, is that you position the content of the Line by defining the widths of the 2 containers here, so if you want the logo to be more centered you need to play around with the with of both containers, they always need to sum up to 100% width!
You can use flex box as below.
The only challenge by doing it this way is to center align the Subheading2 below heading_text, one way is to set flex-basis 100% of the box width - the width of the Subheading1 element.
This solution is for the case when you don't have access or not able to change html structure but if you can change the html structure that can be easily styled with flex-box.
.packaging_details {
display: flex;
flex-wrap: wrap;
border: solid 1px #000;
padding: 10px;
width: 95%;
margin-left: auto;
margin-right: auto;
margin-top: 30px;
margin-bottom: 30px;
}
.heading_texts {
flex: 1;
text-transform: uppercase;
font-weight: bold;
font-size: 14px;
text-align: center;
}
.Subheading2 {
flex-basis: calc(100% - 55px);
text-align: center;
font-size: 14px;
text-transform: uppercase;
}
.Subheading1 {
font-weight: bold;
text-transform: uppercase;
text-align: right;
}
<div class="packaging_details">
<div class="heading_texts">Company Name</div>
<div class="Subheading1">LABEL</div>
<div class="Subheading2">
<span class="logids">Name:</span> ###
</div>
</div>

How to move specific text upwards within same div?

I have 1 div with two separate sections of text. However, one of these sections of text is smaller than the other, leaving it slightly lower than the other section.
I would like it to be centered both vertically and horizontally within the div - inline with the larger text... margin-bottom is not working, however margin-left and margin-right are... how do I do this? Thankyou.
.portfolioHeader {
position: relative;
font-family: coolfont;
top: 20px;
font-size: 55px;
color: black;
margin-left: 70px;
text-align: left;
}
a.miniheader {
text-decoration: none;
margin-left: 20px;
}
span.smallerish {
font-size: 35px;
color: #3F3F3F;
text-decoration: none;
}
<div class="portfolioHeader"><a class="header" href="http://www.coopertimewell.com/portfolio">Portfolio ><a class = "miniheader" href="http://www.coopertimewell.com/portfolio/website-design"><span class = "smallerish">di Matteos</span></a></a>
</div>
This is how I would do it:
Fix invalid html
Put the font sizes on the anchors
Vertical align the anchors
If you want the text horizontally centered, then use text-align center on the div (instead of left with margin)
.portfolioHeader {
position: relative;
font-family: coolfont;
top: 20px;
color: black;
text-align: center;
}
a.header {
font-size: 55px;
vertical-align:middle;
}
a.miniheader {
font-size: 35px;
text-decoration: none;
margin-left: 20px;
vertical-align:middle;
}
span.smallerish {
color: #3F3F3F;
text-decoration: none;
}
<div class="portfolioHeader">
<a class="header" href="http://www.coopertimewell.com/portfolio">Portfolio ></a>
<a class="miniheader" href="http://www.coopertimewell.com/portfolio/website-design"><span class = "smallerish">di Matteos</span></a>
</div>
Set vertical property of anchor tag
.portfolioHeader a
{
vertical-align: middle;
}
You need to vertical-align the 'a' tags.
This css should help.
.portfolioHeader {
color: black;
display: table;
font-family: coolfont;
font-size: 55px;
margin-left: 70px;
position: relative;
text-align: left;
top: 20px;
vertical-align: middle;
}
a {
display: table-cell;
text-align: center;
vertical-align: middle;
}
a.miniheader {
left: 30px;
position: relative;
text-decoration: none;
top: -5px;
}
span.smallerish {
color: #3f3f3f;
font-size: 35px;
text-decoration: none;
}

I am trying to make a responsive rectangle with an image to the left inside and text centered

I am trying to make a responsive tweet button with the twitter bird floated left, the text next to it and centered.
My code is:
.flex-rectangle {
float: left;
margin: 0 5px;
max-width: 500px;
text-align: center;
width: 200%;
background: #FFFFFF;
border: 7px solid #00A5EF;
}
/* Styles Twitter Bird png */
.image-wrapper {
padding-top: 10%;
position: relative;
width: 100%;
padding-bottom: 10%;
}
img .tweet {
float: left;
}
/* Tweet This: */
.span-content {
display: block;
color: #00A5EF;
}
.span {
display: block;
text-align: center;
font-family: OpenSans;
font-size: 36px;
color: #00A5EF;
}
<div class="flex-rectangle">
<div class="image-wrapper">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/281152/Twitter_bird_logo_2012.svg" class="tweet" />
</div>
</div>
<div id="buttons">
<div class="span-content">
<span>Tweet This</span>
</div>
</div>
CSS
I've tried pretty much everything under the sun.
I can't seem to get the rectangle to shrink and widen when I resize the page or go into Dev Tools and use the mobile device pane.
I understand CSS less than I do JavaScript at this point. Not sure if I should use flexbox in this instance or how I would do that.
Here is the CodePen
you can use quotes using pseudo element ::before and a::after
Thank you. This works for the most part. However I can't get the
twitter bird to float left and the text to be beside it. Any
suggestions?
I used flexbox the text will be next to the twitter button on desktop view, and below on mobile view.
#import url(https://fonts.googleapis.com/css?family=Open+Sans|Satisfy);
/*Styles for whole page */
img {
max-width: 100%;
border: 7px solid #00a5ef;
}
#page-wrap {
display: flex;
flex-wrap: wrap;
justify-content: center
}
h1 {
font-weight: bold;
text-transform: uppercase;
font-size: 30px;
margin-top: 50px;
width: 300px;
line-height: 1;
font-family: 'Open Sans', sans-serif;
color: #1485C7;
text-align: center;
letter-spacing: 0;
}
/* On: */
h1 .center {
text-transform: capitalize;
font-weight: normal;
font-family: "Satisfy";
vertical-align: text-bottom;
line-height: 10px;
color: #1485C7;
}
h1 .bigger {
font-size: 46px;
color: #1485C7;
display: block
}
/* Rectangle 1: */
.flex-rectangle {
background: #fff none repeat scroll 0 0;
flex: 1 15%;
margin: 0 15%;
max-width: 300px;
padding: 10px;
position: relative;
quotes: "\201C""\201D";
text-align: center;
top: 0;
}
.flex-rectangle::before {
color: #00a5ef;
content: open-quote;
font-family: Georgia;
font-size: 25vw;
left: -15vw;
position: absolute;
top: 50%;
}
.flex-rectangle::after {
color: #00a5ef;
content: close-quote;
font-family: Georgia;
font-size: 25vw;
position: absolute;
right: -15vw;
top: 50%;
}
.text {
align-self: flex-end
}
.span-content {
display: inline-block;
color: #00A5EF;
margin: 0 auto;
padding: 5px;
border: 3px solid #00A5EF;
}
<div id="page-wrap">
<div class="flex-rectangle">
<div class="heading">
<h1>Random Quotes<span class="center">On</span><span class="bigger">Design</span></h1>
</div>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/281152/Twitter_bird_logo_2012.svg" class="tweet" />
<div id="buttons">
<div class="span-content">
Tweet This
</div>
</div>
</div>
<div class="text">
<h1>Random Quotes</h1>
</div>
</div>
you have to place the bird and the text to one div and code for the image element in order to code for the image part you have to call first the first parent div and other div in one code where the image element is located .flex-rectangle .image-wrapper imgto edit the code for image. and also you have to insert the html code for <span>Tweet This</span> inside the .image-wrapper to make the image go left and your text go center.
CSS CODE :
.flex-rectangle {
float: left;
margin: 0 5px;
max-width: 500px;
text-align:center;
width: 200%;
background: #FFFFFF;
border: 7px solid #00A5EF;
}
/* Styles Twitter Bird png */
.image-wrapper {
padding-top: 10%;
position: relative;
margin: auto;
max-width: 125;
max-height: 50px;
width: 100%;
padding-bottom: 15%;
}
.flex-rectangle .image-wrapper img {
float: left;
max-width: 50px;
max-height: 50px;
width: 100%;
}
/* Tweet This: */
.span-content {
display: block;
text-align: center;
color: #00A5EF;
}
.span {
display: block;
text-align: center;
font-family: OpenSans;
font-size: 36px;
color: #00A5EF;
}
HTML Code:
<div class="flex-rectangle">
<div class="image-wrapper">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/281152/Twitter_bird_logo_2012.svg" class="tweet"/>
<div id="buttons">
<div class="span-content">
<span>Tweet This</span>
</div>
</div>
</div>
</div>

Button is not centred even with resolution independent alignment

I have a button on my website, and I used resolution independent alignment. I checked two different computer screens with different resolutions and it looks alright, however, once opened on a larger aspect ratio screen or a mobile/tablet device it re-positions. On a larger aspect ratio screen the buttons moves to the left, on the smaller devices, it floats towards the right. I'm not 100% certain what could of gone wrong. Below is my CSS and HTML code.
HTML:
<div class="Welcome">
<h1>Welcome to Beauty Factory Bookings</h1>
<button>Book Appointment</button>
</div>
CSS:
body {
background: url('http://i.imgur.com/4mKmYMb.jpg') no-repeat fixed center center;
background-size: cover;
font-family: Montserrat;
margin: 0;
padding: 0;
.Welcome {
margin-top: 13%;
}
.Welcome h1 {
text-align: center;
font-family: Montserrat;
font-size: 50px;
text-transform: uppercase;
}
.Welcome button {
height: 60px;
width: 340px;
background: #ff656c;
border: 1px solid #e15960;
color: #fff;
font-weight: bold;
text-transform: uppercase;
font-size: 17px;
font-family: Montserrat;
outline: none;
cursor: pointer;
text-align: center;
margin-left: 33%;
margin-top: 3%;
border-radius: 5px;
}
Any idea how to fix this?
You center a html element, which has the standard position and is a block element with margin-left: auto and margin-right: auto.
It is a convention to write the first letter of classes and ids in lowercase.
Example
Just another way to do it:
I wrap your button in div and center the button using text-align:center
Don't forget to take out margin-left: 33%; in your css
HTML
<div class="Welcome">
<h1>Welcome to Beauty Factory Bookings</h1>
<div class="center">
<button>Book Appointment</button>
</div>
</div>
CSS
.Welcome {
margin-top: 13%;
}
.Welcome h1 {
text-align: center;
font-family: Montserrat;
font-size: 50px;
text-transform: uppercase;
}
.center {
text-align: center;
}
.Welcome button {
height: 60px;
width: 340px;
background: #ff656c;
border: 1px solid #e15960;
color: #fff;
font-weight: bold;
text-transform: uppercase;
font-size: 17px;
font-family: Montserrat;
outline: none;
cursor: pointer;
text-align: center;
margin-top: 3%;
border-radius: 5px;
}
Example: http://codepen.io/anon/pen/EPyjXm
create a new CSS property for a tag and set display to flex(takes up 100% of width; and justify content to center.
EDIT
After checking out your site,
there is a margin-left of 15px coming from somewhere. Get rid of it if that is a possibility or else just add margin-left: 0 to the .Welcome a {...}
.Welcome a {
display: flex;
/*set display mode of anchor to flex*/
justify-content: center; /* Justify content center*/
margin-left: 0; /* Add !important in case it is overwritten*/
}
.Welcome {
margin-top: 13%;
}
.Welcome h1 {
text-align: center;
font-family: Montserrat;
font-size: 50px;
text-transform: uppercase;
}
.Welcome a {
display: flex;
/*set display mode of anchor to flex*/
justify-content: center; /* Justify content center*/
}
.Welcome button {
height: 60px;
width: 340px;
background: #ff656c;
border: 1px solid #e15960;
color: #fff;
font-weight: bold;
text-transform: uppercase;
font-size: 17px;
font-family: Montserrat;
outline: none;
cursor: pointer;
text-align: center;
border-radius: 5px;
}
<div class="Welcome">
<h1>Welcome to Beauty Factory Bookings</h1>
<a href="website_link">
<button>Book Appointment</button>
</a>
</div>