How can I do something like this?
The Orange Line should be on the same Line as the Instruction Text, I have this as my CSS Code
.InstructionText{
margin-bottom: auto;
font-family: Arial, Helvetica, sans-serif;
font-size: 29px;
text-align: center;
color: #007FC0;
text-transform: uppercase;
font-style: italic;
font-weight: bold;
}
.hr-rule{
position: absolute;
border: 7px solid #FF9900;
width: 400px;
}
But rather than have the above image, I have this Instead.
And using it inside the code I have this
import React from 'react';
import './app-styles.css';
import Vector from './Vector.png'
import ie_logo from './ie_logo.png';
import {Link} from 'react-router-dom';
function HomePage() {
return (
<div className="App">
<header className="header">
<img src={Vector} style={{margin:7, flexDirection:'column', alignItems: 'center'}} alt="Vector" />
<img src={ie_logo} style={{margin:7, flexDirection: 'row', width:114, height:25}} alt="ie_logo" />
<p className="needhelpText">REGISTERED? LOGIN</p>
</header>
<form>
<div className="InstructionText">
payment
</div>
<div className="hr-rule">
</div>
</form>
<footer className="footer">
Privacy Policy |
Do Not Sell My Personal Information |
Advertising Guidelines |
Site Map
<div className="copyrightText">
© Copyright 2021 | Lucas Tech | All Rights Reserved
</div>
<div className="footerLogo">
<img src={ie_logo} alt="ie_logo" />
</div>
</footer>
</div>
);
}
export default HomePage;
This seems like a very complicated method. Why not use a pseudo-element?
.InstructionText {
margin-bottom: auto;
font-family: Arial, Helvetica, sans-serif;
font-size: 29px;
justify-content: center;
color: #007FC0;
text-transform: uppercase;
font-style: italic;
font-weight: bold;
display: flex;
}
.InstructionText:after {
content: "";
border-bottom: 7px solid #FF9900;
margin-bottom: 7px;
width: 200px; /* or whatever width you require */
}
<div class="InstructionText">
payment
</div>
The main reason being that div is a block element by default, thus it will stack on top of each others. We can achieve your goal by using flex, which put the 2 divs side-by-side:
HTML:
<form>
<div class="header-container">
<div class="InstructionText">
payment
</div>
<div class="hr-rule"></div>
</div>
</form>
CSS:
.header-container {
display: flex;
justify-content: center;
align-items: center;
}
.InstructionText{
margin-bottom: auto;
font-family: Arial, Helvetica, sans-serif;
font-size: 29px;
text-align: center;
color: #007FC0;
text-transform: uppercase;
font-style: italic;
font-weight: bold;
}
.hr-rule{
margin-left: 20px;
height: 14px;
background-color: #FF9900;
width: 400px;
}
For the thick line, instead of using border, it's more efficient and understandable to just make a div with the width and 14px height, which achieve the same thing.
Related
I'm having an issue where the grid columns in my React component are showing up on separate rows in Safari 13. Numerous Google searches have come up with nothing and I'm really hoping somebody here can help. Here is the code of my React component (I've left out a bunch of state stuff and functions that aren't relevant):
import React, { useState, useRef } from 'react'
import classNames from 'classnames'
import SlideToggle from 'react-slide-toggle'
import styles from './shoppingListItem.module.css'
const ShoppingListItem = ({
itemId,
listTitle,
canEdit,
description,
quantity,
notes
}) => {
const [currentQuantity, setCurrentQuantity] = useState(quantity)
return(
<div className={styles.root}>
<button className={styles.button} onClick={toggleDetails}>
<span ref={headerRef} className={classNames(styles.header, { [styles.headerEditable]: canEdit })}>
{canEdit &&
<span className={styles.editIcons} ref={iconsRef}>
<div className={styles.icon} ref={deleteRef} onClick={destroyItem}><FontAwesomeIcon className={classNames(styles.fa, styles.destroyIcon
)} icon={faTimes} /></div>
<div className={styles.icon} ref={editRef} onClick={showEditForm}><FontAwesomeIcon className={styles.fa} icon={faEdit} /></div>
</span>}
<h4 className={styles.description}>{description}</h4>
</span>
<span className={styles.quantity}>
{canEdit && <div className={styles.icon} ref={incRef} onClick={incrementQuantity}>
<FontAwesomeIcon className={styles.fa} icon={faAngleUp} />
</div>}
<div className={styles.quantityContent}>
{currentQuantity}
</div>
{canEdit && <div className={styles.icon} ref={decRef} onClick={decrementQuantity}>
<FontAwesomeIcon className={styles.fa} icon={faAngleDown} />
</div>}
</span>
</button>
<SlideToggle toggleEvent={toggleEvent} collapsed>
{({ setCollapsibleElement }) => (
<div className={styles.collapsible} ref={setCollapsibleElement}>
<p className={styles.notes}>{notes || 'No details available'}</p>
</div>
)}
</SlideToggle>
</div>
)
}
The relevant CSS is:
.root {
font-family: 'Quattrocento Sans', Arial, Helvetica, sans-serif;
background-color: var(--main-color);
border-bottom: 1px solid var(--border-color);
}
.root:hover {
background-color: var(--hover-color);
}
.button {
width: 100%;
background: none;
border: none;
border-bottom: 1px solid var(--border-color);
text-align: left;
cursor: pointer;
padding: 0;
display: grid;
grid-template-columns: 2fr 1fr;
}
.fa {
color: var(--title-text-color);
}
.destroyIcon {
margin-right: 8px;
}
.header {
display: inline-block;
padding: 32px 16px;
border-right: 1px solid var(--border-color);
}
.headerEditable {
display: flex;
align-items: flex-start;
}
.editIcons {
display: flex;
flex-direction: row;
margin: auto 12px auto 0;
}
.quantity {
font-family: 'Quattrocento Sans', Arial, Helvetica, sans-serif;
font-size: 1rem;
color: var(--title-text-color);
display: inline-block;
margin: auto 0;
padding: 32px 8px;
display: flex;
justify-content: space-between;
}
.quantityContent {
margin: auto;
}
.icon {
display: inline-block;
padding: 4px;
cursor: pointer;
}
.description {
display: inline-block;
font-family: 'Quattrocento Sans', Arial, Helvetica, sans-serif;
font-size: 1.025rem;
color: var(--title-text-color);
margin: auto 0;
line-height: 1.25;
}
This is what the list item .button element/its children look like in Chrome (i.e., the way it's supposed to look):
This is the way the element looks in Safari (i.e., how it's not supposed to look):
The issue here turned out to be that I was using the button element incorrectly as the slide-toggle trigger and Chrome didn't mind but Safari didn't like it. I had made it a button because of accessibility reasons but I guess that was the wrong way to go. Changing the slide-toggle trigger into a div made it look the same in both Chrome and Safari.
I want the image / logo on the footer to be on the same line as the text on the footer, but whatever I do,it goes below the Line and looks like this
My css code is looking like this
.header{
background-color: #007FC0;
width: 100%;
padding: 25px 0;
}
.container{
flex : 1 1 auto;
color:white;
}
.needhelpText{
text-align: right;
font-weight: bold;
color: white;
display: inline-block;
padding: 10px;
float: right;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-size: medium;
}
.copyrightText{
margin: 8px;
color: white;
font-size: 13px;
}
.footerLinks{
color: white;
display: inline-block;
font-size: 13px;
text-decoration: none;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.footerLogo{
float: right;
width : 134px;
height: 40px;
padding: 10px;
align-items: center;
display: inline-block;
}
.footer{
position: fixed;
left: 0;
padding: 10px;
bottom: 0;
width: 100%;
height: 70px;
background-color: #16192C;
}
My React Code looks like this
import React from 'react';
import './app-styles.css';
import Vector from './Vector.png'
import ie_logo from './ie_logo.png';
import {Link} from 'react-router-dom';
function HomePage() {
return (
<div className="App">
<header className="header">
<img src={Vector} style={{margin:7, flexDirection:'column', alignItems: 'center'}} alt="Vector" />
<img src={ie_logo} style={{margin:7, flexDirection: 'row', width:114, height:25}} alt="ie_logo" />
<p className="needhelpText">LOGIN HERE?</p>
</header>
<form>
<label>
Hello React Label
</label>
</form>
<footer className="footer">
Privacy Policy |
Do Not Sell My Personal Information |
Advertising Guidelines |
Site Map
<div className="copyrightText">
© Copyright 2021 | Luther Corp | All Rights Reserved
</div>
<img src={ie_logo} style={{margin:9}} className="footerLogo" alt="ie_logo" />
</footer>
</div>
);
}
export default HomePage;
The Css holding this is the footer Logo which is this one
.footerLogo{
float: right;
width : 134px;
height: 40px;
padding: 10px;
align-items: center;
display: inline-block;
}
Pls what am I missing? Is there something I missed?
Have you tried out giving your footer a 100% width attribute? And if so, please also check the width of the logo. Incase that doesn't work out you can always create a div with 100% width containing only the logo. Than give that dive a text-align:right; attribute.
It's hard to see what's going on without a logo, but I think the footerLogo css height and inline-block are clashing.
If you want to have all the child elements in the same line whilst keeping their height the same (and therefore centered), use a display: flex on the parent without flex wrap. You can then use css margin-left: auto on the logo to make it float to the right and whatever height you want.
PS: align-items property does not work unless the container is display:flex. And it's confusing to add style when there's a class (unless the style is dynamically determined).
I need all of my elements inside my flexbox container to be close to each other. Unfortunately, since they have different font sizes, this is proving hard to accomplish. I could fix it using margins, but it seems like a hacky way to do it.
#price {
font-weight: bold;
border: none;
font-size: 1.5em;
}
#currency {
color: #000000;
font-size: 1.5em;
font-weight: bold;
}
#price:focus {
outline: none;
}
#price-info {
display: flex;
align-items: flex-start;
}
<div id="price-info">
<p id="currency">U$S</p><input id="price" type="text" value={this.state.price} onChange={this.handleChange} />
<p>$/m2{sizePrice}</p>
</div>
Updated problem, still spacing problems
#price{
font-weight: bold;
border:none;
font-size: 1.5em;
}
#currency{
color:#000000;
font-size: 1.5em;
font-weight: bold;
}
#price:focus {
outline:none;
}
#price-info{
display: flex;
justify-content: center;
align-items: baseline
}
<div id="price-info">
<p id="currency">U$S</p><input id="price" type="text" value={this.state.price} onChange={this.handleChange} />
<p>$/m2{sizePrice}</p>
</div>
Here is a possible solution you are looking for.
You can play around with justify-content to place your elements horizontally.
I believe what you wanted can be done by align-items property.
Try this. but is not much easy you have to set margins manually
#price {
font-weight: bold;
border: none;
font-size: 1.5em;
}
#currency {
color: #000000;
font-size: 1.5em;
font-weight: bold;
margin-right: .3rem;
}
#price:focus {
outline: none;
}
#price-info {
display: flex;
align-items: center;
}
#size-price{
margin-left: -5rem;
}
.itens{
display: inline-block;
width: fit-content;
}
<div id="price-info">
<p class="itens" id="currency">U$S</p>
<input class="itens" id="price" type="text" value={this.state.price} onChange={this.handleChange} />
<p class="itens" id="size-price">$/m2{sizePrice}</p>
</div>
I'm trying to design a Card but my <p> text is somehow inline. I don't want that. I tried display: block;and other options but that doesn`t work.
I work with Bootstrap and CSS but as far as I know, this is a plain CSS question.
Here is my Html for one card:
<div class="">
<div class="card">
<img class="card-img-top" src="../../../assets/images/offer_1.jpg">
<div class="card-body text-center">
<h1>{{offer.name}}</h1>
<p>{{offer.description}}</p>
<h2>{{offer.price}}€</h2>
</div>
And here my SCSS:
$font-serif: 'Playfair Display', serif;
$font-sans-serif: 'Raleway', sans-serif;
$color_price: #F96D00;
$color_description: #b8b8b8;
.card {
border-radius: 0;
.card-body {
padding: 3rem;
h1 {
font-family: $font-serif;
font-weight: bold;
line-height: 1.45;
font-size: 26px;
}
h2 {
font-family: $font-serif;
font-weight: bold;
line-height: 1.45;
font-size: 22px;
color: $color_price;
}
p {
font-family: $font-serif;
line-height: 1.45;
font-size: 18px;
color: $color_description;
height: 100px;
}
}
}
It looks like this:
Edit: The Problem is the paragraph has a flixible width but the text inside is somehow always inline and wider then the paragraph itself.
You don't need to use overflow:hidden or !important on text-align: center.
You need to set a maximum width on the card element that is the parent of the P.
Look at your styles rendered in a codepen:
https://codepen.io/NeilWkz/pen/vaaMoO
The name and price are left-aligned, and the description is center aligned.
This is because you've used a helper class 'text-center' I assume this comes from some framework that you have not mentioned in your question. The helper class will not cascade down if you have alignment set on the h1 or h2 element, in that case you need to apply it to the actual element:
HTML:
<div class="">
<div class="card">
<img class="card-img-top" src="../../../assets/images/offer_1.jpg">
<div class="card-body">
<h1 class="text-center">{{offer.name}}</h1>
<p class="text-center">{{offer.description}}</p>
<h2 class="text-center">{{offer.price}}€</h2>
</div>
</div>
SCSS:
$font-serif: 'Playfair Display', serif;
$font-sans-serif: 'Raleway', sans-serif;
$color_price: #F96D00;
$color_description: #b8b8b8;
.card {
border-radius: 0;
//Added width & background color for demo
width: 320px;
background: azure;
.text-center {
text-align: center;
}
.card-body {
padding: 3rem;
display: block;
h1 {
font-family: $font-serif;
font-weight: bold;
line-height: 1.45;
font-size: 26px;
display: center;
}
h2 {
font-family: $font-serif;
font-weight: bold;
line-height: 1.45;
font-size: 22px;
color: $color_price;
}
p {
font-family: $font-serif;
line-height: 1.45;
font-size: 18px;
color: $color_description;
height: 100px;
}
}
}
Here's a working pen with the styles above:
https://codepen.io/NeilWkz/pen/gjjJpw
I would like to reproduce the following image with CSS:
Especially important is to me that both lines have equal length:
I tried to recreate it with this code (jFiddle):
.box {
font-family: "Open Sans";
line-height: 28px;
font-weight: 700;
background-color: #2c343c;
margin: 20px;
padding: 20px;
width: 150px;
text-align: justify;
}
.box .name {
color: #fff;
font-size: 24px;
}
.box .sub {
color: #f29400;
font-size: 15px;
letter-spacing: 1px;
}
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
<div class="box">
<span class="name">Dr. Nielsen</span><br>
<span class="sub">WEBDEVELOPER
</div>
But its not quite perfect:
Is there a good way how to achieve this with CSS so that both lines get the same lengths on any device. Or is it recommended to rather use a picture for this?
You can give a try to text-align-last:justify;
Beside, to avoid setting a width, you may turn the box into a block that shrinks on its content via display:table; . You can also avoid the <br> setting spans into blocks
.box {
font-family: "Open Sans";
line-height: 28px;
font-weight: 700;
background-color: #2c343c;
margin: 20px;
padding: 20px;
display: table;
text-align: justify;
}
span {
display: block;
text-align-last: justify;
}
.box .name {
color: #fff;
font-size: 24px;
}
.box .sub {
color: #f29400;
font-size: 15px;
letter-spacing: 1px;
}
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
<div class="box">
<span class="name">Dr. Nielsen</span>
<span class="sub">WEBDEVELOPER</span>
</div>
<div class="box">
<span class="name">Dr. Nielsen</span>
<span class="sub">WEB-DEVELOPPER</span>
</div>
<div class="box">
<span class="name">Watch Out when top too long</span>
<span class="sub">single-short-breaks!</span>
</div>
You should remove the text-align: justify; on the container (.box) and give .name some extra letter-spacing so the 2 lines line up.
Be aware that this would be completely dependent on the font settings. Another font-family, size, etc. would change the size of both lines and make it different again. If people visiting your website changed their browser font size, then they won't see exactly what you see. If you want to avoid this (as much as possible) then look into font-size resets.
.box {
font-family: "Open Sans";
line-height: 28px;
font-weight: 700;
background-color: #2c343c;
margin: 20px;
padding: 20px;
width: 150px;
}
.box .name {
color: #fff;
font-size: 24px;
letter-spacing: .3px;
/* added */
}
.box .sub {
color: #f29400;
font-size: 15px;
letter-spacing: 1px;
}
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
<div class="box">
<span class="name">Dr. Nielsen</span>
<span class="sub">WEBDEVELOPER</span>
</div>