How can I target the odd and even divs using CSS? - html

I want to apply different CSS to the odd and even divs but the current code I am using doesn't work. I just want it to target the first child, AKA the divs, and not the children of the divs.
.work-layer {
display: flex;
justify-content: center;
flex-direction: column;
color: white;
height: 100%;
}
.work-container:nth-child(odd) {
text-align: right;
padding-right: 100px;
}
.work-container:nth-child(even) {
text-align: left;
padding-right: 100px;
}
.name {
font-size: 3em;
text-transform: uppercase;
}
.desc {
font-size: 1.75em;
width: 40%;
}
.url {
font-weight: bold;
font-size: 1.5em;
color: white;
}
.work-layer {
height: 300px;
}
.layer-textastic {
background-color: rgba(0, 133, 255, 1);
}
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700,800" rel="stylesheet">
<div class="work">
<div class="work-container textastic">
<div class="work-layer layer-textastic">
<h1 class="name">Textastic</h1>
<p class="desc">I made this website as an homage to a great little text editor for iOS known as Textastic</p>
jordanbaron.me/Updated-Textastic-Site
</div>
</div>
</div>

Can’t you just change .work-container:nth-child(even) and .work-container:nth-child(odd) to .work:nth-child(even) and .work:nth-child(odd) respectively. If this is not what you want, post a picture using like MS paint of what you want it to look like.

Your Code with even and odd just works fine, I guess you want the text in the p-Tag also on the right side, the problem here is the width of 40% you had on the class .desc. Just add a div around with width 100%, and add float right to the text within the div (only for odd .work-container).
Edit: Instead of using the code above (and in the Snippet) you can just add the following 3 lines of code, it has the same Effect:
.work-container:nth-child(odd) p{
margin-right: auto;
}
.work-layer {
display: flex;
justify-content: center;
flex-direction: column;
color: white;
height: 100%;
}
.work-container:nth-child(odd) {
text-align: right;
padding-right: 100px;
}
.work-container:nth-child(odd) .inner-desc{
float: right;
}
.work-container:nth-child(even) {
text-align: left;
padding-right: 100px;
}
.name {
font-size: 3em;
text-transform: uppercase;
}
.desc {
font-size: 1.75em;
width: 100%;
}
.inner-desc{
width: 40%
}
.url {
font-weight: bold;
font-size: 1.5em;
color: white;
}
.work-layer {
height: 300px;
}
.layer-textastic {
background-color: rgba(0, 133, 255, 1);
}
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700,800" rel="stylesheet">
<div class="work">
<div class="work-container textastic">
<div class="work-layer layer-textastic">
<h1 class="name">Textastic</h1>
<div class="desc">
<p class="inner-desc">I made this website as an homage to a great little text editor for iOS known as Textastic</p>
</div>
jordanbaron.me/Updated-Textastic-Site
</div>
</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.

How to horizontally align pseudo element with element and its container

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>

Icons with Text located beside it

I am trying to use custom icons (3 of them) be located in their own cell in a table with the cell directly beside them being the text that goes along with them. I want the text to be close to the image. The image is to enlarge slightly when hovered over as it will also be a hyperlink. I can't seem to get code to ensure it is aligned center of the page and formatted correctly. Also the scale isn't working when I set it to enlarge on hover.
I have already tried multiple codes but none seem to be working within sharepoint.
.demo-problem,
.demo-solution {
font-size: 1.5em;
}
body {
padding: 30px;
}
.outer-div {
padding: 30px;
}
.inner-div {
margin: 0 auto;
width: 100%;
height: 100%;
}
.demo-solution--flexbox {
display: flex;
align-items: center;
}
img3 {
width: 25%;
height: auto;
display: block;
}
img3:hover {
transform: scale(3);
}
a:hover {
text-decoration: none;
color: black;
font-weight: bold;
}
<div class="demo-solution demo-solution--flexbox">
<div class="outer-div">
<img src="https://ontariopowergeneration.sharepoint.com/:i:/r/sites/powernet/support/res/PublishingImages/Pages/Real%20Estate/Icons/ICON_Real-Estate.png?csf=1&e=acVaiZ" alt="" class="img3">
</div>
<div class="inner-div"><span><blockquote>Corporate Real Estate & Workplace</blockquote></span></div>
</div>
The img3 is a class so u need to specify
.img3 whereas you have done just img3.
If you change it to .img3 scale works
.demo-problem,
.demo-solution {
font-size: 1.5em;
}
body {
padding: 30px;
}
.outer-div {
padding: 30px;
}
.inner-div {
margin: 0 auto;
width: 100%;
height: 100%;
}
.demo-solution--flexbox {
display: flex;
align-items: center;
}
.img3 {
width: 25%;
height: auto;
display: block;
}
.img3:hover {
transform: scale(3);
}
a:hover {
text-decoration: none;
color: black;
font-weight: bold;
}
<div class="demo-solution demo-solution--flexbox">
<div class="outer-div">
<img src="https://www.slipperelectrical.co.nz/wp-content/uploads/2015/12/dummy-image.jpg" alt="" class="img3">
</div>
<div class="inner-div"><span><blockquote>Corporate Real Estate & Workplace</blockquote></span></div>
</div>

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>

