content is exceeding my box (small CSS issue) - css

Im copying this Gensis Theme for CSS practice: http://my.studiopress.com/themes/daily-dish/#demo-full
I am now having an issue, since one of the black boxes exceeds its parent-Box.
The attribute causing this is the following code
.heading{
padding-left: 2em;
however I want this padding. How do I make the black background stop at the end of the parent box(id='right_1') and maintain the left padding?
*You have to scroll to the right when you run the snippet to see the issue
*{
margin: 0 auto;
}
body{
margin: 0 auto;
background-image: url('background.png');
}
.heading{
padding-left: 2em;
border: 1px solid green;
font-size: 1em;
display: flex;
width: 100%;
align-items: center;
color: white;
background-color: black;
height: 40px;
}
header{
padding: 70px;
display: flex;
flex-direction: column;
align-items: center;
}
#wrapper{
border: 1px solid lightgrey;
padding-left: 40px;
padding-right: 40px;
margin: auto;
width: 960px;
height: 2000px;
background: white;
}
main{
display: flex;
border: 1px solid red;
}
.blackbox{
}
#left {
width: 100%;
display: flex;
height: 1000px;
border: 1px solid black;
}
#left_1{
display: flex;
width: 100%;
}
#right {
margin-left: 5%;
width: 30%;
display: flex;
border: 1px solid black;
}
#right_1{
width: 100%;
}
<main>
<section id='left'>
<section id='left_1'>
<h2 class='heading'>Featured Dish</h2>
</section>
</section>
<aside id='right'>
<aside id='right_1'>
<h2 class='heading'>About the Author</h2>
</aside>
</aside>
</main>
</div>

You can add box-sizing:border-box to the .heading element.
This way the width and height properties include the padding.
CSS would be:
.heading {
padding-left: 2em;
border: 1px solid green;
font-size: 1em;
display: flex;
width: 100%;
align-items: center;
color: white;
background-color: black;
height: 40px;
box-sizing: border-box; // Add box-sizing: border-box
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
}
Hope this helps :)

You can solve this issue making box-sizing: border-box;
Try below CSS
*{
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
}
JSFIDDLE DEMO
Read more about box-sizing

Related

React fixed navbar with flexbox

so I'm trying to create my blog using the react framework, but I'm facing an issue here.
I really have been trying to tweaks settings on the css, html or even try to switch to grid instead of flexbox but I can't figure out how to make the "fixed" navbar detected by the flexbox.
Currently, the navbar works fine I guess, but the content that is supposed to be on the right, is not taking the place it should, it's taking the entire screen instead of the rigth section next to the navbar.
Some help would be highly appreciated !
body {
overflow: hidden;
height: 100vh;
top: 0;
left: 0;
margin: 0;
}
/*left box -Navbar*/
.nav-tab-text{
font-size: 1.6em;
display: block;
padding: 00px 0px 50px 0px;
text-align: center;
list-style-type: none;
display: flex;
}
.nav-tab a {
display: block;
text-align: center;
padding: 15px 18px;
text-decoration: none;
font-size: 18px;
color: aliceblue;
}
.nav-tab {
background-color: blue;
height: 100vh;
width: 18%;
border: 3px solid red;
position: fixed;
}
/*Right box - Home content*/
.home-content-container {
width: 100%;
height: 100vh;
border: 5px solid green;
}
.home-content-title {
text-align: center;
font-size: 1.7em;
text-decoration: underline;
text-decoration-thickness: 3px;
}
.home-content-featured{
border: 3px solid purple;
width: 50%;
height: 50%;
align-self: center;
margin-top: 3%;
}
.test{
display: flex;
}
function Navbar() {
return (
<div className="flex-container">
{/*left box - Navbar*/}
<nav className="nav-tab">
Home
Articles
Archives
About
</nav>
{/*Right box - Home content*/}
<div className="home-content-container">
<div className="home-content-title">
<h3>Name</h3>
</div>
<div className="home-content-featured">
<p>1</p>
</div>
</div>
<div className="test">
<p>2</p>
</div>
</div>
);
}
export default Navbar;
import Navbar from "./components/Navbar";
function App() {
return (
<div>
<Navbar />
</div>
);
}
export default App;
body {
overflow: hidden;
top: 0;
left: 0;
margin: 0;
}
/*left box -Navbar*/
.flex-container{
display: flex;
flex-flow: row;
}
.nav-tab a {
display: block;
text-align: center;
padding: 15px 18px;
text-decoration: none;
font-size: 18px;
color: aliceblue;
}
.nav-tab {
background-color: blue;
height: 100vh;
width: 18%;
border: 3px solid red;
}
/*Right box - Home content*/
.home-content-container {
width: 100%;
height: 100vh;
border: 5px solid green;
display: flex;
flex-direction: column-reverse;
}
.home-content-title {
text-align: center;
font-size: 1.7em;
text-decoration: underline;
text-decoration-thickness: 3px;
}
.home-content-featured{
border: 3px solid purple;
width: 50%;
height: 50%;
margin-top: 3%;
align-self: center;
}

