How to make a header ribbon responsive - html

I have the following JSFiddle: http://jsfiddle.net/eotamvwy/
HTML:
<div class="infobox-container">
<div class="triangle-l"></div>
<div class="triangle-r"></div>
<div class="infobox">
<h3><span>This is the Header</span></h3>
<p>This is the content of the infobox.<p/>
</div>
</div>
How can I modify the CSS so that it is responsive?
I have a div which has the following style:
width: 98%
padding: 0 1% 0 1%
I want to insert the infobox-container inside and stretch it 100% and resize based on the above div.

Use percentage units for responsiveness and for triangles you don't need extra elements, you could use :after and :before :pseudo-elements on .infobox h3.
Updated Fiddle
body {
width: 100%;
margin: 0;
}
.main-container {
width: 98%;
padding: 0 1% 0 1%;
text-align: center;
}
.infobox-container {
position: relative;
display: inline-block;
margin: 0;
padding: 0;
width: 100%;
}
.infobox {
width: 80%;
padding: 10px 5px 5px 5px;
margin: 10px;
position: relative;
z-index: 1;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px;
-webkit-box-shadow: 0px 0px 3px rgba(0, 0, 0, 0.55);
-moz-box-shadow: 0px 0px 3px rgba(0, 0, 0, 0.55);
box-shadow: 0px 0px 3px rgba(0, 0, 0, 0.55);
background: #424242;
background-image: -webkit-gradient(linear, left top, left bottom, from(#6a6b6b), to(#424242));
background-image: -moz-linear-gradient(top, #6a6a6a, #424242);
color: #fff;
font-size: 90%;
}
.infobox h3 {
position: relative;
width: calc(100% + 22px);
color: #fff;
padding: 10px 5px;
margin: 0;
left: -15px;
-webkit-box-shadow: 0px 0px 3px rgba(0, 0, 0, 0.55);
-moz-box-shadow: 0px 0px 3px rgba(0, 0, 0, 0.55);
box-shadow: 0px 0px 3px rgba(0, 0, 0, 0.55);
background: #3198dd;
background-image: -webkit-gradient(linear, left top, left bottom, from(#33acfc), to(#3198dd));
background-image: -moz-linear-gradient(top, #33acfc, #3198dd);
font-size: 160%;
text-align: center;
text-shadow: #2187c8 0 -1px 1px;
font-weight: bold;
}
.infobox h3:before,
.infobox h3:after {
content: '';
border-color: transparent #2083c2 transparent transparent;
border-style: solid;
border-width: 12px;
height: 0;
width: 0;
position: absolute;
left: -12px;
top: 100%;
transform: translateY(-50%);
z-index: -1;
/* displayed under infobox */
}
.infobox h3:after {
border-color: transparent transparent transparent #2083c2;
left: 100%;
margin-left: -12px;
}
.infobox a {
color: #35b0ff;
text-decoration: none;
border-bottom: 1px dotted transparent;
}
.infobox a:hover,
.infobox a:focus {
text-decoration: none;
border-bottom: 1px dotted #35b0ff;
}
<div class="main-container">
<div class="infobox-container">
<div class="infobox">
<h3><span>This is the Header</span></h3>
<p>This is the content of the infobox.</p>
</div>
</div>
</div>

If you want this header ribbon to be responsive, you need to get away from using fixed-widths and instead combine width:100%; and max-width: 270px; (or whatever).
When you define the width attribute to be 270px, you are telling the browser you want this particular element to have both a minimum and maximum width of 270px. If you are thinking responsively, what you actually want is for your element to expand as much as possible (width:100%), but to max-out at 270px (max-width: 270px;).
Thats the responsive bit.
What you are actually after is something closer to this:
http://jsfiddle.net/TheIronDeveloper/eotamvwy/3/
* {
box-sizing: border-box;
}
.infobox-container {
position: relative;
display: block;
margin: 0;
padding: 0;
max-width: 500px;
width: 100%;
}
.infobox {
padding: 3em 5px 5px;
margin:10px;
position: relative;
z-index: 90;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px;
-webkit-box-shadow: 0px 0px 3px rgba(0,0,0,0.55);
-moz-box-shadow: 0px 0px 3px rgba(0,0,0,0.55);
box-shadow: 0px 0px 3px rgba(0,0,0,0.55);
background: #424242;
background-image: -webkit-gradient(linear, left top, left bottom, from(#6a6b6b), to(#424242));
background-image: -moz-linear-gradient(top,#6a6a6a,#424242);
color: #fff;
font-size: 90%;
}
.infobox-ribbon {
position: absolute;
top: 10px;
width: 100%;
color: #fff;
padding: 10px 5px;
margin: 0;
z-index: 100;
-webkit-box-shadow: 0px 0px 3px rgba(0,0,0,0.55);
-moz-box-shadow: 0px 0px 3px rgba(0,0,0,0.55);
box-shadow: 0px 0px 3px rgba(0,0,0,0.55);
background: #3198dd;
background-image: -webkit-gradient(linear, left top, left bottom, from(#33acfc), to(#3198dd));
background-image: -moz-linear-gradient(top,#33acfc,#3198dd);
font-size: 160%;
text-align: center;
text-shadow: #2187c8 0 -1px 1px;
font-weight: bold;
}
.infobox-container .triangle-l {
border-color: transparent #2083c2 transparent transparent;
border-style:solid;
border-width:13px;
height:0;
width:0;
position: absolute;
left: -12px;
top: 45px;
z-index: 0; /* displayed under infobox */
}
.infobox-container .triangle-r {
border-color: transparent transparent transparent #2083c2;
border-style:solid;
border-width:13px;
height:0;
width:0;
position: absolute;
right: -12px;
top: 45px;
z-index: 0; /* displayed under infobox */
}
.infobox a {
color: #35b0ff;
text-decoration: none;
border-bottom: 1px dotted transparent;
}
.infobox a:hover, .infobox a:focus {
text-decoration: none;
border-bottom: 1px dotted #35b0ff;
}
<div class="infobox-container">
<div class="triangle-l"></div>
<div class="triangle-r"></div>
<h3 class="infobox-ribbon">This is the Header</h3>
<div class="infobox">
<p>This is the content of the infobox.</p>
</div>
</div>
I did a few things here:
I applied * {box-sizing:border-box;}, which does a nicer job at making elements "mold" to the widths that I tell them to (regardless of margins), more details here
I took the h3 ribbon out of the infobox, and changed its position to absolute. My reasoning is that the h3-ribbon needs to conform to the info-box container's width, not the infobox itself. That way, regardless of the width, the ribbon will conform to its parent, and the infobox can occupy its 100% + margins (which should always be even on both sides.)
And like I mentioned before, I changed the fixed-width of the infobox-container to width:100%;max-width:500px;. If you try resizing down, the ribbon stays in place.

I think you can just make a couple of small changes to make all the sizes responsive at least to the content:
The most important changes:
Use 'Calc' to set the width. Support is reasonable well (see caniuse), but you could also solve this differently using negative margins (or probably other ways as well).
.infobox h3 {
width: calc(100% + 20px);
}
The right arrow can simply be solved by setting right to -12px, just as the left one has left: -12px.
.infobox-container .triangle-r {
right: -12px;
}
.infobox-container {
position: relative;
display: inline-block;
margin: 0;
padding: 0;
width: auto;
}
.infobox {
padding: 10px 5px 5px 5px;
margin:10px;
position: relative;
z-index: 90;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px;
-webkit-box-shadow: 0px 0px 3px rgba(0,0,0,0.55);
-moz-box-shadow: 0px 0px 3px rgba(0,0,0,0.55);
box-shadow: 0px 0px 3px rgba(0,0,0,0.55);
background: #424242;
background-image: -webkit-gradient(linear, left top, left bottom, from(#6a6b6b), to(#424242));
background-image: -moz-linear-gradient(top,#6a6a6a,#424242);
color: #fff;
font-size: 90%;
}
.infobox h3 {
position: relative;
width: calc(100% + 20px);
color: #fff;
padding: 10px 5px;
margin: 0;
left: -15px;
z-index: 100;
-webkit-box-shadow: 0px 0px 3px rgba(0,0,0,0.55);
-moz-box-shadow: 0px 0px 3px rgba(0,0,0,0.55);
box-shadow: 0px 0px 3px rgba(0,0,0,0.55);
background: #3198dd;
background-image: -webkit-gradient(linear, left top, left bottom, from(#33acfc), to(#3198dd));
background-image: -moz-linear-gradient(top,#33acfc,#3198dd);
font-size: 160%;
text-align: center;
text-shadow: #2187c8 0 -1px 1px;
font-weight: bold;
}
.infobox-container .triangle-l {
border-color: transparent #2083c2 transparent transparent;
border-style:solid;
border-width:13px;
height:0;
width:0;
position: absolute;
left: -13px;
top: 54px;
z-index: 2; /* displayed under infobox */
}
.infobox-container .triangle-r {
border-color: transparent transparent transparent #2083c2;
border-style:solid;
border-width:13px;
height:0;
width:0;
position: absolute;
right: -12px;
top: 54px;
z-index: 2; /* displayed under infobox */
}
.infobox a {
color: #35b0ff;
text-decoration: none;
border-bottom: 1px dotted transparent;
}
.infobox a:hover, .infobox a:focus {
text-decoration: none;
border-bottom: 1px dotted #35b0ff;
}
<div class="infobox-container">
<div class="triangle-l"></div>
<div class="triangle-r"></div>
<div class="infobox">
<h3><span>This is the Headewefewfewfewfewfewfewfr</span></h3>
<p>This is the content of the infobox.</p>
</div>
</div>

Related

How to change the height of the div according to the text?

I'm having trouble putting height variant sizes according to the number of balloons in my div.
They are following a fixed height and are not changing size according to the text, I can't put the first balloon as a height smaller than the first balloon, I already tried for a negative margin that didn't work either.
//the html below is rendered by javascript
div#chat-panel-casca {
z-index: 9999;
position: fixed;
overflow: hidden;
margin: 0;
width: 500px;
opacity: 1;
border-radius: 0;
transition-delay: .6s;
transition: .7s;
top: 0;
right: 0;
}
div #chat-casca {
height: 100vh;
background-color: #F4F4F6;
position: fixed;
top: 50px;
right: 0;
width: 499px;
}
/*this stretch corresponds to a tail applied to the first balloon*/
div #chat-casca #tail {
width: 0;
height: 0;
border-width: 0 17.5px 19px 17.5px;
border-color: transparent transparent #FFFFFF transparent;
border-style: solid;
filter: drop-shadow(-6px 2px 2px rgba(166, 166, 166, 0.24));
transform: rotate(48deg);
position: relative;
border-radius: 25px;
top: -32px;
right: 19px;
}
div #chat-casca .chat-box {
border-radius: 10px;
width: 323px;
background-color: white;
position: relative;
margin-top: 12px;
left: 45px;
box-shadow: 0px 0px 5px 0px rgba(166, 166, 166, 0.60);
-webkit-box-shadow: 0px 0px 5px 0px rgba(166, 166, 166, 0.60);
-moz-box-shadow: 0px 0px 5px 0px rgba(166, 166, 166, 0.60);
}
/*This is my main css, it is the balloon composition*/
div #chat-casca .chat-box p {
padding-left: 20px;
padding-top: 10px;
position: relative;
}
div #chat-casca .chat-box .chat-time {
position: relative;
color: #4d4e53;
font-size: 9px;
font-stretch: condensed;
top: -25px;
padding-left: 293px;
}
<div id="chat-panel-casca">
<div id="chat-casca">
<div class="chat-box">
<p>Hy, i ame here</p>
<div id="tail"></div>
<small class="chat-time">9:6</small>
</div>
<div class="chat-box">
<p>Some text</p>
<p> Another text.</p>
<small class="chat-time">9:6</small>
</div>
</div>
</div>
My goal is to decrease the margin-botton of the first div of the example below and set the spacing of the following divs keeping the height proportion.
I have this result:
But I need this result
You can fix it just by changing your CSS.
Remove vertical margins from p inside .chat-box
Remove position:relative from .chat-time
Style #tail with absolute positioning
Add some padding-bottom to .chat-box
body {
background: #eee;
}
div#chat-panel-casca {
z-index: 9999;
position: fixed;
overflow: hidden;
margin: 0;
width: 500px;
opacity: 1;
border-radius: 0;
transition-delay: .6s;
transition: .7s;
top: 0;
right: 0;
}
div#chat-casca {
height: 100vh;
background-color: #F4F4F6;
position: fixed;
top: 50px;
left: 0;
width: 499px;
}
/*this stretch corresponds to a tail applied to the first balloon*/
div#chat-casca #tail {
width: 0;
height: 0;
border-width: 0 17.5px 19px 17.5px;
border-color: transparent transparent #FFFFFF transparent;
border-style: solid;
filter: drop-shadow(-6px 2px 2px rgba(166, 166, 166, 0.24));
transform: rotate(48deg);
position: absolute;
border-radius: 25px;
top: 0;
left: -19px;
}
div#chat-casca .chat-box {
border-radius: 10px;
width: 323px;
background-color: white;
position: relative;
margin-top: 12px;
left: 45px;
box-shadow: 0px 0px 5px 0px rgba(166,166,166,0.60);
-webkit-box-shadow: 0px 0px 5px 0px rgba(166,166,166,0.60);
-moz-box-shadow: 0px 0px 5px 0px rgba(166,166,166,0.60);
padding-bottom: 10px;
}
/*This is my main css, it is the balloon composition*/
div#chat-casca .chat-box p {
padding-left: 20px;
padding-top: 10px;
position: relative;
margin: 0;
}
div#chat-casca .chat-box .chat-time {
color: #4d4e53;
font-size: 9px;
font-stretch: condensed;
padding-left: 293px;
}
<div id="chat-casca">
<div class="chat-box">
<p>Hy, i ame here</p>
<div id="tail"></div>
<small class="chat-time">9:6</small>
</div>
<div class="chat-box">
<p>Some text</p>
<p> Another text.</p>
<small class="chat-time">9:6</small>
</div>
</div>
now another solution works for me
div #chat-casca .chat-box {
border-radius: 10px;
width: 323px;
background-color: white;
position: relative;
display: flex; /*add this line*/
flex-flow: wrap; /*and this line*/
margin-top: 12px;
left: 45px;
box-shadow: 0px 0px 5px 0px rgba(166, 166, 166, 0.60);
-webkit-box-shadow: 0px 0px 5px 0px rgba(166, 166, 166, 0.60);
-moz-box-shadow: 0px 0px 5px 0px rgba(166, 166, 166, 0.60);
}
thanks everbody for try help me
Your tail div is interfering with the chat box's height.
Rather than using an actual div for the tail, try adding a class to the existing chat-casca div when you need the tail.
<div class="chat-box tail">
then add the ::before selector so it doesn't interfere with the other elements. Position this absolute and the chat-box positioned relative, then you can position the tail relative to the chat box.
#chat-casca .tail::before {
content: "";
width: 0px;
height: 0px;
position: absolute;
border-left: 10px solid transparent;
border-right: 10px solid #fff;
border-top: 10px solid #fff;
border-bottom: 10px solid transparent;
left: -19px;
top: 0px;
filter: drop-shadow(-4px 2px 2px rgba(166, 166, 166, 0.24));
}
#chat-casca .chat-box {
border-radius: 0 10px 10px 10px;
width: 323px;
background-color: white;
position: relative;
margin-top: 0;
margin-left: 45px;
height: auto;
box-shadow: 0px 0px 5px 0px rgba(166, 166, 166, 0.60);
-webkit-box-shadow: 0px 0px 5px 0px rgba(166, 166, 166, 0.60);
-moz-box-shadow: 0px 0px 5px 0px rgba(166, 166, 166, 0.60);
}

Why wont my css styling of background color ,width, and height work on my last div >gameover?

Why wont my css styling of background color ,width, and height work on my last div >gameover ?
this first part is my html code:
<head>
<title>Maths Game</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-
scalable=yes">
<link rel="stylesheet" href="styling.css">
</head>
<body>
<div id="container">
<div id="score">Score: <span id="scoreValue">0</span></div>
<div id="correct">Correct</div>
<div id="wrong">Try Again</div>
<div id="question">7x7</div>
<div id="instructionBox">Click on the correct answer</div>
<div id="choices">
<div id="box1" class="box">1</div>
<div id="box2" class="box">2</div>
<div id="box3" class="box">3</div>
<div id="box4" class="box">4</div>
</div>
<div id="startReset">start Game</div>
Im guessing right here below is where it started getting messed up:
<div id="timeremaining">Time remaining:<span id="timeRemainingValue">
60</span> sec</div>
<div id="gameOver">
<p>Game Over!</p>
<p>Your score is __</p>
</div>
</div>
this second part is my css code and only the last style "game over" isn't working;
html {
height: 100%;
background: radial-gradient(circle, white, grey);
}
#container {
height: 440px;
width: 550px;
background-color: #9DD2EA;
margin: 100px auto;
/* this line directly above centers the container top and bottom 100px and left and
right to auto so that margin keeps getting
bigger and bigger on both sides till the element is center */
padding: 10px;
border-radius: 20px;
/* above line curves corners of element */
box-shadow: 4px 4px 6px 6px purple;
-webkit-box-shadow: 4px 4px 6px 6px purple;
-moz-box-shadow: 4px 4px 6px 6px purple;
/* [horizontal offset] [vertical offset] [blur radius] [optional spread radius] [color]
*/
position: relative;
}
#score {
background-color: yellow;
padding: 10px;
position: absolute;
left: 475px;
box-shadow: 0px 4px purple;
-moz-box-shadow: 0px 4px purple;
-webkit-box-shadow: 0px 4px purple;
}
#correct {
position: absolute;
left: 240px;
background-color: green;
color: white;
padding: 10px;
display: none;
}
#wrong {
/* line 45 makes it to where this element does not interact with other elements and
other elements behave as if it doesent exist*/
position: absolute;
left: 240px;
background-color: red;
color: white;
padding: 10px;
display: none;
}
#question {
margin: 55px auto 10px auto;
height: 150px;
width: 420px;
background-color: rgb(184, 53, 240);
box-shadow: 0px 4px purple;
font-size: 100px;
text-align: center;
font-family: Arial, Helvetica, sans-serif, sans-serif;
line-height: 150px;
color: black;
border-radius: 5px;
position: relative;
}
#question:active {
box-shadow: 0px 0px purple;
-moz-box-shadow: 0px 0px purple;
-webkit-box-shadow: 0px 0px purple;
top: 4px
}
#instructionBox {
height: 60px;
width: 420px;
background-color: blue;
margin: 1px auto 1px auto;
text-align: center;
line-height: 55px;
box-shadow: 0px 4px purple;
-moz-box-shadow: 0px 4px purple;
-webkit-box-shadow: 0px 4px purple;
border-radius: 5px;
position: relative;
/* transition: all 0.2s; line 71 & 72 with line 77 make the transition happen on click
*/
}
#instructionBox:active {
box-shadow: 0px 0px purple;
-moz-box-shadow: 0px 0px purple;
-webkit-box-shadow: 0px 0px purple;
top: 4px;
}
#choices {
/* background-color: sandybrown; */
height: 100px;
width: 420px;
margin: 10px auto;
color: black;
text-align: center;
line-height: -50px;
margin: 10px auto;
border-radius: 5px;
}
.box {
/*these boxes are within a choices div to help them size together*/
margin-right: 26px;
width: 85px;
height: 85px;
background-color: white;
float: left;
border-radius: 5px;
cursor: pointer;
box-shadow: 0px 4px grey;
-moz-box-shadow: 0px 4px grey;
-webkit-box-shadow: 0px 4px grey;
line-height: 80px;
position: relative;
/* with position relative and .box:active { top: 4px; the box moves down 4px}*/
/* transition: all 0.2s;
-webkit-transition: all 0.2s;
-moz-transition: all 0.2s;
-o-transition: all 0.2s;
-ms-transition: all 0.2s; */
}
.box:hover,
#startReset:hover {
background-color: grey;
color: white;
box-shadow: 0px 4px purple;
-webkit-box-shadow: 0px 4px purple;
-moz-box-shadow: 0px 4px purple;
}
.box:active,
#startReset:active {
box-shadow: 0px 0px purple;
-webkit-box-shadow: 0px 0px purple;
-moz-box-shadow: 0px 0px purple;
top: 4px;
}
/* #box1{
margin: 10px 10px;
background-color: red;
width: 30px;
height: 30px;
}
#box2{
margin: 10px 10px;
background-color: white;
width: 30px;
height: 30px;
}
#box3{
margin: 10px 10px;
background-color: blue;
width: 30px;
height: 30px;
}*/
#box4 {
margin-right: 0;
}
#startReset {
/*these boxes are within a choices div to help them size together*/
margin-left: 230px;
width: 100px;
height: 45px;
background-color: rgb(255, 255, 255, 0.5);
float: left;
border-radius: 5px;
cursor: pointer;
box-shadow: 0px 4px grey;
-moz-box-shadow: 0px 4px grey;
-webkit-box-shadow: 0px 4px grey;
line-height: 45px;
text-align: center;
position: relative;
}
/* instead of writing these same pargraphs of code just at the element id to the similar
code alrady made like above */
/* #startReset:hover{
background-color: grey;
color: white;
box-shadow: 0px 4px purple;
-webkit-box-shadow: 0px 4px purple;
-moz-box-shadow: 0px 4px purple;
}
#startReset:active{
box-shadow: 0px 0px purple;
-webkit-box-shadow: 0px 0px purple;
-moz-box-shadow: 0px 0px purple;
top: 4px;
} */
#timeremaining {
/*these boxes are within a choices div to help them size together*/
visibility: hidden;
/* display: none; */
margin-left: 10px;
width: 200px;
height: 45px;
background-color: greenyellow;
float: left;
border-radius: 5px;
cursor: pointer;
box-shadow: 0px 4px grey;
-moz-box-shadow: 0px 4px grey;
-webkit-box-shadow: 0px 4px grey;
line-height: 45px;
text-align: center;
position: relative;
}
this below is the broken part with the >gameover style or gameOver div:
#gameOver {
height: 200px;
width: 500px;
background-color: linear-gradient(blue, green);
font-size: 1.0em;
}