How to perfectly center text on an inline-display block with no definitive height correctly in this very standard yet unanswered way?

I've managed to use the preceding <span> method of centering items, which is all well, except for one little tiny issue illustrated in this image: http://imgur.com/UoKFW6P
how do i fix this? here is my css and html:
* {
padding: 0px 0px 0px 0px;
margin: 0px 0px 0px 0px;
text-align: center;
}
#font-face {
font-family: myfirstfont;
src: url(century-gothic.ttf);
}
body,
html {
height: 100%;
white-space: -0.125em;
background-color: rgb(0, 0, 0);
}
#wrapper {
height: inherit;
min-height: 100%;
}
.O1-3 {
color: white;
width: 100%;
height: 33.5%;
display: inline-block;
text-align: center;
font-family: myfirstfont;
}
div span {
height: 100%;
vertical-align: middle;
display: inline-block;
}
div a {
font-size: 35px;
display: inline-block;
font-style: italic;
text-decoration: none;
}
#media screen and (min-width:600px) {
.O1-3 {
height: inherit;
width: 33.3%;
}
}
</style>
</head>
<body>
<div id="wrapper">
<div class="O1-3" id="one">
<span></span>
<a id="n-textonly">Luis Rojas</a>
</div>
<div class="O1-3" id="two">
<span></span>
<a id="c-textonly">Contact</a>
</div>
<div class="O1-3" id="three">
<span></span>
<a id="rw-textonly">Recent Work</a>
</div>
</div>
</body>
</html>
There are multiple methods of centering in css, but without a definitive height, you're confined to a just few methods. Here are a few techniques I put together and commented out for you to take a look at: https://jsfiddle.net/73mtxgcc/3/
There are other techniques such as using flex or using display:table, but I find those, personally, either sloppy or not quite supported enough. As well, if you have something relative to the window, then you can always also use
.element{
display: inline-block;
margin: 0 auto;
}
with .element being the parent of the content you'd like to center.
If you have any more questions, or if you need any further clarifications, then please don't hesitate to ask!
You want to give all three columns the same padding with auto width, to get the text to be evenly spaced, then the wrapper centers the entire group. You get same amount of space on each side of the group, and then equal spacing in-between, so the center column ends up not being in the exact center of the page, but it has a very balanced visual effect for the page as a whole. You still need some adjustments with break-points though, I added one.
#wrapper {
width: auto;
height: inherit;
min-height: 100%;
}
.O1-3 {
padding: 1em;
color: white;
width: auto;
height: 33.5%;
display: inline-block;
text-align: center;
font-family: myfirstfont;
}
#media screen and (min-width:600px) {
.O1-3 {
padding: 2em;
height: inherit;
}
}
#media screen and (min-width:1000px) {
.O1-3 {
padding: 5em;
}
}
When it comes to formatting HTML content with CSS, you should really use Flexbox. It is becoming really popular and is widely supported. In the code below, I have added a display: flex; property to your #wrapper. This creates a flex-box out of the wrapper. From there, I added a flex-direction of row, which will automatically format it's three child elements horizontally. In the media query, I have changed the flex-direction property so that the wrapper's child elements are formatted vertically.
-- Hope this helps.
<html>
<head>
<style>
* {
padding: 0px 0px 0px 0px;
margin: 0px 0px 0px 0px;
text-align: center;
}
#font-face {
font-family: myfirstfont;
src: url(century-gothic.ttf);
}
body,
html {
height: 100%;
white-space: -0.125em;
background-color: rgb(0, 0, 0);
}
#wrapper {
height: inherit;
min-height: 100%;
display: flex;
flex-direction: row;
}
.O1-3 {
color: white;
width: 100%;
height: 33.5%;
text-align: center;
font-family: myfirstfont;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
div span {
height: 100%;
vertical-align: middle;
display: inline-block;
}
div a {
font-size: 35px;
display: inline-block;
font-style: italic;
text-decoration: none;
}
#media screen and (max-width:600px) {
.O1-3 {
height: inherit;
width: 100%
margin: auto;
}
#wrapper {
flex-direction: column;
}
}
</style>
</head>
<body>
<div id="wrapper">
<div class="O1-3" id="one">
<span></span>
<a id="n-textonly">Luis Rojas</a>
</div>
<div class="O1-3" id="two">
<span></span>
<a id="c-textonly">Contact</a>
</div>
<div class="O1-3" id="three">
<span></span>
<a id="rw-textonly">Recent Work</a>
</div>
</div>
</body>
</html>