border Is moving div while it appears

Well the code is
.all-card{
width: 100%;
height: 100%;
background-color: red;
}
.left-panel-child{
display: flex;
box-sizing: border-box;
justify-content: flex-start;
align-items: center;
height: 70px;
width: 100%;
margin-top: 1px;
background-color: darkblue;
border:white solid;
color: white;
cursor: pointer;
border-width: 0.1px 0 0 0;
}
.left-panel-child:hover{
border-left:white solid;
}
<div class="all-card">
<div class="left-panel">
<div class="left-panel-child"><span>hello</span></div>
</div>
</div>
My problem is that the left border that appears after`: hover' moves the text away from itself
I ve tried position:absolute with relative
add a transparent border to the initial element
.all-card{
width: 100%;
height: 100%;
background-color: red;
}
.left-panel-child{
display: flex;
box-sizing: border-box;
justify-content: flex-start;
align-items: center;
height: 70px;
width: 100%;
margin-top: 1px;
background-color: darkblue;
border:white solid;
color: white;
cursor: pointer;
border-width: 0.1px 0 0 0;
border-left:transparent solid;
}
.left-panel-child:hover{
border-left:white solid;
}
<div class="all-card">
<div class="left-panel">
<div class="left-panel-child"><span>hello</span></div>
</div>
</div>
is causing by the white border when mouse is on the div because you're turning the div's border to white which is the same color as the background one means that the border will look like is pushing somehow but not just remove border-left:white solid; or change the color to see the difference
.all-card {
width: 100%;
height: 100%;
background-color: red;
}
.left-panel-child {
display: flex;
box-sizing: border-box;
justify-content: flex-start;
align-items: center;
height: 70px;
width: 100%;
margin-top: 1px;
background-color: darkblue;
border: solid white;
color: white;
cursor: pointer;
border-width: 0.1px 0 0 0;
}
.left-panel-child:hover {
/*border-left:white solid;*/
}
<div class="all-card">
<div class="left-panel">
<div class="left-panel-child"><span>hello</span></div>
</div>
</div>

How to make this input text field responsive

Open in full window and resize the window the input field is not responsive so the button moves below the input which is not what i want.
.coupon {
width: 100%;
max-width: 500px;
outline: none;
margin: 0;
box-sizing: border-box;
height: 22px;
}
.coupon-btn {
background: #21b85b;
border: 0;
padding: 7px 20px 7px 20px;
text-transform: uppercase;
color: #fff;
display: inline;
font-size:0.875;
max-width: 100%;
}
<input type="text" class="coupon input-res">
<button class="coupon-btn">Apply</button>
try with width: calc(100% - 86px);.
.coupon {
width: calc(100% - 86px);
outline: none;
margin: 0;
box-sizing: border-box;
height: 22px;
}
.coupon-btn {
background: #21b85b;
border: 0;
padding: 7px 20px 7px 20px;
text-transform: uppercase;
color: #fff;
display: inline;
font-size:0.875;
}
<input type="text" class="coupon input-res">
<button class="coupon-btn">Apply</button>
Try like this
.flex-col {
display: flex;
display: -webkit-flex;
}
.coupon {
width: 100%;
max-width: 500px;
outline: none;
margin: 0;
box-sizing: border-box;
height: 30px;
}
.coupon-btn {
background: #21b85b;
border: 0;
padding: 7px 20px 7px 20px;
text-transform: uppercase;
color: #fff;
display: inline;
font-size: 0.875;
max-width: 100%;
}
<div class="flex-col">
<input type="text" class="coupon input-res">
<button class="coupon-btn">Apply</button>
</div>
try adding some mediaqueries
#media(max-width: 37em){
.coupon{width: 50%;}
}
You Must Learn #media contents https://www.w3schools.com/cssref/css3_pr_mediaquery.asp
otherwise, use Bootstrap https://www.w3schools.com/bootstrap4/
The easy way is to use bootstrap.
* {
margin: 0;
padding: 0;
}
.container {
display: grid;
grid-template-columns: 80% 20%;
justify-content: center;
align-items: center;
}
.coupon {
width: 100%;
outline: none;
margin: 0;
box-sizing: border-box;
padding: 8px 0;
}
.coupon-btn {
background: #21b85b;
border: 0;
padding: 10px 20px 10px 20px;
text-transform: uppercase;
color: #fff;
display: inline;
font-size:0.875;
max-width: 100%;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<div class="container">
<input type="text" class="coupon input-res">
<button class="coupon-btn">Apply</button>
</div>
</body>
</html>
Wrap the elements into a .container and use display: grid
You can give column width to on the container as you want it to be! I have used percentage, instead you can use pixel.
For reference go through this link https://www.w3schools.com/css/css_grid.asp
Hope it'll solve your problem

CSS - Inverted border radius to draw a rounded corner

I would like to know if there is a way to do these borders only using CSS in a way that they follow this shape:
I am trying to use CSS pseudo-elements ::after and ::before but I can't feel a kind of gap between divs. Any suggestion?
You can use pseudoelements to created rounded fragments and "clipped" borders.
.flex {
display: flex;
flex-direction: column;
align-items: flex-end;
}
.flex > * {
height: 50px;
position: relative;
display: flex;
align-items: center;
}
.flex > *:before {
content: "";
position: absolute;
display: inline-block;
top: 10px;
bottom: 0px;
left: -90px;
width: 90px;
border-right: 2px solid red;
border-bottom: 2px solid red;
border-bottom-right-radius: 10px;
}
.flex > *:after {
content: "";
position: absolute;
display: inline-block;
top: -2px;
height: 10px;
left: 0px;
width: 10px;
border-left: 2px solid red;
border-top: 2px solid red;
border-top-left-radius: 10px;
}
.flex > .one {
width: 100px;
}
.flex > .two {
width: 200px;
}
.flex > .three {
width: 300px;
}
.flex > .four {
width: 400px;
}
.degrees {
/* circle styles */
width: 30px;
height: 30px;
border-radius: 50%;
border: 1px solid red;
/* styles for centering */
display: flex;
align-items: center;
justify-content: center;
margin-left: 15px;
}
<div class="flex">
<div class="one">
<div class="degrees">1°</div>
</div>
<div class="two">
<div class="degrees">2°</div>
</div>
<div class="three">
<div class="degrees">3°</div>
</div>
<div class="four">
<div class="degrees">4°</div>
</div>
</div>
These are styles. Therefore in tag style="-moz-border-radius:5px;"
input[type=email] {
-moz-border-radius: 5px;
border-radius: 5px;
border: solid 1.4px black;
padding: 5px;
padding: 7px 7px 7px 7px;
max-width: 300px;
width: 80%;
}

Firefox flex and max-width

I’m trying to display an image centered and resized by CSS (max-width / max-height, flex).
This is working fine in Chrome but not in Firefox. What’s wrong?
a {
border: 1px solid red;
display: flex;
height: 100px;
width: 100px;
justify-content: center;
align-items: center;
box-sizing: border-box;
padding: 5px;
}
img {
max-width: 100%;
max-height: 100%;
border: 1px solid green;
}
<a class="frame">
<img src="http://placehold.it/500x150"/>
</a>
See: http://jsfiddle.net/ymLb50w0/2/
Try this solution...
a {
border: 1px solid red;
display: inline-block;
height: 100px;
width: 100px;
justify-content: center;
align-items: center;
box-sizing: border-box;
padding: 5px;
max-width: 100%;
}
img {
max-width: 100%;
max-height: 100%;
border: 1px solid green;
}
<body style="text-align: center;">
<a class="frame">
<img src="http://placehold.it/500x150"/>
</a>
</body>
You may try to align it vertically like it's explained here
Horizontal alignment shouldn't be a problem

Resources