Build line-through style with flexbox and pseudo elements - html

I'm building a line-through header that can span multiple lines. Using the sample code below, is it possible to write my CSS in such a way that the left and right divs are not needed? Where they could be added as pseudo-classes to my header class?
CodePen
.container {
box-sizing: border-box;
display: flex;
place-content: center space-evenly;
align-items: center;
}
.line {
flex: 1;
height: 2px;
background: black;
}
.header {
font-size: 50px;
margin: 0 30px;
text-align: center;
}
.header-broken:after {
content: '';
display: -webkit-inline-flex;
display: -ms-inline-flexbox;
display: inline-flex;
width: 50px;
height: 5px;
flex: auto;
width: 100%;
height: 2px;
background: black;
}
<div class="container">
<div class="line"></div>
<div class="header">Normal Title<br>fdasfsaf</div>
<div class="line"></div>
</div>

It can be done with just one div, see the example below, add some margin to the pseudo elements as needed for spacing.
.container {
display: flex;
text-align: center;
}
.container:before,
.container:after {
content: "";
flex: 1;
background: linear-gradient(black, black) center / 100% 1px no-repeat;
}
<div class="container">
Normal Title<br>fdasfsaf
</div>

You can also try this.
HTML:
<div class="container">
<div class="header">
<h1>Normal Title
<br>fdasfsaf
</h1>
</div>
</div>
CSS:
.container {
display: flex;
text-align: center;
}
.header {
flex: 1;
}
.header h1 {
font-size: 50px;
margin: 0 30px;
text-align: center;
background-color: #fff;
display: inline-block;
}
.header:after {
content: '';
border-bottom: 1px solid #000;
display: block;
margin-top: -58px;
}

Related

How to place an item under another item using flxbox?

I have a JS fiddle here and it's pretty simple what I want to happen but difficult for me to execute it. In the fiddle, you notice there is a red box. I want that red box to be displayed under the text "Join Balance...". I am not sure how to do this.
Can somebody help me?
Fiddle: https://jsfiddle.net/f2h390wc/
HTML and CSS:
/* newsletter section */
#custom_html-5 {
width: 100%;
background-color: #f2f2f2;
padding-bottom: 40px;
padding-top: 20px;
margin-bottom: 70px;
padding-left: 70px !important;
padding-right: 20px !important;
}
.newsletter_inner_section {
display: flex;
}
.newsletter_gif {
width: 200px;
height: auto;
}
.newsletter_left,
.newsletter_center,
.newsletter_right {
display: inline-flex;
}
.newsletter_left {
width: auto;
}
.newsletter_center {
width: 100%;
align-items: center;
}
.newsletter_right {
background: red;
width: 40%;
justify-content: flex-end;
}
.newsletter_text_section {
color: black !important;
font-size: 24px !important;
font-weight: bold;
}
.eVEmvD.eVEmvD.eVEmvD.eVEmvD.eVEmvD.eVEmvD {
width: fit-content !important;
padding: 0 20px;
}
.fGCWnQ.fGCWnQ {
justify-content: flex-end;
}
.kvTDNe.kvTDNe {
display: unset;
}
/* Media Newsletter section only */
#media (max-width:1144px) {
#custom_html-5 {
padding-left: 20px !important;
padding-right: 20px !important;
}
.newsletter_inner_section {
width: 100% !important;
justify-content: center;
display: flex;
}
.newsletter_center,
.newsltter_right {
flex-direction: column !important;
}
}
<!-- newsletter section -->
<div class="newsletter_section">
<div class="newsletter_inner_section">
<div class="newsletter_left">
<img src="https://balancecoffee.co.uk/wp-content/themes/balancecoffeechild/img/newsletternnobkg2.gif" alt="Balance Newsletter" style="padding-right:30px;" class="newsletter_gif">
</div>
<div class="newsletter_center">
<p class="newsletter_text_section">Join Balance and get 20% off your first order</p>
</div>
<div class="newsletter_right">
<div class="newsletter_input_section">
<div class="klaviyo-form-Rrsqsh"></div>
</div>
</div>
</div>
</div>
If you want the text and the red box on the right to form a column, then they both need to be in a flexbox with flex-direction: column;.
I created a sample from scratch because there is a lot of superfluous stuff in your JSFiddle.
.group {
display: flex;
flex-direction: row;
width: 100%;
}
.content-box {
display: flex;
flex-direction: column;
justify-content: center;
align-content: center;
padding: 40px;
}
.left {
background-color: blue;
}
.right {
flex-grow: 1;
display: flex;
flex-direction: column;
}
.top-right {
background-color: green;
}
.bottom-right {
background-color: red;
}
<div class='group'>
<div class='left content-box'>
Content
</div>
<div class='right'>
<div class='top-right content-box'>
Content
</div>
<div class='bottom-right content-box'>
Content
</div>
</div>
</div>
https://www.w3schools.com/cssref/css3_pr_flex-direction.asp
display: flex;
flex-direction: column;

