How to make the text overflow the backrgound from top and bottom? - css

I'm trying to emulate this behavior using CSS:
And this is what I have to this moment:
.contenedor{
height: 30px;
margin-bottom: 10px;
}
.lineaRoja{
background-color: red;
opacity: 0.5;
height: 20px;
border-radius: 5px;
text-align: center;
}
.centreado{
font-size: 30px;
}
<div class="contenedor">
<div class="lineaRoja">
<h2 class="centreado">Streaming</h2>
</div>
</div>
How can I get that CSS behavior?

I would cut the upper and lower part via clip-path. No need to use extra elements or pseudoelements
h2 {
background: #f16c73;
color: #fff;
font: 2.4em Arial;
font-style: italic;
font-weight: 800;
text-align: center;
letter-spacing: 2px;
clip-path: polygon(20% 33%, 20% 70%, 80% 70%, 80% 33%);
}
<h2>STREAMING</h2>

Here is another idea where you can consider line-height
h2 {
background: #f16c73;
color: #fff;
font: 2.4em Arial;
font-style: italic;
font-weight: 800;
text-align: center;
letter-spacing: 2px;
line-height:0.45;
/*overflow:hidden; uncomment this if you want to hide the overflow */
}
<h2>STREAMING</h2>
Another one where you can adjust the background:
h2 {
color: #fff;
font: 2.4em Arial;
font-style: italic;
font-weight: 800;
text-align: center;
letter-spacing: 2px;
background:
linear-gradient(#f16c73,#f16c73) center
/100% 45% /* Adjust this value */
no-repeat;
}
<h2>STREAMING</h2>

I wouldn't use opacity, but simply white text and white background. The text can be vertically positioned by using postion: relative and a bottom setting to offset it to the optimal position.
.contenedor {
height: 30px;
margin-bottom: 10px;
}
.lineaRoja {
background-color: red;
height: 24px;
border-radius: 5px;
text-align: center;
}
.centreado {
font-family: sans-serif;
font-style: oblique;
font-size: 50px;
color: white;
position: relative;
bottom: 8px;
}
<div class="contenedor">
<div class="lineaRoja">
<h2 class="centreado">STREAMING</h2>
</div>
</div>

Another solution is to move the text via transform property of CSS.
.contenedor {
height: 30px;
}
.lineaRoja {
background-color: rgba(255, 0 ,0, 0.5);
opacity: 0.5;
height: 20px;
border-radius: 5px;
text-align: center;
overflow: hidden;
}
.centreado {
font-size: 70px;
line-height: 70px;
color: white;
margin: 0;
padding: 0;
transform: translateY(-40%);
}
<div class="contenedor">
<div class="lineaRoja">
<h2 class="centreado">Streaming</h2>
</div>
</div>

Change the text colour to transparent and set the font style to italic.
.centreado{
font-size: 60px;
color: transparent;
font-style: italic;
}
Move the div downwards.
.contenedor{
height: 30px;
margin-bottom: 10px;
transform: translateY(20px); /*Change this value according to your need */
}

html:
<div class="contenedor">
<div class="lineaRoja">
<h2 class="centreado">Streaming</h2>
</div>
</div>
css:
.contenedor {
height: 30px;
margin-bottom: 10px;
}
.lineaRoja {
position: relative;
background-color: red;
opacity: 0.5;
height: 20px;
border-radius: 5px;
}
.centreado {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: white;
font-size: 38px;
text-transform: uppercase;
font-style: italic;
margin: 0
}
JSfiddle: https://jsfiddle.net/hansfelix50/q0zxh9ku/

The secret here is overflow: hidden; on your red line, anything overflowing it gets cut off.
.contenedor {
height: 30px;
margin-bottom: 10px;
}
.lineaRoja {
background-color: red;
opacity: 0.5;
height: 20px;
border-radius: 5px;
text-align: center;
position: relative;
overflow: hidden;
}
.centreado {
font-size: 55px;
position: absolute;
width: 100%;
top: 50%;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
margin: 0;
color: #fff;
text-transform: uppercase;
}
<div class="contenedor">
<div class="lineaRoja">
<h2 class="centreado">Streaming</h2>
</div>
</div>

You can do this easily with css flexbox.
Steps:
Remove the opacity: 0.5; and text-align: center; from .lineaRoja
Add background-color: #f36167; to .lineaRoja
Add display: flex; align-items: center; justify content: center; to .lineaRoja
Style the h1 as necessary; I've used: letter-spacing: 2px; font-size: 55px; font-family: arial; font-style: italic; color: white;
Here is a simple example using:
body {
background-color: grey;
padding-top: 50px;
}
.lineaRoja {
background-color: #f36167;
height: 20px;
border-radius: 5px;
display: flex;
align-items: center;
justify-content: center;
}
.centreado {
letter-spacing: 2px;
font-size: 55px;
font-family: arial;
font-style: italic;
color: white;
}
<div class="lineaRoja">
<h1 class="centreado">STREAMING</h1>
</div>

Related

Why these CSS rules are not applied

I was trying to make this parallax-website. In the CSS I am defining properties for .image1 . So I wrote down properties and then just below it I again wrote some properties for the same class .image1. But only the ~ opacity, position (from 1st) and other properties defined (from 2 time) were applied. I checked the it using Inspect Element and all other properties were cut down. I am not able to understand why this is happening. Please help me.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,
body {
height: 100%;
font-family: 'Lato', sans-serif;
font-weight: 400;
line-height: 1.8em;
color: #666;
}
.image1 {
position: relative;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
background-attachment: fixed;
opacity: 0.70;
}
.image1 {
background: url('https://jolly-kalam-23776e.netlify.app/parallaxsite/img/image1.jpg');
min-height: 100%;
}
.text-box-image1 {
position: absolute;
/* To bring that box in center */
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.text-image1 {
font-size: 27px;
letter-spacing: 8px;
color: white;
background-color: #111;
padding: 20px;
}
.section-one {
padding: 50px 80px;
}
.section-one .heading {
text-align: center;
letter-spacing: 1px;
margin: 20px;
}
p {
text-align: center;
font-size: 17px;
}
<div class="image1">
<div class="text-box-image1">
<span class="text-image1">PARALLAX WEBSITE</span>
</div>
</div>
I think you need to mention background image as "background-image". You are declaring background property individually. or you can write like that way :
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,
body {
height: 100%;
font-family: 'Lato', sans-serif;
font-weight: 400;
line-height: 1.8em;
color: #666;
}
.image1 {
background: url('https://jolly-kalam-23776e.netlify.app/parallaxsite/img/image1.jpg') no-repeat fixed center center;
background-size: cover;
min-height: 100%;
opacity: 0.70;
position: relative;
}
.text-box-image1 {
position: absolute;
/* To bring that box in center */
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.text-image1 {
font-size: 27px;
letter-spacing: 8px;
color: white;
background-color: #111;
padding: 20px;
}
.section-one {
padding: 50px 80px;
}
.section-one .heading {
text-align: center;
letter-spacing: 1px;
margin: 20px;
}
p {
text-align: center;
font-size: 17px;
}
<div class="image1">
<div class="text-box-image1">
<span class="text-image1">PARALLAX WEBSITE</span>
</div>
</div>

When i increase size of box element the box below it goes down like 300px

/* Add a black background color to the top navigation */
body {
margin: 0px;
background-color: rgb(89, 90, 74);
}
.menu {
background-color: rgb(54,54,53);
overflow: hidden;
width: 100%;
padding-bottom: 10px;
padding-top: 10px;
position: fixed;
z-index: 4;
}
.menu a {
font-size: 30px;
font-family: Arial, sans-serif;
color: rgb(176, 254, 118);
text-decoration: none;
margin-left: 15px;
}
.container {
width: 90%;
margin-left: 8%;
margin-right: 8%;
overflow: hidden;
margin-top: 70px;
padding: 30px 0px;
position: absolute;
}
.container div {
display: block;
position: relative;
margin-left: 15px;
margin-bottom: 15px;
width: 250px;
height: 450px;
overflow: hidden;
background-color: rgb(255,255,255);
color: rgb(255,255,255);
float: left;
background-color: rgb(176, 254, 118);
border-radius: 15px;
}
.ahover:hover{
color: rgb(255,255,255);
transition: 0.6s;
}
.ahover:not(:hover){
color: rgb(176, 254, 118);
transition: 0.6s;
}
#sellbox {
color: rgb(54,54,53)
}
#sellbox ul {
list-style: none
}
#sellbox #element {
font-size: 25px;
text-align: center;
font-family: Arial, Helvetica, sans-serif;
margin-top: 0px;
margin-bottom: 3px;
}
#sellbox #title {
text-align: center;
font-size: 30px;
margin-top: 4px;
font-family: Arial, Helvetica, sans-serif;
}
#sellbox:hover{
padding: 3px;
box-shadow: rgb(54,54,53) 3px;
}
#sellbox:not(:hover){
padding: 0px;
box-shadow: none;
}
My problem is that the box that says "Buy me" when you hover it, it increases the size, but every other box moves, i tried to check already existing questions on this type but i havent found my answer, could you create a new fiddle with the working one and tell me what was the problem, thanks.
That's the css, also heres a fiddle https://jsfiddle.net/t4r3L2v8/
Change
#sellbox:hover{
padding: 3px;
box-shadow: rgb(54,54,53) 3px;
}
#sellbox:not(:hover){
padding: 0px;
box-shadow: none;
}
to
#sellbox{
padding: 0;
}
#sellbox:hover{
box-shadow: 3px 3px 3px rgb(54,54,53);
}
There's no need for :not(:hover) and as the other answer already said, the padding: 3px makes the element sightly so bigger that it takes up space in the next row.
Also there was something wrong with your box-shadow syntax. Read up on box-shadow on CSS Tricks - Box Shadow
An element floated where it get space first & want to get most top &left space. when you increase padding it little bit take extra space from which break the next flow.
Replace your whole css by this-
/* Add a black background color to the top navigation */
body {
margin: 0px;
background-color: rgb(89, 90, 74);
}
.menu {
background-color: rgb(54,54,53);
overflow: hidden;
width: 100%;
padding-bottom: 10px;
padding-top: 10px;
position: fixed;
z-index: 4;
}
.menu a {
font-size: 30px;
font-family: Arial, sans-serif;
color: rgb(176, 254, 118);
text-decoration: none;
margin-left: 15px;
}
.container {
width: 90%;
margin-left: 8%;
margin-right: 8%;
overflow: hidden;
margin-top: 70px;
padding: 30px 0px;
position: absolute;
}
.container div {
display: block;
position: relative;
margin-left: 15px;
margin-bottom: 15px;
width: 250px;
height: 450px;
overflow: hidden;
background-color: rgb(255,255,255);
color: rgb(255,255,255);
float: left;
background-color: rgb(176, 254, 118);
border-radius: 15px;
}
.ahover:hover{
color: rgb(255,255,255);
transition: 0.6s;
}
.ahover:not(:hover){
color: rgb(176, 254, 118);
transition: 0.6s;
}
#sellbox {
color: rgb(54,54,53);
transition: .5s;
}
#sellbox ul {
list-style: none
}
#sellbox #element {
font-size: 25px;
text-align: center;
font-family: Arial, Helvetica, sans-serif;
margin-top: 0px;
margin-bottom: 3px;
}
#sellbox #title {
text-align: center;
font-size: 30px;
margin-top: 4px;
font-family: Arial, Helvetica, sans-serif;
}
#sellbox:hover{
transform: scale(1.03);
box-shadow: 0 0 5px rgb(54,54,53);
}
#sellbox:not(:hover){
padding: 0px;
box-shadow: none;
}
The main reason for this is that you're using padding to highlight your element, the total size of your box is calculated by summing content width, content height, padding and borders (content width + padding-left + padding-right + border-left + border-right) (content height + padding-top + padding-bottom + border-top + border-bottom) so when you increase the padding of a box, its size will increase, and as a result it may push neighbour boxes.
Check box-model to understand more
Solution:
One way to solve it is by defining your box-sizing to border-box, this will prevent the total size of the box from increasing by decreasing the size of the content relatively to the border and padding.
it would be good if you add this property to every element in your page by adding the following css code:
*{
box-sizing: border-box;
}
Your problem's solution:
One way to highlight your element is by using transform: scale(value), scale() will resize your element as shown in documentation (increase if value > 1, decrease if value < 1)
your code should look like this, feel free to change the value in order to understand how it works:
#sellbox:hover{
transform: scale(1.03);
box-shadow: rgb(54,54,53) 3px;
}
/* Add a black background color to the top navigation */
*{
box-sizing: border-box;
}
body {
margin: 0px;
background-color: rgb(89, 90, 74);
}
.menu {
background-color: rgb(54,54,53);
overflow: hidden;
width: 100%;
padding-bottom: 10px;
padding-top: 10px;
position: fixed;
z-index: 4;
}
.menu a {
font-size: 30px;
font-family: Arial, sans-serif;
color: rgb(176, 254, 118);
text-decoration: none;
margin-left: 15px;
}
.container {
width: 90%;
margin-left: 8%;
margin-right: 8%;
overflow: hidden;
margin-top: 70px;
padding: 30px 0px;
position: absolute;
}
.container div {
display: block;
position: relative;
margin-left: 15px;
margin-bottom: 15px;
width: 250px;
height: 450px;
overflow: hidden;
background-color: rgb(255,255,255);
color: rgb(255,255,255);
float: left;
background-color: rgb(176, 254, 118);
border-radius: 15px;
}
.ahover:hover{
color: rgb(255,255,255);
transition: 0.6s;
}
.ahover:not(:hover){
color: rgb(176, 254, 118);
transition: 0.6s;
}
#sellbox {
color: rgb(54,54,53)
}
#sellbox ul {
list-style: none
}
#sellbox #element {
font-size: 25px;
text-align: center;
font-family: Arial, Helvetica, sans-serif;
margin-top: 0px;
margin-bottom: 3px;
}
#sellbox #title {
text-align: center;
font-size: 30px;
margin-top: 4px;
font-family: Arial, Helvetica, sans-serif;
}
#sellbox:hover{
transform: scale(1.03);
box-shadow: rgb(54,54,53) 3px;
}
#sellbox:not(:hover){
padding: 0px;
box-shadow: none;
}
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="menu">
<a class="ahover" href="#home">
Home
</a>
<a class="ahover" href="#contact">
Contact us
</a>
<a class="ahover" style="margin-left: 78%;" href="#signup">Sign up</a>
</div>
<div class="container">
<div id="sellbox">
<p id="title">Buy me now</p>
<p id="element">whew</p>
<p id="element">whew</p>
<p id="element">whew</p>
<p id="element">whew</p>
<p id="element">whew</p>
<p id="element">whew</p>
<p id="element">whew</p>
</div>
<div>
</div>
<div>
</div>
<div>
</div>
<div>
</div>
<div>
</div>
<div>
</div>
<div>
</div>
<div>
</div>
<div>
</div>
<div>
</div>
<div>
</div>
</div>
</body>
</html>
the boxes are moving because you are padding when you hover over it and it cause the element size to enlarge and to make space for that size it pushes items

