I'm trying to display rotated text whereby its always absolute positioned to the bottom of its parent. The parent is 100% height of the browser window and I'd like the text to appear 50px from the bottom for all browser/screen sizes.
Here's my code:
html,body,.carousel,.carousel a.item { height: 100%; }
.carousel a.item {
height: 100%;
padding-top: 100px;
position: relative;
overflow: hidden;
width: 25%;
float: left;
}
.rotate {
zoom: 1;
white-space: nowrap;
position: absolute;
bottom: 0;
right: 0;
z-index: 3;
display: block;
width: 100%;
background: pink;
-webkit-transform-origin: right bottom;
-moz-transform-origin: right bottom;
-o-transform-origin: right bottom;
-ms-transform-origin: right bottom;
transform-origin: right bottom;
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
-o-transform: rotate(-90deg);
-ms-transform: rotate(-90deg);
transform: rotate(-90deg);
}
.carousel a.item h1 {
color: #fff;
position: absolute;
right: 0;
bottom: 0;
height: 100%;
width: 100%;
background: blue;
z-index: 5;
display: block;
}
.bg-image {
background-repeat: no-repeat;
background-position: center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
<div class="carousel">
<a href="#" class="item bg-image" style="background-image: url('https://placeholdit.imgix.net/~text?txtsize=33&txt=300%C3%97800&w=300&h=800');">
<div class="rotate">
<h1>Some really long title thats quite long. Did I say it was long?</h1>
</div>
</a>
<a href="#" class="item bg-image" style="background-image: url('http://www.freelargeimages.com/wp-content/uploads/2014/12/Landscape_01.jpg');">
<div class="rotate">
<h1>This is really short</h1>
</div>
</a>
<a href="#" class="item bg-image" style="background-image: url('https://placeholdit.imgix.net/~text?txtsize=33&txt=300%C3%97800&w=300&h=800');">
<div class="rotate">
<h1>Short but also longer but not to long</h1>
</div>
</a>
<a href="#" class="item bg-image" style="background-image: url('http://www.freelargeimages.com/wp-content/uploads/2014/12/Landscape_01.jpg');">
<div class="rotate">
<h1>Some really long title thats quite long. Did I say it was long?</h1>
</div>
</a>
</div>
I have a fiddle setup of my code so far: https://jsfiddle.net/77xzfsfa/ and here's an image of what I'm trying to achieve:
You don't need to absolutely position the content of the rotated element.
Just adjust the transforms and transform origin.
.rotate{
zoom: 1;
white-space: nowrap;
position: absolute;
z-index: 3;
display: inline-block;
position: absolute;
right: 0;
bottom: 50px;
transform:translate(100%,0%) rotate(-90deg);
transform-origin:bottom left;
}
.carousel a.item h1 {
color: #fff;
z-index: 5;
}
* {
margin: 0;
}
html,
body,
.carousel,
.carousel a.item {
height: 100%;
}
.carousel a.item {
height: 100%;
padding-top: 100px;
position: relative;
overflow: hidden;
width: 25%;
float: left;
}
.rotate {
zoom: 1;
white-space: nowrap;
position: absolute;
z-index: 3;
display: inline-block;
position: absolute;
right: 0;
bottom: 50px;
transform: translate(100%, 0%) rotate(-90deg);
transform-origin: bottom left;
}
.carousel a.item h1 {
color: #fff;
z-index: 5;
}
.bg-image {
background-repeat: no-repeat;
background-position: center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
<div class="carousel">
<a href="#" class="item bg-image" style="background-image: url('https://placeholdit.imgix.net/~text?txtsize=33&txt=300%C3%97800&w=300&h=800');">
<div class="rotate">
<h1>Some really long title thats quite long. Did I say it was long?</h1>
</div>
</a>
<a href="#" class="item bg-image" style="background-image: url('http://www.freelargeimages.com/wp-content/uploads/2014/12/Landscape_01.jpg');">
<div class="rotate">
<h1>This is really short</h1>
</div>
</a>
<a href="#" class="item bg-image" style="background-image: url('https://placeholdit.imgix.net/~text?txtsize=33&txt=300%C3%97800&w=300&h=800');">
<div class="rotate">
<h1>Short but also longer but not to long</h1>
</div>
</a>
<a href="#" class="item bg-image" style="background-image: url('http://www.freelargeimages.com/wp-content/uploads/2014/12/Landscape_01.jpg');">
<div class="rotate">
<h1>Some really long title thats quite long. Did I say it was long?</h1>
</div>
</a>
</div>
You need to tweak the transform-origin and the positioning of the .rotate element like this :
html,body,.carousel,.carousel a.item { height: 100%; }
.carousel a.item {
height: 100%;
padding-top: 100px;
position: relative;
overflow: hidden;
width: 25%;
float: left;
}
.rotate {
white-space: nowrap;
position: absolute;
bottom: 50px;
left: 100%;
transform-origin: left bottom;
transform: rotate(-90deg);
}
.carousel a.item h1 {
color: #fff;
}
.bg-image {
background-repeat: no-repeat;
background-position: center center;
background-size: cover;
}
<div class="carousel">
<a href="#" class="item bg-image" style="background-image: url('https://placeholdit.imgix.net/~text?txtsize=33&txt=300%C3%97800&w=300&h=800');">
<div class="rotate"><h1>Some really long title thats quite long. Did I say it was long?</h1></div>
</a>
<a href="#" class="item bg-image" style="background-image: url('http://www.freelargeimages.com/wp-content/uploads/2014/12/Landscape_01.jpg');">
<div class="rotate"><h1>This is really short</h1></div>
</a>
<a href="#" class="item bg-image" style="background-image: url('https://placeholdit.imgix.net/~text?txtsize=33&txt=300%C3%97800&w=300&h=800');">
<div class="rotate"><h1>Short but also longer but not to long</h1></div>
</a>
<a href="#" class="item bg-image" style="background-image: url('http://www.freelargeimages.com/wp-content/uploads/2014/12/Landscape_01.jpg');">
<div class="rotate"><h1>Some really long title thats quite long. Did I say it was long?</h1></div>
</a>
</div>
Note that I removed all the vendor prefixes in the snippet for answer brievity and removed unecessary CSS.
when you do put rotate: -90px
the real bottom is the left
the real right is the bottom
then we can say:
bottom -> right
right -> top
top -> left
left -> bottom
but when you put here
left: 0px;
it does not really 0px;
because on calculate from the center of div in horizontal position
for you code it will be correctly
like this
.carousel a.item h1 {
color: #fff;
font-size: 15px;
font-weight: 400;
position: absolute; bottom:10px; left: 150px;
height: 100%;
width: 100%;
background: blue;
z-index: 5;
display: block;
}
Try this, simply put the <br> in the code:
<div class="rotate">
<h1>Short but also longer but not to long</h1>
<br>
</div>
Related
I want to center all items within the contacts class
.contacts {
width: 250px;
height: 500px;
margin-left: 37px;
margin-top: 50px;
position: relative;
background-color: aqua;
}
.contact-card {
position: absolute;
left: 0;
right: 0;
}
.contacts .contact-card img {
width: 225px;
height: 200px;
object-fit: cover;
}
<div className="contacts">
<div className="contact-card">
<img src="https://dummyimage.com/600x400/357f94/00ff04" />
<h3>Mr.Whiskerson</h3>
<div className="info-group">
<i className="fa-solid fa-phone"></i>
<p>(212) 555-1234</p>
</div>
<div className="info-group">
<i className="fa-solid fa-envelope"></i>
<p>MrWhiskerson.meow</p>
</div>
</div>
</div>
when I set as position left 0 and right 0 nothing is change how can I do this using position absolute
Just use Flexbox property (or Grid) to center elements.
I'll add in your code display:flex to the main container, and set justify-content: center; to center it's child horizontally (Jusitfy-content defines the alignment along the main axis).
.contacts {
width: 250px;
height: 500px;
margin-left: 37px;
margin-top: 50px;
position: relative;
background-color: aqua;
display:flex;/* add */
justify-content:center; /* add */
}
.contact-card {
/*position: absolute; remove
left: 0;
right: 0;*/
}
.contacts .contact-card img {
width: 225px;
height: 200px;
object-fit: cover;
}
<div class="contacts">
<div class="contact-card">
<img src="https://dummyimage.com/600x400/357f94/00ff04" />
<h3>Mr.Whiskerson</h3>
<div class="info-group">
<i class="fa-solid fa-phone"></i>
<p>(212) 555-1234</p>
</div>
<div class="info-group">
<i class="fa-solid fa-envelope"></i>
<p>MrWhiskerson.meow</p>
</div>
</div>
</div>
If you want to use position:absolute instead you can do this way
.contacts {
width: 250px;
height: 500px;
margin-left: 37px;
margin-top: 50px;
position: relative;
background-color: aqua;
}
.contact-card {
position: absolute;
left: 50%;
transform: translateX(-50%);
}
.contacts .contact-card img {
width: 225px;
height: 200px;
object-fit: cover;
}
<div class="contacts">
<div class="contact-card">
<img src="https://dummyimage.com/600x400/357f94/00ff04" />
<h3>Mr.Whiskerson</h3>
<div class="info-group">
<i class="fa-solid fa-phone"></i>
<p>(212) 555-1234</p>
</div>
<div class="info-group">
<i class="fa-solid fa-envelope"></i>
<p>MrWhiskerson.meow</p>
</div>
</div>
</div>
I have a little css problem, and i dont know of its completely possible to do this in css, but i accept any other solution aswell.
Here i have an example of what i am trying to accomplish.
I am trying to add the red circles in the top right of the divisions.
My code sofar:
HTML
<div class="w3-container customheight">
<div class="center buttons">
<a class="todo roundbutton">
<div class="redicon"></div>
<div class="redicontext">
<span class="todotext">1</span>
</div>
</a>
<a class="decision roundbutton">
<div class="redicontext">
<span class="decisiontext">2</span>
</div>
</a>
<a class="remark roundbutton">
<div class="redicontext"></div>
<span class="remarktext">3</span>
</div>
</a>
</div>
</div>
CSS
.center{
margin: 0 auto;
}
.roundbutton{
width: calc(33.333% - 20px);
height: 100%;
margin: 10px;
margin-top: 20px;
margin-bottom: 20px;
display:block;
background-size: contain;
float:left;
background-repeat: no-repeat;
background-position: center center;
position: relative;
}
.todo{
background-image: url("../img/todo.jpg");
}
.decision{
background-image: url("../img/decision.jpg");
}
.remark{
background-image: url("../img/remark.jpg");
}
.redicon{
position: absolute;
top: 10px;
left: 3%;
background: red;
padding:10px;
box-sizing: border-box;
border-radius: 100%;
}
.redicontext{
position: absolute;
top: 10px;
right: 3%;
padding:10px;
box-sizing: border-box;
border-radius: 100%;
}
I tried multiple things already:
- creating another div behind the first one to use padding on that div without creating an ovale
- absolute values for the red circles, this can be used with a certain height and width, but it has to work responsive.
I am not that good in css, but i know the basics.
Any help on this is really nice!
Greetings!
Use a relative position and position the circle.
.redicon{
position: absolute;
top: -10px;
right: -10px;
background: red;
padding:10px;
box-sizing: border-box;
border-radius: 100%;
}
Snippet
.center{
margin: 0 auto;
}
.roundbutton{
width: calc(33.333% - 20px);
height: 130px;
margin: 10px;
margin-top: 20px;
margin-bottom: 20px;
display:block;
background-size: contain;
float:left;
background-repeat: no-repeat;
background-position: center center;
position: relative;
}
.todo{
background-image: url("//placehold.it/150");
background-color: #fff;
border-radius: 100%;
}
.decision{
background-image: url("//placehold.it/150");
background-color: #fff;
border-radius: 100%;
}
.remark{
background-image: url("//placehold.it/150");
background-color: #fff;
border-radius: 100%;
}
.redicon{
position: absolute;
top: -10px;
right: -10px;
background: red;
padding:10px;
box-sizing: border-box;
border-radius: 100%;
}
.redicontext{
position: absolute;
top: 10px;
right: 3%;
padding:10px;
box-sizing: border-box;
border-radius: 100%;
}
<div class="w3-container customheight" style="width: 450px;">
<div class="center buttons">
<a class="todo roundbutton">
<div class="redicon"></div>
<div class="redicontext">
<span class="todotext">1</span>
</div>
</a>
<a class="decision roundbutton">
<div class="redicontext">
<span class="decisiontext">2</span>
</div>
</a>
<a class="remark roundbutton">
<div class="redicontext">
<span class="remarktext">3</span>
</div>
</a>
</div>
</div>
Preview
I have created a website and i am unable to make the tiled layout responsive. I am a beginner and i have no idea how to make my website responsive. Any help will be appreciated. The css and html is given below. Plus the background is repeating itself 3 times while i have added no repeat property in css.
HTML
<div class="grid">
<div class="tile hvr-reveal " id="tile1">
<div style="text-align: center;">
<div class="img-with-text ">
<p>
<strong>
Contact Us
</strong>
<img src="homepage images/file242.png" alt="sometext" width="64" height="64" id="img0"/>
</p>
</div>
</div>
</div>
<div class="tile hvr-reveal" id="tile2">
<div style="text-align: center;">
<div class="img-with-text">
<p>
<strong>
Products
</strong>
<img src="homepage images/shopping145.png" alt="sometext" width="64" height="64" id="img"/>
</p>
</div>
</div>
</div>
<div class="tile hvr-reveal " id="tile3">
<div style="text-align: center;">
<div class="img-with-text">
<p>
<strong>
Partners
</strong>
<img src="homepage images/celebration19.png" alt="sometext" width="64" height="64" id="img2"/>
</p>
</div>
</div>
</div>
<div class="tile hvr-reveal" id="tile4">
<div style="text-align: center;">
<div class="img-with-text">
<p>
<strong>
About Us
</strong>
<img src="homepage images/men16.png" alt="sometext" width="64" height="64" id="img1"/>
</p>
</div>
</div>
</div>
</div>
CSS
body {
font-family: chewy;
color: #ffffff;
background-image: url(pictures%20for%20web/bg3.jpg) ;
background-position: center center;
background-attachment: fixed;
background-size: cover;
**strong text**background-repeat: no-repeat;
webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
}
.grid {
width: 1140px;
height: 650px;
margin: auto;
}
.tile {
position: absolute;
width: 200px;
left: 451px;
top: 152px;
height: 152px;
box-sizing: border-box;
}
#tile1 {
top: 407px;
left: 754px;
width: 338px;
height: 196px;
margin-left: 2px;
margin-right: 2px;
background-color: #ff3300;
}
#tile2 {
margin-left: 2px;
margin-right: 2px;
top: 100px;
left: 980px;
width: 148px;
height: 154px;
background-color: #008000;
}
#tile3 {
top: 255px;
left: 523px;
width: 200px;
height: 150px;
background-color: #660066 ;
margin-left: 2px;
margin-right: 2px;
}
#tile4 {
top: 255px;
left: 118px;
width: 200px;
height: 150px;
background-color: #990000;
margin-left: 2px;
margin-right: 2px;
}
I'm guessing you want something like this:
<div class="container">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
.container {
position: relative;
top: 0;
left: 0;
width: 90%;
height: auto;
margin-left: 5%;
background-color: #444;
display: block;
text-align: center;
}
.box {
border: solid 1px #000;
height: 200px;
width: 200px;
display: inline-block;
margin: 25px auto;
}
.box:nth-of-type(1){
background: yellow;
}
.box:nth-of-type(2){
background: red;
}
.box:nth-of-type(3){
background: blue;
}
.box:nth-of-type(4){
background: green;
}
Which will keep the boxes aligned and depending on the width of the browser, shifts them.
http://codepen.io/DB1500/pen/JGqaBZ
Currently I'm working on a website which contains four rows. I'd like to center the container horizontally and vertically where horizontally centering is already done.
Can anyone help me, please? I already tried with "display: flex" but it still doesn't work.
I'm working with Twitter Bootstrap and Font Awesome.
https://jsfiddle.net/L9dbzgpr/
Code:
<div class="container text-center">
<div class="row">
<div class="col-sm-3"> <i class="fa fa-5x fa-desktop"></i>
</div>
<div class="col-sm-3"> <i class="fa fa-5x fa-music"></i>
</div>
<div class="col-sm-3"> <i class="fa fa-5x fa-cloud"></i>
</div>
<div class="col-sm-3"> <i class="fa fa-5x fa-cog"></i>
</div>
</div>
<div class="row margin-top">
<div class="col-sm-3"> <i class="fa fa-5x fa-youtube-play"></i>
</div>
<div class="col-sm-3"> <i class="fa fa-5x fa-facebook"></i>
</div>
<div class="col-sm-3"> <i class="fa fa-5x fa-soundcloud"></i>
</div>
<div class="col-sm-3"> <i class="fa fa-5x fa-google"></i>
</div>
</div>
<div class="row margin-top">
<div class="col-sm-3"> <i class="fa fa-5x fa-instagram"></i>
</div>
<div class="col-sm-3"> <i class="fa fa-5x fa-dropbox"></i>
</div>
<div class="col-sm-3"> <i class="fa fa-5x fa-twitter"></i>
</div>
<div class="col-sm-3"> <i class="fa fa-5x fa-cog"></i>
</div>
</div>
<div class="row margin-top">
<div class="col-sm-3"> <i class="fa fa-5x fa-cog"></i>
</div>
<div class="col-sm-3"> <i class="fa fa-5x fa-desktop"></i>
</div>
<div class="col-sm-3"> <i class="fa fa-5x fa-music"></i>
</div>
<div class="col-sm-3"> <i class="fa fa-5x fa-cloud"></i>
</div>
</div>
</div>
CSS:
#charset "UTF-8";
/********** General styles **********/
body {
font-size: 16px;
background: url('../media/images/banner.jpg') no-repeat center center fixed;
background-repeat: no-repeat;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
width: 100%;
height: 100%;
position: relative;
}
a, a:focus, a:active {
text-decoration: none;
color: #F9F9F9;
opacity: 0.7;
}
a>.fa:hover, a:hover {
-webkit-transition: all .5s ease;
transition: all .5s ease;
transform: scale(1.2);
opacity: 1;
}
.container {
margin: 0 auto; /* horizontally centered */
}
.margin-top {
margin-top: 3em;
}
Update of my solution:
HTML:
#charset "UTF-8";
/********** General styles **********/
html, body {
height: 100%;
margin: 0;
}
body {
font-size: 16px;
background: url('../media/images/banner.jpg') no-repeat center center fixed;
background-repeat: no-repeat;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
a, a:focus, a:active {
text-decoration: none;
color: #F9F9F9;
opacity: 0.7;
}
a>.fa:hover, a:hover {
-webkit-transition: all .5s ease;
transition: all .5s ease;
transform: scale(1.2);
opacity: 1;
}
.wrapper {
display: table;
height: 100%;
margin: 0 auto;
}
.wrapper-inner {
display: table-cell;
vertical-align: middle;
}
.margin-top {
margin-top: 3em;
}
.col-sm-3 {
padding-right: 4em;
padding-left: 4em;
}
CSS:
#charset "UTF-8";
/********** General styles **********/
html, body {
height: 100%;
margin: 0;
}
body {
font-size: 16px;
background-color: blue;
background-repeat: no-repeat;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
a, a:focus, a:active {
text-decoration: none;
color: #F9F9F9;
opacity: 0.7;
}
a>.fa:hover, a:hover {
-webkit-transition: all .5s ease;
transition: all .5s ease;
transform: scale(1.2);
opacity: 1;
}
.wrapper {
display: table;
height: 100%;
margin: 0 auto;
}
.wrapper-inner {
display: table-cell;
vertical-align: middle;
}
.margin-top {
margin-top: 3em;
}
.col-sm-3 {
padding-right: 4em;
padding-left: 4em;
}
Patrick F, Hi there.
Have a look at just using this to center both ways.
.center {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
In your code you use col-sm-3 I changed this to col-xs-3 to stop all the display items going 1 row vertical in small screens. Unless that is what you want to happen.
Resize the window and you will see what I mean.
Here is the Fiddle.
If you don't know the height and width of the container you could use this styling to center the element horizontally and vertically:
.container {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
But I don't know if this has other unwanted effects.
I need some advice on this issue i'm having. In the jsfiddle below, I'm trying to create a responsive grid layout. The issue with what i have is, i would like the text to be in the middle of each individual grid. I've tried bumping it using margin-top but instead of the images stacking onto each other while resizing, the images are overlapping each other. The end result desired will be to have the text aligned center onto the image and have no gaps on all sides of the grid when resizing according to various screen resolution.
Link: http://jsfiddle.net/kelvinchow/VaDS9/
<style type="text/css">
#wrapper {
display: block;
width: 100%;
height: auto;
background: green;
}
.box {
display: inline-block;
float: left;
width: 50%;
height: auto;
vertical-align: baseline;
background: red;
}
.box-img img {
width: 100% !important;
height: auto;
}
.box-title {
display: block;
background: grey;
height: 25px;
font-size: 20px;
font-family: helvetica, san serif;
color: blue;
text-align: center;
margin-top: -100px;
}
</style>
<div id="wrapper">
<div class="box">
<div class="box-img">
<img src="http://airinlee.com/wp-content/uploads/2013/06/thumbnail6.png">
</div>
<p class="box-title">howdy</p>
</div>
<div class="box">
<div class="box-img">
<img src="http://airinlee.com/wp-content/uploads/2013/06/thumbnail6.png">
</div>
<p class="box-title">howdy</p>
</div>
<div class="box">
<div class="box-img">
<img src="http://airinlee.com/wp-content/uploads/2013/06/thumbnail6.png">
</div>
<p class="box-title">howdy</p>
</div>
<div class="box">
<div class="box-img">
<img src="http://airinlee.com/wp-content/uploads/2013/06/thumbnail6.png">
</div>
<p class="box-title">howdy</p>
</div>
</div>
You'll get this:
Fiddle here: http://jsbin.com/osazav/1.
With this markup:
<body>
<div id="tl" class="box">
<p class="box-title">howdy</p>
</div>
<div id="tr" class="box">
<p class="box-title">howdy</p>
</div>
<div id="bl" class="box">
<p class="box-title">howdy</p>
</div>
<div id="br" class="box">
<p class="box-title">howdy</p>
</div>
</body>
And this css:
div.box {
background: url('http://airinlee.com/wp-content/uploads/2013/06/thumbnail6.png');
position: absolute;
height: 50%;
width: 50%;
background-size: cover;
background-position: center;
}
div.box p.box-title {
color: red;
background-color: black;
padding: 5px;
position: absolute;
margin: -10px -20px;
top: 50%;
left: 50%;
}
div.box#tl { top: 0%; left: 0%; }
div.box#tr { top: 0%; left: 50%; }
div.box#bl { top: 50%; left: 0%; }
div.box#br { top: 50%; left: 50%; }