Flexbox row with min-height does not stretch in IE

I have one flexbox with two rows and min-height. The right row has another flex with 2 columns with justify-content space between.
It works perfectly fine in Chrome but it does not fill the min-height in IE. There are many questions about it but none of them worked for me. Please note I have different styles of this where image is on top, bottom or right. I need to expand both content and image to fill the entire card in IE.
Here is the code.
.card-wrap {
display: block;
position: relative;
}
a {
display: block;
}
.card-image-left {
flex-direction: row;
}
.card {
box-sizing: border-box;
display: flex;
border: 1px solid black;
min-height: 200px;
}
.card-content {
padding: 12px;
display: flex;
flex-direction: column;
justify-content: space-between;
flex-grow: 1;
}
.card-text {
font-size: 0.875rem;
color: #1D1D1D;
}
.card-footer {
margin-top: 12px;
}
.card-image-wrap {
overflow: hidden;
position: relative;
}
h3 {
font-size: 1.25rem;
font-weight: 500;
margin: 0 0 4px 0;
}
.card-image {
width: 100%;
background-size: cover;
width:80px;
height: 100%;
background-repeat: no-repeat;
background-position: 50% 50%;
background-image: url("https://images.pexels.com/photos/67636/rose-blue-flower-rose-blooms-67636.jpeg");
}
<div class='card-wrap'>
<a href='#'>
<div class='card card-image-left'>
<div class='image-wrap'>
<div class='card-image'>
</div>
</div>
<div class='card-content'>
<div class='card-header'>
<h3>test title</h3>
<div class='card-text'>test subtitlte</div>
</div>
<div class='card-footer'>
<div>
<div class='card-footer-monetary'>1000</div>
</div>
</div>
</div>
</div>
</a>
</div>
Image from IE
Its a bug in IE 10-11. In IE 10-11, min-height declarations on flex containers work to size the containers themselves, but their flex item children do not seem to know the size of their parents. They act as if no height has been set at all.
More info: https://github.com/philipwalton/flexbugs#flexbug-3
Workaround
Simply wrap the flex container (here it div with classname card) with another flex-container having flex direction column
.ie-fix-wrapper{
display: flex;
flex-direction:column;
}
.card-wrap {
display: block;
position: relative;
}
a {
display: block;
}
.card-image-left {
flex-direction: row;
}
.card {
box-sizing: border-box;
display: flex;
border: 1px solid black;
min-height: 200px;
}
.card-content {
padding: 12px;
display: flex;
flex-direction: column;
justify-content: space-between;
flex-grow: 1;
}
.card-text {
font-size: 0.875rem;
color: #1D1D1D;
}
.card-footer {
margin-top: 12px;
}
.card-image-wrap {
overflow: hidden;
position: relative;
}
h3 {
font-size: 1.25rem;
font-weight: 500;
margin: 0 0 4px 0;
}
.card-image {
width: 100%;
background-size: cover;
width:80px;
height: 100%;
background-repeat: no-repeat;
background-position: 50% 50%;
background-image: url("https://images.pexels.com/photos/67636/rose-blue-flower-rose-blooms-67636.jpeg");
}
<div class='card-wrap'>
<a href='#'>
<div class="ie-fix-wrapper">
<div class='card card-image-left'>
<div class='image-wrap'>
<div class='card-image'>
</div>
</div>
<div class='card-content'>
<div class='card-header'>
<h3>test title</h3>
<div class='card-text'>test subtitlte</div>
</div>
<div class='card-footer'>
<div>
<div class='card-footer-monetary'>1000</div>
</div>
</div>
</div>
</div>
</div>
</a>
</div>
The solution provided by #Soothran works well. There is also alternative solution that is quicker to implement - inherit min-height in the children. In this case of the code above:
.image-wrap {
min-height: inherit;
}
.card-content {
min-height: inherit;
}
.card-wrap {
display: block;
position: relative;
}
a {
display: block;
}
.card-image-left {
flex-direction: row;
}
.card {
box-sizing: border-box;
display: flex;
border: 1px solid black;
min-height: 200px;
}
.card-content {
min-height: inherit;
padding: 12px;
display: flex;
flex-direction: column;
justify-content: space-between;
flex-grow: 1;
}
.card-text {
font-size: 0.875rem;
color: #1D1D1D;
}
.card-footer {
margin-top: 12px;
}
.card-image-wrap {
overflow: hidden;
position: relative;
}
h3 {
font-size: 1.25rem;
font-weight: 500;
margin: 0 0 4px 0;
}
.image-wrap {
min-height: inherit;
}
.card-image {
width: 100%;
width:80px;
height: 100%;
background: black;
}
<div class='card-wrap'>
<a href='#'>
<div class='card card-image-left'>
<div class='image-wrap'>
<div class='card-image'>
</div>
</div>
<div class='card-content'>
<div class='card-header'>
<h3>test title</h3>
<div class='card-text'>test subtitlte</div>
</div>
<div class='card-footer'>
<div>
<div class='card-footer-monetary'>1000</div>
</div>
</div>
</div>
</div>
</a>
</div>
You need to wrap any flex-direction:column inside a flex-direction:row
(or just display:flex for simple)