center '+' inside the border-radius 50% div?

I'd like to center a + inside a div. The problem is on ios it shows more in the bottom of the div and not in the middle. in chrome it is ok.
Any ideas to solve this?
Fiddle
.addplus {
border-radius: 50%;
background-color: blue;
width: 38px;
height: 38px;
margin: 5px;
color: #fff;
font-size: 38px;
float: left;
text-align: center;
line-height: 38px;
font-family: Helvetica Neue,Helvetica,Arial,sans-serif;
}
<div class='addplus'>
+
</div>
I don't have an Ios device near me right now so I can't be sure if it works, but try this:
Put the "+" in a span, then center the span in the div instead.
Something like this:
.addplus {
position: relative;
border-radius: 50%;
background-color: blue;
width: 38px;
height: 38px;
margin: 5px;
color: #fff;
font-size: 38px;
float: left;
text-align: center;
line-height: 38px;
font-family: Helvetica Neue,Helvetica,Arial,sans-serif;
}
.plus {
position: absolute;
color: #fff;
font-size: 38px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<div class="addplus">
<span class="plus">+</span>
</div>

Responsive Text Sizing Issues within container

I am having the hardest time here...I have searched for a while now and can't quite figure out how to properly get my text to properly re-size in my parent container.
Here is the code:
html,
body,
box,
thumbnail_image,
overlay,
h1,
h3,
h6,
p,
body {
width: 100%;
padding-bottom: 25px;
font-size: 100%;
}
input {
font-family: "Roboto";
position: absolute;
top;
25.5px;
font-weight: 700;
font-size: 14px;
color: #fff;
background-color: transparent;
text-align: right;
border-width: 0;
width: 100%;
margin: 0 0 .1em 0;
}
.heart_button {
position: absolute;
top: 25.5px;
right: 55px;
}
.heart_button:hover,
.heart_button:active,
.heart_button:focus {
color: #dd0239;
}
.heart_background {
position: absolute;
top: 20px;
right: 20px;
background-color: #000000;
opacity: .1;
width: 65px;
height: 30px;
border-radius: 15px;
}
.box {
margin: 50px auto;
position: relative;
max-width: 90%;
height: 490px;
width: 700px;
background-color: #18a0ff;
box-shadow: 1px 15px 50px 2px;
}
.quote_image {
position: absolute;
opacity: .1;
top: 62px;
left: 51px;
}
.image_overlay {
background-color: #282a37;
width: 170px;
height: 490px;
position: absolute;
float: left;
}
.thumbnail_image {
position: absolute;
float: left;
opacity: .12;
display: inline-block;
}
.text_container {
left: 200px;
width: 400px;
height: 338px;
max-width: 90%;
word-wrap: break-word;
position: absolute;
}
h1 {
color: #fff;
text-transform: uppercase;
font-size: 3.7em;
font-family: Montserrat;
font-weight: 700;
line-height: 1.3;
text-align: left;
width: 100%;
word-wrap: break-word;
}
.author_name {
position: absolute;
left: 206px;
bottom: 0px;
}
h3 {
font-family: Open Sans;
font-weight: 700;
letter-spacing: 1px;
text-transform: uppercase;
font-size: 1em;
text-align: left;
color: #fff;
}
p {
font-family: "Roboto";
font-weight: 700;
font-size: 14px;
color: #fff;
text-align: center;
}
h6 {
font-family: Open Sans;
font-weight: light;
font-size: 1em;
letter-spacing: 2px;
text-transform: uppercase;
text-align: center;
}
nav {
position: absolute;
left: 35px;
bottom: 28px;
}
html {
background: linear-gradient(209deg, #E5ECEF 40%, #BBC2C5 100%) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#footer {
clear: both;
}
#media screen and (max-width: 649px) {
.box {
width: 450px;
height: 350px;
max-width: 90%;
}
h1 {
font-size: 2em;
word-wrap: break-word;
}
.text_container {
width: 280px;
height: 236.6px;
max-width: 90%;
}
}
<body>
<div class="box">
<div class="heart_button">
<img src="http://res.cloudinary.com/dp32vpqfu/image/upload/v1457311522/little_heart_jle1j3.png">
</div>
<div class="heart_background">
</div>
<div class="image_overlay">
</div>
<div class="thumbnail_image">
<img src="http://res.cloudinary.com/dp32vpqfu/image/upload/v1457298445/Sheldon_Pic_l3cprk.jpg">
</div>
<div class="text_container">
<h1>Don't You think that if I were wrong, I'd know it?</h1>
</div>
<div class="author_name">
<h3> - Sheldon Cooper </h3>
</div>
<div class="quote_image">
<img src="http://res.cloudinary.com/dp32vpqfu/image/upload/v1457314397/quotations_image_wfwimc.png">
</div>
<nav>
<img src="http://res.cloudinary.com/dp32vpqfu/image/upload/v1457364436/arrow-left_moebxn.png">
<img src="http://res.cloudinary.com/dp32vpqfu/image/upload/v1457364436/arrow-right_oilpij.png">
</nav>
</div>
</body>
So again, my thought was that I could have the .box class be a parent container and then the .text_container that would be nested could 're-size the text in a responsive manner in smaller viewports. But it's not...and my hair is going grey.
Errggghhhh...
child with the position absolute can't change the size or its parent or vice versa. Alternatively you can use the float property and set it to "right". Also, you might want to use % instead of pixels if you're aiming for a responsive design.
I guess what you need is http://freqdec.github.io/slabText/
font-size cannot do resize accroding to the windows's width, unless you define different font-size accroding to the width with Media Queries

Text not show up in p tag

My goal is to hover on next_wrapper and nav_text_title_next appears.
Now both the image and the p tag nav_text_title_next appears, but unfortunately I can't see any of the text in p tag nav_text_title_next. I use the same code for other sections, and it works well but it's not working in this part. Can you help me figure out what goes wrong?
HTML:
<div class="next_wrapper" id="next_wrapper_title" style="position:absolute; left:1050px; top:300px; z-index:5;">
<a class="next_button" href="#blah" style="background:none;">
<p class="navigation_text_next" id="nav_text_title_next">
HI!
</p>
<img class="next_button" src="img/next-icon.gif" onmouseover="this.src='img/next-icon-stop2.gif'" onmouseout="this.src='img/next-icon.gif'">
</a>
</div>
Here is the CSS:
.next_wrapper {
position: absolute;
top: 0px;
left: 95px;
}
#nav_text_title_next {
display: none;
}
#next_wrapper_title:hover #nav_text_title_next {
display: block;
}
.next_button {
width:75px;
background: none;
position: absolute;
}
.navigation_text_next {
background: #000;
color: #FFF;
font-family: AvenirLTStd-Medium;
font-weight: normal;
font-style: normal;
font-size: 11px;
position: absolute;
width: 100px;
height: 55px;
top: 30px;
left: 67px;
padding-top: 10px;
padding-bottom: 10px;
padding-left: 45px;
padding-right: 5px;
text-align: left;
display: none;
}
.next_button {
width:75px;
background: none;
position: absolute;
}
your display is none delete that and you will see your text
also delete it on your image
then do something similar to this
in html
<p>bla</p>
in css
p {
opacity:0;
}
p:hover {
opacity:1;
}
You have hidden it from view that is why.
.navigation_text_next {
background: #000;
color: #FFF;
font-family: AvenirLTStd-Medium;
font-weight: normal;
font-style: normal;
font-size: 11px;
position: absolute;
width: 100px;
height: 55px;
top: 30px;
left: 67px;
padding-top: 10px;
padding-bottom: 10px;
padding-left: 45px;
padding-right: 5px;
text-align: left;
display: none; <-- remove this
}
You can remove display: none; as it parents is hiiden and not required.

Resources