I've achieved the result I want. But it's not the correct way to do it. For example if my parent container ever changes widths, this hack won't work. However I did this just to get it on the screen to try and resolve the correct way in the browser.
See screenshot here
HTML
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="product-wrapper">
<div class="product-card">
<img src="../assets/img/46-455.jpg" alt="">
<h4> 46-460 12 1/2 in. Variable Speed MIDI-LATHE® </h4>
<p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.</p>
View Product
</div>
</div>
</div>
</div>
</div>
Sorry about my wacky spacing. For some reason pasting out of Sublime Text 3, everything is all jacked up once it comes here.
Related CSS
.product-img-wrapper {
text-align: center;
}
.product-img-wrapper img {
width: 200px;
height: 200px;
}
.product-wrapper {
position: relative;
margin: 50px 0;
}
.product-card {
position: relative;
max-width: 330px;
height: 450px;
border: 1px solid #eee;
margin: 25px auto 0 auto;
text-align: center;
padding-left: 20px;
padding-right: 20px;
box-shadow: 7px 7px 5px #838485;
}
.product-card .btn {
position: absolute;
min-width: 200px;
bottom: 15px;
left: 60px;
}
use this on your .btn instead. This will make your btn center horizontally.
css3: translateX to center element horizontally:
left: 50%;
-webkit-transform: translateX(-50%);
-moz-transform: translateX(-50%);
transform: translateX(-50%);
As I said in my comment, make a wrapper for the button and position:absolute; that to the bottom. Then as long as you remove the styles from the button, it'll center itself because the wrapper has text-align:center; on it.
.product-img-wrapper {
text-align: center;
}
.product-img-wrapper img {
width: 200px;
height: 200px;
}
.product-wrapper {
position: relative;
margin: 50px 0;
}
.product-card {
position: relative;
max-width: 330px;
height: 450px;
border: 1px solid #eee;
margin: 25px auto 0 auto;
text-align: center;
padding-left: 20px;
padding-right: 20px;
box-shadow: 7px 7px 5px #838485;
}
.product-card .card-bottom {
position: absolute;
bottom: 15px;
width:100%;
left:0;
}
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="product-wrapper">
<div class="product-card">
<img src="../assets/img/46-455.jpg" alt="">
<h4> 46-460 12 1/2 in. Variable Speed MIDI-LATHE® </h4>
<p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.</p>
<div class="card-bottom">View Product</div>
</div>
</div>
</div>
</div>
</div>
Related
I have a requirement to make a banner that is 50% of the width of the "content wrapper" and that content wrapper is dynamically sized to a max width (so it can be, in theory, 0px-1330px). The content wrapper is the dark gray box here. It contains the content of the site. Within that content is a banner that comes out from the side of window. The window in this exactly has a boundary of the black outline.
How with HTML/CSS can I make the content of the purple container fit within the dark "content wrapper" even tho it is 50% of the window and the content lines up with left side of the wrapper when I don't know the specific width.
I've tried all kinds of math but I can't quite get it. I'm using CSS vars for the site max width and I can use var or calc to make this work but just no combo is working.
Does this fit your question?
* {
margin: 0;
padding: 0;
list-style: none;
}
.wrap {
width: 100%;
max-width: 500px;
height: 100vh;
margin: auto;
background-color: #aaa;
}
.banner {
width: 50%;
background-color: #a0f;
padding: 20px 20px 20px 0;
position: relative;
box-sizing: border-box;
}
.banner::before {
content: '';
position: absolute;
background-color: #a0f;
top: 0;
left: calc(100% - 50vw);
height: 100%;
width: calc(50vw - 100%);
}
<div class="wrap">
<h1>Content Wrapper</h1>
<div class="banner-wrap">
<div class="banner">
<h2>The title here</h2>
<p>Some other text here</p>
</div>
</div>
</div>
* {
padding: 0px;
margin: 0px;
box-sizing: border-box;
}
body {
overflow: hidden;
}
.window {
width: 100%;
height: 100vh;
border: 2px black solid;
background-color: lightgrey;
display: grid;
align-items: center;
justify-items: center;
}
.wrapper {
height: 75%;
width: 80%;
background-color: darkgrey;
padding:20px 0px;
}
.content {
padding: 20px 0px;
position: relative;
width:50%;
}
p{
position: relative;
z-index:2;
color:white;
}
.banner-container {
height: 100%;
width: 100%;
position: absolute;
top: 0px;
clip-path:inset( -100vw 0vw -100vw -100vw );
}
.banner {
height: 100%;
width: 150vw;
position: absolute;
top: 0px;
left: -50vw;
background-color: purple;
}
<div class="window">
<div class="wrapper">
<div class="content">
<p><b>Some text here</b></p>
<p>Some text here</p>
<div class="banner-container">
<div class="banner">
</div>
</div>
</div>
</div>
</div>
I'm trying to create a 90 deg rotated layout. But the problem is that none of the method I used to use works in this case. Since it is rotated, changing size, getting it responsive does not seem to work.
I'm trying to let the "My Project" title take half of the rotated screen and the other half will contain
images and containers.
Can anyone help me out with this? How do i make sure that it resizes and placement is always half:half layout without overflow during resize in different device size. Please provide me with a hint to complete my work. Thank you!
Link to the code in jsfiddle.
Here's a link to the think I'm doing:
https://jsfiddle.net/7tfy4gdh/1/
Here's what i want to build: https://prnt.sc/10wb1p7
One way to think of this is to design everything as though it was not rotated and with the container having width 100vh and height 100vw. Then when everything is in place, rotate container by 90 degrees and translate it so it exactly fits within the viewport.
To ensure it is all responsive, use relative units wherever possible. So have widths and heights as %s. Think about padding, possibly define it in terms of vmin and you may also want to define font size relatively so it grows on larger screens.
So, implement this first:
This snippet starts the process, defining a left side div and a right side div, centering the main component of each and rotating and translating the container. It isn't the full job, the logo side needs more work - and you may find defining everything in %s etc that it is better not to use flex but to control the use of the whole space yourself.
And remember that just because something is rotated it does not mean that its height becomes the vertical side...
Here's some code to start things off:
<head>
<style>
* {
box-sizing: border-box;
margin:0;
padding: 0;
overflow: visible;
}
body {
width: 100vw;
height: 100vh;
overflow: visible;
}
.container {
text-align: center;
width: 100vh;
height: 100vw;
transform: rotate(90deg) translateY(-100%);
transform-origin: 0% 0%;
overflow: hidden;
}
.container .left-side {
position: relative;
width: 50vh;
height: 100vw;
float: left;
}
.container .left-side .project-title {
position: relative;
top: 50%;
transform: translateY(-50%);
}
.container .project-title span {
text-align: center;
}
.container .right-side {
position: relative;
top: 0;
width: 50vh;
height: 100vw;
float: left;
padding: 1vmin;
}
.container .right-side .control {
position: relative;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
rmax-width: 450px;
rmin-width: 350px;
height: 80%;
width: 80%;
background-color: red;
padding: 5%;
}
.control .logo {
height: 25%;
}
.control .logo img {
width:100px;
height: 100%;
width: auto;
}
.logo-container {
flex:1;
display:flex;
margin-top: 5%;
height: 30%;
}
.logo-maker{
flex:1;
padding:25px 10px;
background-color: #ccc;
color:#ffffff;
border-radius: 8px;
padding-top: 15px;
}
.logo-maker .maker-contain {
width:50px;
background-color: #ccc;
border-radius: 8px;
padding:5px;
padding-bottom: 0;
margin:auto;
}
.logo-maker .maker-contain img{
width:100%;
}
.logo-maker h3 {
margin-top: 15px;
}
.earn-coin {
flex:1;
text-align: center;
padding:25px 0;
padding-top: 15px;
margin-left: 5px;
border-radius: 8px;
background-color: #ccc;
box-shadow: 5px 4px 5px -5px rgba(0,0,0,0.76);
-webkit-box-shadow: 5px 4px 5px -5px rgba(0,0,0,0.76);
-moz-box-shadow: 5px 4px 5px -5px rgba(0,0,0,0.76);
}
.earn-coin img {
width:40px;
margin:auto;
}
.earn-coin h3{
margin-top: 15px;
}
.footer {
padding:20px 30px;
padding-left: 55px;
background-color: #ccc;
background-color: purple;
height: 25%;
color:#ffffff;
border-radius: 5px;
margin-top: 5%;
text-align: left;
}
.footer i{
font-size:35px;
}
.footer h3 {
display: inline;
margin-left: 20px;
}
</style>
</head>
<body>
<div class="container">
<div class="left-side">
<div class="project-title">
<h2>
My Project
</h2>
</div>
</div>
<div class="right-side">
<div class="control">
<div class="logo">
<img src="https://d1csarkz8obe9u.cloudfront.net/posterpreviews/lion-fire-logo-design-template-free-89daa14626ac403bd3cf6282036663ff_screen.jpg?ts=1572094154">
</div>
<section class="logo-container">
<div class="logo-maker">
<div class="maker-contain">
<img src="https://www.logaster.com/blog/wp-content/uploads/2018/05/LogoMakr.png" alt="">
</div>
<h3>Build Logo</h3>
</div>
<div class="earn-coin">
<div class="coin-img">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSEWIhIZ48jnuWwHjIZ9I_EpQbRsHrFtomThQ&usqp=CAU">
</div>
<h3>Earn Coins</h3>
</div>
</section>
<div class="footer">
<i class="fa fa-bell"></i>
<h3>
Build by Dave ___
</h3>
</div>
</div>
</div>
</div>
</body>
I have inline-block elements. These are glyphs and can contain SVG content, but don't contain text.
The problem is that these elements don't line up with text:
.example {
line-height: 32px;
margin: 12px 0;
}
.wrapper {
display: inline-block;
height: 24px;
width: 24px;
position: relative;
background-color: red;
}
.wrapper > .content {
position: absolute;
bottom: 3px;
right: 3px;
height: 12px;
width: 12px;
background-color: blue;
}
<div class=example>
<div class=wrapper>
<div class=content>
</div>
</div>
not aligned with text
<div class=wrapper>
<div class=content>
</div>
</div>
</div>
I can shift down individual elements easily enough, but it's messy and requires lots of micro tweaking.
I can't rely on the line height and icon size being identical, and the SVG inside are overlaid, which requires absolute positioning.
Is there a way to make these consistently vertically centre with text?
Specify vertical-align:bottom to wrapper class :
.example {
line-height: 24px;
margin: 12px 0;
}
.wrapper {
display: inline-block;
height: 24px;
width: 24px;
position: relative;
background-color: red;
vertical-align:bottom;
}
.wrapper > .content {
position: absolute;
bottom: 3px;
right: 3px;
height: 12px;
width: 12px;
background-color: blue;
}
<div class=example>
<div class=wrapper>
<div class=content>
</div>
</div>
aligned with text
<div class=wrapper>
<div class=content>
</div>
</div>
</div>
I´ve made a transparent "button" and place it on a fullwidth background image
I use the class in an <a>
I would like the button to be centered responsively on the image. I got it done horizontally but not exactly vertically. (My idea is to make a one page type a page)
Here is the html:
<div class="container">
<div class="nav">nav area</div>
<div class="bg-image">
<a class="button-transp abs" href="#">Butt text<br>second line<br>third</a>
<img src="bg_top.jpg">
<h1>This is centered text.</h1>
</div>
<div class="main">main area</div>
</div>
the CSS
.abs {
position: absolute;
z-index: 2;
margin: 25% auto 0;
left: 0;
right: 0;
}
.button-transp {
display: inline-block;
min-width: 170px;
max-width: 500px;
width: 30%;
padding: 8px;
color: #fff;
background-color: transparent;
border: 2px solid #fff;
text-align: center;
outline: none;
}
I use margin: 25% auto 0; to get it something near right..
You wanted the button to stay center responsively to the image, which, in this case you should use background image. Then position your button to be 50% from the top, 50% from the left and pull it back -1/2 of its height to the top and -1/2 of its width to the left. Doing this to enforce the button to always stay in the center of the bg-image.
<div class="container">
<div class="nav">nav area</div>
<div class="bg-image">
<a class="button-transp abs" href="#">Butt text<br>second line<br>third</a>
<h1>This is centered text.</h1>
</div>
<div class="main">main area</div>
</div>
.abs {
position: absolute;
z-index: 2;
top: 50%;
margin-top: -37px; /** the button height is 74, so pull it half to the top the make the gap top and bottom equal */
left: 50%;
margin-left: -95px; /** again, full button width / 2 */
}
.button-transp {
display: inline-block;
min-width: 170px;
max-width: 500px;
width: 30%;
padding: 8px;
color: #fff;
background-color: transparent;
border: 2px solid #fff;
text-align: center;
outline: none;
}
.bg-image {
background: url(http://www.online-image-editor.com//styles/2014/images/example_image.png) no-repeat 0 0;
width: 475px;
height: 360px;
position: relative;
}
See fiddle
I've abbreviated the structure but this option will work for any size button and will always center both horizontally & vertically.
CSS3 transforms are basically IE9 and up (suitably prefixed as required)
.bg-image {
height: 200px;
background: orange;
position: relative; /* positioning contexr */
}
.button-transp {
width: 30%;
white-space:nowrap;
padding: 8px;
color: #fff;
background-color: transparent;
border: 2px solid #fff;
text-align: center;
outline: none;
position: absolute;
z-index: 2;
top:50%;
left: 50%;
transform:translate(-50%,-50%);
}
<div class="container">
<div class="bg-image">
<a class="button-transp abs" href="#">Butt text<br/>second line<br/>third</a>
</div>
</div>
How do I center a text over an image in css?
<div class="image">
<img src="sample.png"/>
<div class="text">
<h2>Some text</h2>
</div>
</div>
I want to do something like the one below but I'm having difficulties, here's my current css
<style>
.image {
position: relative;
}
h2 {
position: absolute;
top: 200px;
left: 0;
width: 100%;
margin: 0 auto;
width: 300px;
height: 50px;
}
</style>
When I use background-image I do not get any output from html2pdf:
<style>
#image_container{
width: 1000px;
height: 700px;
background-image:url('switch.png');
}
</style>
Print
<?php ob_start(); ?>
<div id="image_container"></div>
<?php
$_SESSION['sess'] = ob_get_contents();
ob_flush();
?>
Here's prints.php:
<?php require_once('html2pdf/html2pdf.class.php'); ?>
<?php
$html2pdf = new HTML2PDF('L', 'A4', 'en');
$html2pdf->writeHTML($_SESSION['sess']);
$html2pdf->Output('random.pdf');
?>
How about something like this: http://jsfiddle.net/EgLKV/3/
Its done by using position:absolute and z-index to place the text over the image.
#container {
height: 400px;
width: 400px;
position: relative;
}
#image {
position: absolute;
left: 0;
top: 0;
}
#text {
z-index: 100;
position: absolute;
color: white;
font-size: 24px;
font-weight: bold;
left: 150px;
top: 350px;
}
<div id="container">
<img id="image" src="http://www.noao.edu/image_gallery/images/d4/androa.jpg" />
<p id="text">
Hello World!
</p>
</div>
This is another method for working with Responsive sizes. It will keep your text centered and maintain its position within its parent. If you don't want it centered then it's even easier, just work with the absolute parameters. Keep in mind the main container is using display: inline-block. There are many others ways to do this, depending on what you're working on.
Based off of Centering the Unknown
Working codepen example here
HTML
<div class="containerBox">
<div class="text-box">
<h4>Your Text is responsive and centered</h4>
</div>
<img class="img-responsive" src="http://placehold.it/900x100"/>
</div>
CSS
.containerBox {
position: relative;
display: inline-block;
}
.text-box {
position: absolute;
height: 100%;
text-align: center;
width: 100%;
}
.text-box:before {
content: '';
display: inline-block;
height: 100%;
vertical-align: middle;
}
h4 {
display: inline-block;
font-size: 20px; /*or whatever you want*/
color: #FFF;
}
img {
display: block;
max-width: 100%;
height: auto;
}
Why not set sample.png as background image of text or h2 css class? This will give effect as you have written over an image.
For a responsive design it is good to use a container having a relative layout and content (placed in container) having fixed layout as.
CSS Styles:
/*Centering element in a base container*/
.contianer-relative{
position: relative;
}
.content-center-text-absolute{
position: absolute;
text-align: center;
width: 100%;
height: 0%;
margin: auto;
top: 0;
left: 0;
bottom: 0;
right: 0;
z-index: 51;
}
HTML code:
<!-- Have used ionic classes -->
<div class="row">
<div class="col remove-padding contianer-relative"><!-- container with position relative -->
<div class="item item-image clear-border" ><img ng-src="img/engg-manl.png" alt="ENGINEERING MANUAL" title="ENGINEERING MANUAL" ></div> <!-- Image intended to work as a background -->
<h4 class="content-center-text-absolute white-text"><strong>ENGINEERING <br> MANUALS</strong></h4><!-- content div with position fixed -->
</div>
<div class="col remove-padding contianer-relative"><!-- container with position relative -->
<div class="item item-image clear-border"><img ng-src="img/contract-directory.png" alt="CONTRACTOR DIRECTORY" title="CONTRACTOR DIRECTORY"></div><!-- Image intended to work as a background -->
<h4 class="content-center-text-absolute white-text"><strong>CONTRACTOR <br> DIRECTORY</strong></h4><!-- content div with position fixed -->
</div>
</div>
For IONIC Grid layout, evenly spaced grid elements and the classes used in above HTML, please refer - Grid: Evenly Spaced Columns. Hope it helps you out... :)
as Harry Joy points out, set the image as the div's background and then, if you only have one line of text you can set the line-height of the text to be the same as the div height and this will place your text in the center of the div.
If you have more than one line you'll want to set the display to be table-cell and vertical-alignment to middle.
as of 2017 this is more responsive and worked for me.
This is for putting text inside vs over, like a badge.
instead of the number 8, I had a variable to pull data from a database.
this code started with Kailas's answer up above
https://jsfiddle.net/jim54729/memmu2wb/3/
.containerBox {
position: relative;
display: inline-block;
}
.text-box {
position: absolute;
height: 30%;
text-align: center;
width: 100%;
margin: auto;
top: 0;
bottom: 0;
right: 0;
left: 0;
font-size: 30px;
}
.img-responsive {
display: block;
max-width: 100%;
height: 120px;
margin: auto;
padding: auto;
}
.dataNumber {
margin-top: auto;
}
<div class="containerBox">
<img class="img-responsive" src="https://s20.postimg.org/huun8e6fh/Gold_Ring.png">
<div class='text-box'>
<p class='dataNumber'> 8 </p>
</div>
</div>
A small and short way of doing the same:
.image {
position: relative;
margin-bottom: 20px;
width: 100%;
height: 300px;
color: white;
background: url('https://via.placeholder.com/600') no-repeat;
background-size: 250px 250px;
}
<div class="image">
<p>
<h3>Heading 3</h3>
<h5>Heading 5</h5>
</p>
</div>
Quick solution: Set position: relative; on the container element and set position: absolute; on child elements in that container element, with the necessary top, left, bottom, right-adjusting parameters:
.top-left {
position: absolute;
top: 2px;
left: 2px;
}
.bottom-right {
position: absolute;
bottom: 2px;
right: 2px;
}
.container {
position: relative;
text-align: center;
color: white;
float:left;color: white;
text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;
}
<div class="container" style="">
<img src="https://www.wikipedia.org/portal/wikipedia.org/assets/img/Wikipedia-logo-v2#2x.png" width="100">
<div class="top-left">Wikipedia</div>
<div class="bottom-right">Everyone's Encyclopedia</div>
</div>
Center it directly in the middle with the following CSS...
top: 50%;
left: 50%;
transform: translate(-50%, -50%);