Flexbox with center valign and allow expandable content

First of all, the first snippet below is the problem I'm trying to fix.
Note that this was working perfectly fine IF display: flex; is applied to body.
However, I do not want to apply style to body which will break Google Web Cache layout.
* More explanation after the first snippet
* { box-sizing: border-box; }
body { margin: 0; }
.wrapper {
display: flex;
flex-direction: column;
min-height: 100vh;
width: 100%;
background-color: #ccc;
}
.navigation {
background-color: #f00;
width: 100%;
height: 3rem;
}
.footer {
background-color: #0f0;
width: 100%;
text-align: center;
line-height: 2rem;
}
.content {
background-color: #ff0;
flex: 1;
margin: 0.6rem 0 1.2rem;
}
.container {
background-color: #f0f;
margin: 0 auto;
max-width: 120rem;
width: 100%;
padding: 0 2rem;
}
.centered {
display: flex;
height: 100%;
align-items: center;
justify-content: center;
}
.long-content {
background-color: #fff;
}
<main class="wrapper">
<nav class="navigation">.navigation</nav>
<div class="content">
<section class="container centered">
<div class="long-content">.long-content</div>
</section>
</div>
<footer class="footer">.footer</footer>
</main>
So, removing display: flex; raised this issue:
section within .content does not have the height spanning across .content
Trying to fix it with position: relative on .content and position: absolute on .centered fixed the height issue but raised:
Width of .centered does not span across .content which can be easily fixed with left:0;right:0;
Height does not flow with content in section (I'm out of idea here)
Was it wrong to use position: relative and position: absolute to patch the original issue?
If so, what is the more suitable solution?
* { box-sizing: border-box; }
body { margin: 0; }
.wrapper {
display: flex;
flex-direction: column;
min-height: 100vh;
width: 100%;
background-color: #ccc;
}
.navigation {
background-color: #f00;
width: 100%;
height: 3rem;
}
.footer {
background-color: #0f0;
width: 100%;
text-align: center;
line-height: 2rem;
}
.content {
background-color: #ff0;
flex: 1;
margin: 0.6rem 0 1.2rem;
position: relative;
}
.container {
background-color: #f0f;
margin: 0 auto;
max-width: 120rem;
width: 100%;
padding: 0 2rem;
}
.centered {
display: flex;
position: absolute;
height: 100%;
left: 0;
right: 0;
align-items: center;
justify-content: center;
}
.long-content {
background-color: #fff;
height: 1000px;
}
<main class="wrapper">
<nav class="navigation">.navigation</nav>
<div class="content">
<section class="container centered">
<div class="long-content">.long-content</div>
</section>
</div>
<footer class="footer">.footer</footer>
</main>
I continued looking for solution and quickly noticed that I have shallow knowledge about flexbox itself so I went ahead and played with Flexbox Froggy.
After completing all the levels, I noticed that I can align everything without position: absolute by just using justify-content on .wrapper.
Below is my solution for my silly issue.
If you remove height of .long-content, .centered will continue to get aligned vertically.
Thank you froggies and shout out to Codepip!
* { box-sizing: border-box; }
body { margin: 0; }
.wrapper {
display: flex;
flex-direction: column;
min-height: 100vh;
width: 100%;
background-color: #ccc;
justify-content: space-between;
}
.navigation {
background-color: #f00;
width: 100%;
height: 3rem;
}
.footer {
background-color: #0f0;
width: 100%;
text-align: center;
line-height: 2rem;
}
.content {
background-color: #ff0;
margin: 0.6rem 0 1.2rem;
}
.container {
background-color: #f0f;
margin: 0 auto;
max-width: 120rem;
width: 100%;
padding: 0 2rem;
}
.centered {
display: flex;
height: 100%;
align-items: center;
justify-content: center;
}
.long-content {
background-color: #fff;
height: 1000px;
}
<main class="wrapper">
<nav class="navigation">.navigation</nav>
<div class="content">
<section class="container centered">
<div class="long-content">.long-content</div>
</section>
</div>
<footer class="footer">.footer</footer>
</main>

How can I adjust spacing for space-around?

im a bit lost:
im trying to make the space between 3 divs (horizontally) 40px, but it doesnt seem to work when i do it:
https://github.com/itsolidude/Tea_Cozy
i want the yellow marked parts to be 40px:
html {
font-family: Helvetica;
font-size: 22px;
color: seashell;
background-color: black;
opacity: 0.9;
text-align: center;
}
header {
display: flex;
align-items: center;
justify-content: space-between;
height: 69px;
border-bottom: 1px solid seashell;
position: fixed;
width: 100%;
z-index: 2;
background-color: black;
top: 0;
}
#locations h2 {
flex: 1 0 100%; /* shorthand for: flex-grow:1;
flex-shrink: 0;
flex-basis: 100%; */
text-align: center;
position: absolute; /* found this to be a simpler solution, and i sticked with it even tho i dont have exact 10px :p */
top: 1510px;
z-index: 3;
}
img {
height: 50px;
padding-left: 10px;
}
nav span {
color: seashell;
padding-right: 30px;
}
.mission-banner {
background-color: black;
}
.mission-banner h4 {
padding-bottom: 10px;
}
a {
cursor: pointer;
text-decoration-color: seashell;
}
#mission {
background-image: url(../images/img-mission-background.jpg);
position: relative;
margin: 70px auto 0;
width: 1200px;
height: 700px;
display: flex;
flex-direction: column;
justify-content: center;
}
#tea-of-month {
display: flex;
flex-wrap: wrap;
justify-content: center;
width: 1000px;
margin: 0 auto 70px;
}
#tea-of-month img {
height: 200px;
width: 300px;
margin-bottom: 10px;
}
.item {
display: flex;
flex-direction: column;
padding: 10px;
}
.contact {
height: 200px;
}
#locations {
height: 500px;
width: 1200px;
margin: 0 auto;
background-image: url(../images/img-locations-background.jpg);
display: flex;
justify-content: space-around;
align-items: center;
flex-wrap: wrap;
}
.address {
background-color: black;
width: 300px;
height: 300px;
display: flex;
flex-direction: column;
justify-content: center;
opacity: 1;
}
#copyright {
text-align: left;
margin-left: 20px;
}
<div id="locations">
<h2>Locations</h2>
<div class="address">
<h3>Downtown</h3>
<p>384 West 4th St</p>
<p>Suite 108</p>
<p>Portland, Maine</p>
</div>
<div class="address">
<h3>East Bayside</h3>
<p>3433 Phisherman's Avenue</p>
<p>(Northwest Corner)</p>
<p>Portland, Maine</p>
</div>
<div class="address">
<h3>Oakdale</h3>
<p>515 Crescent Avenue</p>
<p>Second Floor</p>
<p>Portland, Maine</p>
</div>
</div>
i put in the whole css. just in case something is affecting it. Pls explain what and why you did it :p
Don't use justify-content: space-between; as this will allot space depending on the available space.
Instead, center the flex-children and give them side margin of 20px (2 * 20px = 40px).
.wrap {
display: flex;
justify-content: center;
width: 90%;
margin: auto;
border: 1px solid grey;
}
.box {
background: #000;
width: 150px;
height: 150px;
margin: 20px;
}
<div class="wrap">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
Alternatively, you could set a max-width of the parent container, thus making less available space for the children to spread out with the space-between style.

