I have the following div:
<div class="transparent-panel">
<h3>We asked some of our supports the following questions</h3>
WATCH VIDEO
</div>
and I want the text and button to appear centred within the div. Currently it appears like so:
and I am having no luck getting to centre. Here is the css for the transparent-panel div:
.transparent-panel {
padding: 40px 20px 40px 20px;
width: 100%;
height: 100%;
background: rgba(51, 153, 51, 0.7);
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#75FFFFFF, endColorstr=#75FFFFFF)";
}
I tried using position: relative; on the div and then position: absolute; on the h3 and a tag but that didn't work.
If anyone can help me out it would be much appreciated. I am using Bootstrap 3.
Here is a bootply demo http://www.bootply.com/sQ5gyYn7Ru
One way to do it would be to wrap the panel in a container, put the background color on the container and then use a few lines of CSS to vertically center the panel within the container:
HTML:
<div class="panel-container">
<div class="transparent-panel">
<h3>We asked some of our supports the following questions</h3>
WATCH VIDEO
</div>
</div>
CSS:
html,body {
height:100%;
}
.panel-container {
height:100%;
background: rgba(51, 153, 51, 0.7);
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#75FFFFFF, endColorstr=#75FFFFFF)";
}
.transparent-panel {
padding: 40px 20px 40px 20px;
width: 100%;
text-align:center;
/* Code to vertically center below */
position: relative;
top: 50%;
transform: translateY(-50%);
}
Bootply Example
I find it useful to set the container div as display: table, and wrap the content in a inner div set as display: table-cell.
Then you can use the vertical-align property:
Updated BootPly
/* CSS used here will be applied after bootstrap.css */
.teachers-image {
background-size: cover;
height: 418px;
color: #ffffff;
}
.transparent-panel {
padding: 0 20px;
display: table;
width: 100%;
height: 100%;
background: rgba(51, 153, 51, 0.7);
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#75FFFFFF, endColorstr=#75FFFFFF)";
}
.transparent-panel > div {
display: table-cell;
vertical-align: middle;
}
.btn-white-big {
background-color: #ffffff;
height: 50px;
color: #339933;
font-size: 18px;
font-weight: 500;
line-height: 30px;
#include add-border(3px, white, all);
#include border-radius(30px);
&:hover,
&:focus,
&.focus {
background-color: #339933 !important;
color: white;
}
}
<div class="teachers-image">
<div class="transparent-panel">
<div>
<h3>We asked some of our supports the following questions</h3>
WATCH VIDEO
</div>
</div>
</div>
Use a container with View Height for top to bottom centering:
height: 100vh;
The View Height will always use the windows display height.
Fiddle
HTML:
<div class="container">
<div class="transparent-panel">
<h3>We asked some of our supports the following questions</h3>
WATCH VIDEO
</div>
</div>
CSS:
.container {
height: 100vh;
background: rgba(51, 153, 51, 0.7);
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#75FFFFFF, endColorstr=#75FFFFFF)";
}
.transparent-panel {
width: 100%;
text-align:center;
position: relative;
top: 50%;
}
Related
How can I make these forms in the middle of the page width
the Intended form
using pseudo elements before and after
and using this code:
<body>
<div class="cont">One</div>
<div></div>
<div>Three</div>
</body>
Note I am a beginner with CSS
You can try removing one of the content and see effect . Giving margin-top/bottom equal makes it vertically center align and display:block; with margin-left/right:auto makes it horizontally center
.box {
position: relative;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0, 0, 0, 0.4);
}
.content {
position: relative;
background-color: red;
border: 2px solid rgb(209, 208, 208);
border-radius: 5px;
width: 40%;
padding: 2%;
display:block;
margin: 15% auto 15% auto;
}
<div class="box">
<div class="content">hd</div>
<div class="content">hd</div>
</div>
box shadows are basically your shape blurred.
that means that at the edges the shadow is curved up.
what if you don't want that? what if your shadow is for a top bar and you don't want it to seems like it ends?
issue:
desired effect :
how do I obtain this?
html :
<div class="TopBar"> </div>
css :
.TopBar {
box-shadow: 0 4px 28px black;
}
Am I supposed to use an absolute positioned element that's bigger than screen width or something?
You can add a spread parameter to the shadow (not exactly the same appearance, but at least it does what you ask for):
html,
body {
margin: 0;
}
.TopBar {
height: 40px;
background: #444;
box-shadow: 0px 4px 24px 16px black;
}
<div class="TopBar"></div>
Fake it! You can use linear gradient and a pseudo element to get the effect you want:
.TopBar {
height: 50px;
background: gray;
position: relative;
}
.TopBar::after {
content: "";
background: linear-gradient(to bottom, rgba(0,0,0,.8) 0%,rgba(0,0,0,0) 100%);
position: absolute;
width: 100%;
height: 20px;
top: 100%;
}
<div class="TopBar"> </div>
You can add a pseudo-element (:before) to extend it beyond your original container and therefore, get a wider shadow :
html, body { margin:0; padding: 0 }
.TopBar {
height: 50px;
position: relative;
}
.TopBar:before {
content: "";
display: block;
position: absolute;
height: 100%;
width: 100%;
background: #454545;
box-shadow: 0 4px 28px #000;
transform: scaleX(1.1);
z-index: -1;
}
.TopBar .content {
color: #add8e6;
}
<div class="TopBar">
<div class="content">Here's some text inside my top bar</div>
</div>
I have a WebView that displays a html layout. But the problem is the html layout isn't coming out how I expected it. I created a Android layout using xml but I want the layout in html. this is what i am trying trying achieve
The grey part represents a background image.
The purple part a image(Logo).
Then I have a white box with round corners and TextView and Button inside. this is done in android xml but i want something similar in html
This is how it looks in html
But as you can see the logo is behind the white box and the TextView is next to the button instead of the top.
here is my html code
<style>
div {
padding: 10px 10px;
background: #fff;
width: 300px;
border-radius: 10px;
margin : 0 auto;
}
body {
background-image: url("url to background image");
//background-size: cover;
}
.logo {
background-image: url("url to logo");
background-size: cover;
height: 70px;
width: 200px;
margin-bottom 40;
background-color: rgba(0, 0, 0, 0);
}
.container {
display: table;
height: 100%;
position: absolute;
overflow: hidden;
width: 100%;
background-color: rgba(0, 0, 0, 0);
}
.helper {
#position: absolute;
#top: 50%;
display: table-cell;
vertical-align: middle;
background-color: rgba(0, 0, 0, 0);
}
.content {
#position: relative;
#top: -50%;
margin: 0 auto;
width: 200px;
}
.button {
-moz-border-radius:15px;
-webkit-border-radius:15px;
border-radius:15px;
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
</style>
<div class="container">
<div class="helper">
<div class="logo"/>
<div class="content">
<p1>Text </p1>
<input type="submit" class="button" value="Button">
</div>
</div>
</div>
Can someone please help me fix my html code to look like the android xml version
Change <p1>Text </p1> to <p>Text </p>.
A p element has the style display:block; by default and will push the button down.
I want to reach this result:
This is what i have atm: http://mijnwebsitebestellen.be/index.php
So i am currently using SVG elements to slice of the images. You can inspect the code in your browser. I can't get the result right because of z-index issues.
Any tips or examples of any sort are appreciated.
You can achieve the same result using pure CSS.
Use a container element for background color and image
Use the pseudo element ::after with a white right border to imitate the right edge
Use some divs of the same class .tile to imitate the stripes with transform: skewX(-10deg); and let them float: right;
Et voilà:
.container {
height: 300px;
width: 400px;
background: linear-gradient(rgba(219, 41, 117, 0.6), rgba(219, 41, 117, 0.6)), url(https://i.stack.imgur.com/e11Va.jpg);
background-size: cover;
color: white;
position: relative;
padding-right: 26px;
}
.container::after {
content: "";
position: absolute;
display: block;
right: 0;
bottom: 0;
height: 0;
width: 0;
border: none;
border-left: none;
border-right: 52px solid white;
border-top: 300px solid transparent;
border-bottom: none;
}
.tile {
width: 30px;
height: inherit;
background: rgba(0, 0, 0, 0.6);
border-left: 5px solid white;
transform: skewX(-10deg);
float: right;
}
<div class="container">
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
</div>
Of course you can add content to the container. Just use another div inside the container and give it the apropriate width.
I want to contain the teal hover within the borders of my social media links. I’ve tried adjusting the padding and heights and widths via CSS properties but when hovering, it still overlaps over the right border.
This is what it looks like while not hovering:
This is what it looks like when hovering:
The image sizes are each 19px × 15px.
#box {
width: 200px;
height: 50px;
background-clip: padding-box;
position: relative;
margin: 0;
left: 1.4em;
background: rgba(0, 0, 0, 1);
float: right;
z-index: 200;
}
#boxlist li {
height: 50px;
width: 20px;
position: relative;
list-style-type: none;
display: inline-block;
bottom: 1em;
margin-left: -2.5em;
float: left;
}
.imgli:hover {
background: rgba(0, 255, 255, 1);
}
.imgli {
border-left: 1px solid rgba(153, 153, 153, 1);
padding-right: 4em;
}
.imgli:first-child {
left: -0.1em;
border: none;
}
.imgli:nth-child(2) {
left: 1em;
}
.imgli:nth-child(3) {
left: 2em;
}
<header>
<div id="box">
<ul id="boxlist">
<li class="imgli"><img src="images/banner-social-icon-twitter.png" class="boximg"></li>
<li class="imgli"><img src="images/banner-social-icon-facebook.png" class="boximg"></li>
<li class="imgli"><img src="images/banner-social-icon-email.png" class="boximg"></li>
</ul>
</div>
</header>
The overlapping is happening, I believe, because of the
margin-left:-2.5em combined with the fixed width of the container, you are still experiencing overlap, despite the fact that your elements are floating.
Without doing a detailed lookover of your layout, one solution is to apply a background color to your <li>s to prevent the overlap, see the update I made to your fiddle:
http://jsfiddle.net/VVj3R/1/
I just added the background line to .imgli's definition and it seems to work.
.imgli {
border-left: 1px solid rgba(153,153,153,1);
padding-right:4em;
background-color:black;
}
You may want to change black to something else, as long as its an opaque color.
PS the images didn't show up in your fiddle because you used relative path names.
Try making your code bit simpler.. like this:
<div id="box">
<ul>
<li><div class="button" id="btn1"></div></li>
<li><div class="button" id="btn2"></div></li>
<li><div class="button" id="btn3"></div></li>
</ul>
</div>
CSS:
#box ul {
margin: 20px;
padding: 0px;
}
#box li {
float: left;
display: block;
background: #ededed;
padding: 1px;
}
#box .button {
width: 50px;
height: 50px;
background-color: #000;
}
#box .button:hover {
background-color:rgba(0,255,255,1);
}
#btn1 {
background-image: url(someicon.png);
background-repeat: no-repeat;
background-position: center center;
background-size: 40px 40px;
}
Here is fiddle:
http://jsfiddle.net/tb2Ug/