Is it Possible to Draw a Triple Border only on one side of a Rectangle?

I would like to have a Triple Border only one side of a rectangle Without using an Extra Html tag.The Code I have tried so far is Given Below.
Method#1
#element {
width: 100px;
height: 100px;
box-shadow: 0 0 0 3px #000, 0 0 0 6px #f00, 0 0 0 9px #000;
}
<div id="element"></div>
Method#2
#element {
width: 100px;
height: 100px;
border: 3px solid black; /* inner border */
box-shadow: 0px 0px 0px 15px black; /* outer 'border' */
outline: 12px solid green; /* fill */
margin-left: 30px;
margin-top: 30px;
}
<div id="element"></div>
But this can be only use in case if you need Triple Border on all Sides,Instead Of that I only needs the Triple Border on One side.Is it Possible?.Please Help me
Using this CSS Property
box-shadow: 5px 0px 0 0px #000, 10px 0px 0 0px #f00, 15px 0px 0px 0px #000;
#element {
width: 100px;
height: 100px;
box-shadow: 5px 0px 0 0px #000, 10px 0px 0 0px #f00, 15px 0px 0px 0px #000;
}
<div id="element"></div>
You can use before and after to achieve this.
#element {
width: 100px;
height: 100px;
border-right: 5px solid black; /* inner border */
/* box-shadow: 0px 0px 0px 15px black; */ /* outer 'border' */
/* outline: 12px solid green; */ /* fill */
margin-left: 30px;
margin-top: 30px;
}
.triple-right {
position: relative;
}
.triple-right:before, .triple-right:after {
content: "";
position: absolute;
top: 0;
bottom: 0;
width: 5px;
}
.triple-right:before {
background-color: green;
right: -10px;
}
.triple-right:after {
background-color: black;
right: -15px;
}
<div id="element" class="triple-right"></div>
Here is another idea using gradient:
#element {
width: 100px;
height: 100px;
background:
linear-gradient(#000,#000) right/ 5px 100%,
linear-gradient(red,red) right/ 10px 100%,
linear-gradient(blue,blue) right/ 15px 100%;
/*And so on if you want more border*/
background-repeat:no-repeat;
}
<div id="element"></div>