How to get two divs centered vertically and have their background fill browser

I have two divs, but they are at the top, I want them in the middle, also each one has a background color that I'd like to fill their half of the screen.
.contenedor {
display: flex;
justify-content: space-around;
align-items: center;
font-size: 50px;
}
.español {
background: red;
}
.english {
background: blue;
}
a {
text-decoration: none;
}
<div class="contenedor">
<div class="español">
Español
</div>
<div class="english">
English
</div>
</div>
How would I go about doing this?
A picture says more than a thousand words
Thanks!
There's quite a lot to add to your code. If you want to use flex (as you did for the container), use the following settings for the elements:
html,
body {
height: 100%;
margin: 0;
}
.contenedor {
display: flex;
justify-content: space-around;
align-items: center;
font-size: 50px;
height: 100%;
}
.contenedor>div {
width: 100%;
height: 100%;
text-align: center;
position: relative;
display: flex;
flex-direction: column;
justify-content: center;
}
.español {
background: red;
}
.english {
background: blue;
}
a {
text-decoration: none;
color: white;
}
<div class="contenedor">
<div class="español">
Español
</div>
<div class="english">
English
</div>
</div>
There are many approaches you could choose.
A simple one is to set the 2 divs with abolute positionning, with each a width of 50%.
This way each div will occupy the whole height of the page and you don't have to worry about body margins or padding.
.contenedor {
font-size: 50px;
}
.espanol,
.english {
position: absolute;
top: 0;
bottom: 0;
width: 50%;
}
.espanol {
background: red;
left: 0;
}
.english {
background: blue;
left: 50%;
}
.contenedor a {
color: #fff;
text-align: center;
text-decoration: none;
display: flex;
justify-content: center;
flex-direction: column;
height: 100%;
}
<body>
<div class="contenedor">
<div class="espanol">
Español
</div>
<div class="english">
English
</div>
</div>