I need to make a bordered box with multiple elements in CSS - css

I need to create a box like this:
It is a React App. I have the elements - Name, Email, Avatar, etc.. and although I have all the data displayed within a rounded-cornered box at the moment, how do I get the text and image aligned up as per the image?
This is what I have at present:
The page displaying the items is:
import { Card } from "react-bootstrap";
import React, { useState } from "react";
import "./UsersItems.css";
import "./styles/candour.css";
export default function UsersItems(props) {
function createCard(user) {
return (
<Card key={user.id} className="user-card">
<Card.Body>
<Card.Img variant="bottom" src={user.avatar} />
<Card.Title>
{user.first_name} {user.last_name}{" "}
</Card.Title>
<Card.Link> {user.email}</Card.Link>
</Card.Body>
</Card>
);
}
let usersData = props.users;
let usersDivs = usersData.map(createCard);
return (
<div>
<div className="users-items">{usersDivs}</div>
</div>
);
}
and the CSS is:
#import url("https://fonts.googleapis.com/css?family=Source+Sans+Pro:regular,bold,italic&subset=latin,latin-ext");
.card-body {
display: flex;
flex-direction: column;
align-items: left;
padding: 30px 39px 30px 30px;
gap: 24px;
isolation: isolate;
width: 394px;
/* White */
box-shadow: 0px 0px 6px rgba(0, 0, 0, 0.25);
border-radius: 10px;
/* Inside auto layout */
flex: none;
order: 0;
flex-grow: 0;
/* Auto layout */
background: linear-gradient(
to right,
#0057ff,
#0057ff 65px,
white 60px,
white 100%
);
}
.card-img-bottom {
width: 59px;
height: 59px;
/* Warm light grey */
border: 5px solid #f8f7f6;
border-radius: 50%;
/* Inside auto layout */
flex: none;
order: 0;
flex-grow: 0;
z-index: 1;
text-align: left;
}
.card_title {
height: 21px;
/* Title case */
font-family: "Open Sans";
font-style: normal;
font-weight: 600;
font-size: 21px;
line-height: 28px;
/* or 133% */
/* Dark Blue */
color: #132350;
/* Inside auto layout */
flex: none;
order: 0;
flex-grow: 0;
}
.card-link {
height: 15px;
font-family: "Open Sans";
font-style: normal;
font-weight: 400;
font-size: 16px;
line-height: 21px;
color: #59678e;
}
I thought I was pretty good at CSS but clearly not! Any help would be greatly appreciated.

Related

Having trouble adding a line at the end of a div, plus the div is not 100% width