how to put margin between p and h1 tag?

I have call to action bar, inside it there is a h1 tag for slogan and a p tag with a link for actual call to action. I can not marging them properly h1 tag ride on p tag.
SCREENSHOT
HTML
<div id="call-to-act">
<h1>We are Andia, a super cool design agency.We design beautiful websites, logos and prints. Your project is safe with us.</h1>
<p>Contact Us</p>
</div> <!-- end of call-to-action -->
CSS:
div#call-to-act {
background: #fff;
width: 100%;
height: 100px;
position: relative;
margin: 50px auto;
-webkit-box-shadow: inset 10px 10px 72px -28px rgba(0,0,0,0.75);
-moz-box-shadow: inset 10px 10px 72px -28px rgba(0,0,0,0.75);
box-shadow: inset 10px 10px 72px -28px rgba(0,0,0,0.75);
width: 80%;
}
div#call-to-act p {
height: 100%;
}
div#call-to-act a.call2act {
text-indent:0;
border:1px solid #dcdcdc;
display:inline-block;
color:#777777;
font-family:arial;
font-size:15px;
font-weight:bold;
font-style:normal;
height:44px;
line-height:44px;
width:120px;
text-decoration:none;
text-align:center;
text-shadow:1px 1px 0px #ffffff;
position: absolute;
right: 20px;
top: 20px;
}
You can use position: absolute; right: 0; top: 50%; to put the button on the right side 50% from the top, then transform: translateY(-50%) to move the button up half of it's own width to center it vertically. Then apply padding-right: 130px to the parent to make room for the 120px wide button.
* {
margin: 0;
padding: 0;
}
div#call-to-act {
background: #fff;
width: 100%;
min-height: 46px;
position: relative;
margin: 50px auto;
-webkit-box-shadow: inset 10px 10px 72px -28px rgba(0, 0, 0, 0.75);
-moz-box-shadow: inset 10px 10px 72px -28px rgba(0, 0, 0, 0.75);
box-shadow: inset 10px 10px 72px -28px rgba(0, 0, 0, 0.75);
width: 80%;
box-sizing: border-box;
padding-right: 130px;
}
div#call-to-act p {}
div#call-to-act a.call2act {
text-indent: 0;
border: 1px solid #dcdcdc;
display: inline-block;
color: #777777;
font-family: arial;
font-size: 15px;
font-weight: bold;
font-style: normal;
height: 44px;
line-height: 44px;
width: 120px;
text-decoration: none;
text-align: center;
text-shadow: 1px 1px 0px #ffffff;
position: absolute;
top: 50%;
right: 0;
transform: translateY(-50%);
}
<div id="call-to-act">
<h1>We are Andia, a super cool design agency.We design beautiful websites, logos and prints. Your project is safe with us.</h1>
<p>Contact Us</p>
</div>
<!-- end of call-to-action -->