I am learning React and I am trying to simulate this design here: https://www.figma.com/file/QG4cOExkdbIbhSfWJhs2gs/Travel-Journal?node-id=2%3A2&t=LV3bLPEMOLMR8ksp-0
I started working on the project and I more or less finished it.
However, I am having trouble
Adding a line break after each trip-div. I thought I could do so on the ".map" cycle but it breaks. How should I approach it?
const trips = data.map(trip=>{
return (<Trip
item={trip}
/> <hr>)
})
For some reason the trip-div is not expanding 100% to the right. It must be something related to max-widht but I can't understand it.
Here is my code: https://scrimba.com/scrim/c3rDMnUL
Trip
export default function Trip(prop){
return(
<div className='trip container'>
<div className="trip-main">
<img src={prop.item.imageUrl} alt="" className="trip-img" />
</div>
<div className="trip-aside">
<p className="trip-location">{prop.item.location} View on Maps</p>
<h2 className="trip-title">{prop.item.location}</h2>
<p className="trip-dates">{prop.item.startDate} - {prop.item.endDate}</p>
<p className="trip-description">{prop.item.description}</p>
</div>
</div>
)
}
App
import { useState } from 'react'
import reactLogo from './assets/react.svg'
import Nav from "./components/Nav"
import Trip from "./components/Trip"
import data from '../src/assets/data'
const trips = data.map(trip=>{
return (<Trip
item={trip}
/>)
})
function App() {
const [count, setCount] = useState(0)
return (
<div className="App">
<Nav/>
{trips}
</div>
)
}
export default App
css
* {box-sizing: border-box;}
#root{
max-width: 600px;
}
body{
margin: 0;
font-family: 'Inter';
background: #FFFFFF;
}
h1,h2,h3,p {
margin:0
}
.container {
padding: 0 40px;
}
nav {
height: 55px;
background: #F55A5A;
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 2.5rem;
}
.nav-img {
margin-right: 7px;
}
.nav-title{
font-style: normal;
font-weight: 500;
font-size: 14.4608px;
line-height: 18px;
letter-spacing: -0.075em;
color: #FFFFFF;
}
.trip{
display: flex;
gap: 20px;
margin-bottom: 18px;
min-width: 100%;
}
.trip-main{
max-width: 40%;
}
.trip-aside{
max-width: 60%;
}
.trip-img{
width: 125px;
height: 168px;
border-radius: 5px;
}
.trip-location{
font-weight: 400;
font-size: 10.24px;
line-height: 12px;
letter-spacing: 0.17em;
color: #2B283A;
margin-bottom: 7px;
}
.trip-title{
font-weight: 700;
font-size: 25px;
line-height: 30px;
color: #2B283A;
margin-bottom: 7px;
padding-bottom: 10px;
}
.trip-dates{
font-weight: 700;
font-size: 10.24px;
line-height: 12px;
margin-bottom: 10px;
color: #2B283A;
}
.trip-google-maps{
font-weight: 400;
font-size: 10.24px;
line-height: 12px;
/* identical to box height */
text-decoration-line: underline;
color: #918E9B;
}
.trip-description{
font-family: 'Inter';
font-style: normal;
font-weight: 400;
font-size: 10.24px;
line-height: 150%;
/* or 15px */
color: #2B283A;
}
Let's answer your 2nd question first.
For some reason the trip-div is not expanding 100% to the right. It must be something related to max-width but I can't understand it.
The #root div has a max-width of 600px, which is cascading down and is affecting all the child components under it.
Now onto the more complicated one.
Adding a line break after each trip-div. I thought I could do so on the ".map" cycle but it breaks. How should I approach it?
You can only return 1 element from the map but you're trying to return 2 - 1 and 1 .
There's a couple of ways you can solve it.
The more obvious one - wrap them in a <div>
const trips = data.map(trip=>{
return (<div>
<Trip item={trip} />
<hr>
</div>)
})
The better solution is to use a React Fragment
const trips = data.map(trip=>{
return (<React.Fragment>
<Trip item={trip} />
<hr>
</React.Fragment>)
})
This way you don't need to render additional DOM elements.
For the first point:
You can't return adjacent elements like this:
const trips = data.map(trip=>{
return (<Trip
item={trip}
/> <hr>)
})
You need to wrap them in a parent and make container for hr to get the same width, it will be like this:
const trips = data.map(trip=>{
return (
<React.Fragment>
<Trip
item={trip}
/>
<div className="container"><hr /></div>
</React.Fragment>
)
})
For the second point:
You have max-width: 600px on the root, you need to remove that and for the .trip-aside remove the max-width and give it flex-grow: 1; to take the rest of the width of the screen.
So it will be like this:
.trip-aside{
flex-grow: 1;
}

How can I use CSS to style the Stripe inputs on a Bigcommerce cart integration?

I am using Stripe as my payment processor on BigCommerce. It works perfectly. The problem is that my site theme has a black background. When you type in your credit card info, the text is black in the Stripe inputs so you can't see it. I've tried to use CSS in both checkout.scss and optimized-checkout.scss to try and overwrite it, but since Stripe is loaded via JS and in what looks to be an iFrame, I can't figure it out.
I've added this css to both and it still doesn't work
input {
color: #eee !important;
}
May be you can use JavaScript for this,
document.getElementById("element_id").style etc...
I did not do that thing earlier, but this solution works on these types of scenarios!
but since Stripe is loaded via JS and in what looks to be an iFrame, I can't figure it out.
Indeed! It doesn't use the styling in your CSS, you have to specify it via Javascript by passing a style object when creating the Element:
https://stripe.com/docs/js/elements_object/create_element?type=card#elements_create-options-style
https://stripe.dev/elements-examples/
If you're not the one writing the code that interacts with stripe.js at this level you probably want to reach out to Bigcommerce or something to ask them to expose access in some way.
var stripe = Stripe('pk_test_6pRNASCoBOKtIshFeQd4XMUh');
var elements = stripe.elements();
var card = elements.create('card', {
style: {
base: {
iconColor: '#666EE8',
color: 'white', // color of the text : https://stripe.com/docs/js/appendix/style
lineHeight: '40px',
fontWeight: 300,
fontFamily: 'Helvetica Neue',
fontSize: '15px',
'::placeholder': {
color: '#CFD7E0',
},
},
}
});
card.mount('#card-element');
* {
font-family: "Helvetica Neue", Helvetica;
font-size: 15px;
font-variant: normal;
padding: 0;
margin: 0;
}
body {
background: #171515;
display: flex;
align-items: center;
justify-content: center;
min-height: 100%;
}
form {
width: 480px;
margin: 20px 0;
}
.group {
box-shadow: 0 7px 14px 0 rgba(49,49,93,0.10),
0 3px 6px 0 rgba(0,0,0,0.08);
border-radius: 4px;
margin-bottom: 20px;
}
label {
position: relative;
color: #8898AA;
font-weight: 300;
height: 40px;
line-height: 40px;
margin-left: 20px;
display: flex;
flex-direction: row;
}
.group label:not(:last-child) {
border-bottom: 1px solid #F0F5FA;
}
label > span {
width: 80px;
text-align: right;
margin-right: 30px;
}
.field {
background: transparent;
font-weight: 300;
border: 0;
color: #31325F;
outline: none;
flex: 1;
padding-right: 10px;
padding-left: 10px;
cursor: text;
}
.field::-webkit-input-placeholder { color: #CFD7E0; }
.field::-moz-placeholder { color: #CFD7E0; }
<script src="https://js.stripe.com/v3/"></script>
<body>
<form>
<div class="group">
<label>
<span>Card</span>
<div id="card-element" class="field"></div>
</label>
</div>
</form>
</body>

Override bootstrap css only in one react component

so I'm using a gorgeous search bar component that I found on codepen in my react (CRA) project.
I have imported css in the default src/index.js
Then I have my search component which is composed of Search.js and Search.module.css.
Clearly Bootstrap styling and the Search component styling doesn't work together, when I comment the bootstrap file import in src/index.js, the Search component will be working fine.
So how can I override bootstrap only on my Search Component?
Here is the css of the Search.module.css
#import url("https://fonts.googleapis.com/css?family=Roboto:400,400i,700");
* {
font-family: Roboto, sans-serif;
padding: 0;
margin: 0;
}
.flexbox {
background: linear-gradient(155deg, #cccccc, #e8ecee, #d4d4d4);
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.search {
margin: 20px;
}
.search>h3 {
font-weight: normal;
}
.search>h1,
.search>h3 {
color: white;
margin-bottom: 15px;
text-shadow: 0 1px #eaeff1;
}
.search>div {
display: inline-block;
position: relative;
}
.search>div:after {
content: "";
background: white;
width: 4px;
height: 20px;
position: absolute;
top: 40px;
right: 2px;
transform: rotate(135deg);
box-shadow: 1px 0 #eaeff1;
}
.search>div>input {
color: white;
font-size: 16px;
background: transparent;
width: 25px;
height: 25px;
padding: 10px;
border: solid 3px white;
outline: none;
border-radius: 35px;
box-shadow: 0 1px #eaeff1;
transition: width 0.5s;
}
.search>div>input::placeholder {
color: #5a5a5a;
opacity: 1;
}
.search>div>input::-ms-placeholder {
color: #efefef;
}
.search>div>input::-ms-input-placeholder {
color: #5a5a5a;
}
.search>div>input:focus,
.search>div>input:valid {
width: 250px;
}
As you haven't shared the code snippets. I am assuming the bootstrap search will be using: text and button tag. Now, the CSS of this would be coming from bootstrap.
You can do the following:
1) Make a search component level class eg "search-module"
2) Now, create css or scss file import in the search component and within that css
override the bootstrap css by :
.search-module input[type=search] {...}
OR
3) you can do this overriding on your main style.css file too.
You need do to step 2 for all the other conflicting classes, tags, and IDs in the bootstrap with the search component.
PS: This will bloat your CSS. Best would be if you can just pick that part of Bootstrap which is required and rest you write your own style.
Thank you.

Align list items horizontally in adaptive design

Please see the JSFiddle.
This is an adaptive design with "vw" parameters in the code. I want Text_1, Text_2 and Text_3 be aligned horizontally, which means that when i change the browser's window size, the distance from the left side of the screen to the beginning of the text is the same for those 3 words. With the current code I align them (via "margin" property), but as soon as the browser's window size changes, Text_2 and Text_3 move relatively to Text_1 (to the right when window size dicreases, to the left when it increases). What is wrong in the code please?
<div class="meaning">
<ol class="circle">
<li>Text_1</li>
<ul>
<li><span class="example">Text_2</span></li>
<li><span class="example_translated">Text_3</span></li>
</ul>
</ol>
</div>
.meanings_and_examples {
display: flex;
flex-direction: column;
}
.meaning {
font-family: Tahoma, Geneva, sans-serif;
width: auto;
text-align: left;
color: #1f2c60;
font-weight: 700;
word-wrap: break-word;
text-shadow: 0.06em 0.06em 0.09em rgba(0, 0, 0, 0.2);
margin-right: 1%;
font-size: calc(0.5em + 2.3vw);
}
ol.circle {
list-style-type: none;
}
li {
line-height: calc(1.1em + 1.5vw);
}
ol.circle > li {
counter-increment: item;
margin: 0% 0% 0.2% 1.3em;
}
ol.circle > li::before {
content: counter(item);
display: inline-block;
text-align: center;
border-radius: 100%;
width: calc(1.2em + 1.5vw);
background: #1f2c60;
color: white;
box-shadow: 0.06em 0.06em 0.09em rgba(0, 0, 0, 0.2);
margin: 0% 3.5% 0% -2.4em;
}
ul {
list-style-type: none;
}
.example {
width: auto;
text-align: left;
font-weight: 400;
}
.example_translated {
width: auto;
text-align: left;
font-weight: 400;
color: #5d78e5;
}
Okay, you have a lot of things going on, for your next question I would strip the fiddle of any code that is not needed for the example, all styling and such.
Next you are using too many dynamic widths together and as Paulie_D said, you are not allowed to put anything other than li-tags in a ul-tag or ol-tag.
The main issue is that you have two lists, one within the other where the padding is very dynamic, I tried to change it so the padding matched the dynamic width of the bullet.
I kept your HTML and changed some CSS so it behaves like you want but you really should think of a new HTML setup.
.meanings_and_examples {
display: flex;
flex-direction: column;
}
.meaning {
font-family: Tahoma, Geneva, sans-serif;
width: auto;
text-align: left;
color: #1f2c60;
font-weight: 700;
word-wrap: break-word;
text-shadow: 0.06em 0.06em 0.09em rgba(0, 0, 0, 0.2);
margin-right: 1%;
font-size: calc(0.5em + 2.3vw);
}
ol.circle {
list-style-type: none;
border: 2px solid purple;
position: relative;
padding-left: 10vw;
}
li {
line-height: calc(1.1em + 1.5vw);
}
ol.circle > li {
counter-increment: item;
margin: 0% 0% 0.2% 0;
border: 2px solid orange;
padding: 0;
position: relative;
}
ol.circle > li::before {
content: counter(item);
display: inline-block;
text-align: center;
border-radius: 100%;
position: absolute;
background: #1f2c60;
color: white;
box-shadow: 0.06em 0.06em 0.09em rgba(0, 0, 0, 0.2);
width: calc(1.2em + 1.5vw);
transform: translateX(-100%);
}
ul {
list-style-type: none;
padding-left: 0;
border: 2px solid red;
}
.example {
width: auto;
text-align: left;
font-weight: 400;
}
.example_translated {
width: auto;
text-align: left;
font-weight: 400;
color: #5d78e5;
}
<div class="meaning">
<ol class="circle">
<li>Text_1</li>
<ul>
<li><span class="example">Text_2</span></li>
<li><span class="example_translated">Text_3</span></li>
</ul>
</ol>
</div>
See my modified fiddle for the behaviour you requested.
I'm not sure what is the point of inserting the ul in the ol. But I think if is not mandatory, you should use them separately since you are enumerating same type of elements from what I can see.
Then there are several problems with your margins: your conter has width: calc(1.2em + 1.5vw); but your margins are margin: 0% 3.5% 0% -2.4em; .
I am guessing this is accomplished by trying different values.
But your couter witch has width: calc(1.2em + 1.5vw); is pushing the first element out of the list.
So the margin should consider that if you want the list items to be aligned. So your counter should have the margins something like margin: 0% 3.5% 0% calc(-3.5% - 1.2em - 1.5vw);
I did a working example here . I am not sure if you want it exactly this way, but you can start from here.
But I have to ask:
Do you really need one and one or you just use them so you can add before some of the elements the counter? Because it might be better to just use a class (for the counter) and use a sigle list for all elements.

CSS fill parent width

I'm struggling to set the div width to the remaining width of the container div. In the example below I want the red div (an input) to take as much space as possible. If you enter anything in the input the green div appears, which should always be right aligned.
I don't want to use either flex nor display: table-* or workarounds like setting overflow: hidden for to make space for floats.
EDIT: I'm looking for any solution that works for IE10+ (including display: table-*, etc.)
Example: https://codesandbox.io/s/23xo3wjjrp (Change the template and style tag inside /components/SearchBox.vue for changes)
The example uses vue, but for completeness I post the code here too:
HTML
<div class="ms-Fabric ms-SearchBox" :class="searchBoxStyle">
<div class="ms-SearchBox-iconContainer">
<i class="ms-SearchBox-icon ms-Icon ms-Icon--Search"></i>
</div>
<input class="ms-SearchBox-field" type="text" placeholder="Search"
v-model="searchQuery" ref="input"
#blur="onBlur" #focus="onFocus">
<div class="ms-SearchBox-clearButton" v-show="searchQuery.length > 0"
#click="clear">
<i class="ms-SearchBox-icon ms-Icon ms-Icon--Clear"></i>
</div>
</div>
SCSS
// Active styles
.ms-SearchBox.is-active {
.ms-SearchBox-iconContainer {
width: 4px;
transition: width .167s;
.ms-SearchBox-icon {
opacity: 0;
}
}
}
// Static styles
.ms-SearchBox {
display: inline-block;
font-size: 0px;
font-weight: 400;
color: #333;
border: 1px solid #a6a6a6;
height: 32px;
padding-left: 8px;
width: 208px;
.ms-SearchBox-iconContainer {
font-size: 14px;
color: #106ebe;
transition: width .167s;
.ms-SearchBox-icon {
opacity: 1;
transition: opacity .167s 0s;
}
background: rgba(0, 0, 0, 0.2);
}
.ms-SearchBox-field {
display: inline-block;
font-size: 14px;
margin: 0;
padding: 0;
text-overflow: ellipsis;
overflow: hidden;
border: none;
outline: 1px solid transparent;
height: 32px;
vertical-align: top;
background: rgba(255, 0, 0, 0.2);
}
.ms-SearchBox-iconContainer,
.ms-SearchBox-clearButton {
display: inline-block;
height: 32px;
line-height: 32px;
width: 32px;
text-align: center;
}
.ms-SearchBox-clearButton {
font-size: 14px;
background: rgba(0, 255, 0, 0.2);
&:hover {
cursor: pointer;
}
}
}
You should try to set a width:100% to your input, and to set position:absolute to your icon containers. With paddings on the input, this should do the thing.
Hope I understood the question :)

Resources