making ribbon center using css

Im creating a ribbon using css. the page it is on is FOUND HERE
I know the rest of my page needs more work but right this second I am focusing on the ribbon.
I need it to be auto 90% and center no matter what the screen size. at the moment it is cut off on the left a little and not center.
my css code:
.ribbon {
width: 90%;
position: absolute;
text-align: center;
font-size: 15px!important;
background: #2cdb1c;
background: -webkit-gradient(linear, left top, left bottom, from(#2cdb1c), to(#618028));
background: -webkit-linear-gradient(top, #2cdb1c, #618028);
background: -moz-linear-gradient(top, #2cdb1c, #618028);
background: -ms-linear-gradient(top, #2cdb1c, #618028);
background: -o-linear-gradient(top, #2cdb1c, #618028);
background-image: -ms-linear-gradient(top, #2cdb1c 0%, #618028 100%);
-webkit-box-shadow: rgba(000,000,000,0.3) 0 1px 1px;
-moz-box-shadow: rgba(000,000,000,0.3) 0 1px 1px;
box-shadow: rgba(000,000,000,0.3) 0 1px 1px;
font-family: 'Helvetica Neue',Helvetica, sans-serif;
}
.ribbon h1 {
font-size: 23px!important;
color: #000000;
text-shadow: #b9c9b5 0 1px 0;
margin:0px;
padding: 15px 10px;
}
.ribbon:before, .ribbon:after {
content: '';
position: absolute;
display: block;
bottom: -1em;
border: 1.5em solid #379c27;
z-index: -1;
}
.ribbon:before {
left: -2em;
border-right-width: 1.5em;
border-left-color: transparent;
-webkit-box-shadow: rgba(000,000,000,0.4) 1px 1px 1px;
-moz-box-shadow: rgba(000,000,000,0.4) 1px 1px 1px;
box-shadow: rgba(000,000,000,0.4) 1px 1px 1px;
}
.ribbon:after {
right: -2em;
border-left-width: 1.5em;
border-right-color: transparent;
-webkit-box-shadow: rgba(000,000,000,0.4) -1px 1px 1px;
-moz-box-shadow: rgba(000,000,000,0.4) -1px 1px 1px;
box-shadow: rgba(000,000,000,0.4) -1px 1px 1px;
}
.ribbon .ribbon-content:before, .ribbon .ribbon-content:after {
border-color: #000000 transparent transparent transparent;
position: absolute;
display: block;
border-style: solid;
bottom: -1em;
content: '';
}
.ribbon .ribbon-content:before {
left: 0;
border-width: 1em 0 0 1em;
}
.ribbon .ribbon-content:after {
right: 0;
border-width: 1em 1em 0 0;
}
.ribbon-stitches-top {
margin-top:2px;
border-top: 1px dashed rgba(0, 0, 0, 0.2);
-moz-box-shadow: 0px 0px 2px rgba(0, 0, 0, 0.5);
-webkit-box-shadow: 0px 0px 2px rgba(0, 0, 0, 0.5);
box-shadow: 0px 0px 2px rgba(255, 255, 255, 0.5);
}
.ribbon-stitches-bottom {
margin-bottom:2px;
border-top: 1px dashed rgba(0, 0, 0, 0.2);
-moz-box-shadow: 0px 0px 2px rgba(0, 0, 0, 0.3);
-webkit-box-shadow: 0px 0px 2px rgba(0, 0, 0, 0.3);
box-shadow: 0px 0px 2px rgba(255, 255, 255, 0.3);
}
Can someone please help me? thank you.
It can't be positioned as absolute. Remove that. Make sure its parent has 100% width and then set margin:0 auto;
You could put your entire ribbon inside a divide. Then instead of centering the ribbon just give it a width of 100%.
ribbon_divide {
margin: 0 auto;
width: 90%;
}
You should wrap ribbon element and set width=100% for ribbon.
.ribbon-wrapper {
position: relative;
width: 90%;
margin: 0 auto;
}
.ribbon {
width: 100%
}
<div class="ribbon-wrapper">
<!-- Your ribbon html code -->
</div>
Just wrap your ribbon with a div.
<div style="width:90%;margin:0 auto;">
<div class="ribbon"><div class="ribbon-stitches-top"></div><strong class="ribbon-content"><h1>Xclo.mobi</h1></strong><div class="ribbon-stitches-bottom"></div></div>
</div>
You could actually center it based on percentage and absolutely:
.ribbon {
position: absolute;
width: 90%;
left: 50%;
margin-left: -45%;
}