I am trying to make a slanted div with a background image. HERE is a screenshot of what I am trying to achieve.
I have always made my slanted divs using css triangles. However I am finding this technique troublesome in this situation because it is 2 separate parts and the pictures wont connect.
As of right now in my code I have a div with the background image applied with a before element that looks like this:
#booking-form:before{
content: "";
position: absolute;
top: 0;
bottom: 0;
left: -320px;
border-top: 726px solid transparent;
border-right: 320px solid $secondary;
}
This makes the triangle I am looking for however if I add an image to the triangle it fills the entire before css and looks like this:
But I need it to look like the original.
Any suggestions? Thank you!
Just use a full width div with a suitably angled gradient background instead.
No transforms, no borders.
body {
text-align: center;
}
.content {
height: 150px;
padding: 20px 0;
background: linear-gradient(-65deg, rgba(0, 0, 255, 0.5) 65%, transparent 65%);
display: flex;
}
div {
background-image: url(http://www.fillmurray.com/460/300);
}
form {
width: 50%;
background: rgba(255, 255, 255, 0.85);
margin-left: auto;
margin-right: 1em;
}
<div>
<div class="content">
<form action=""></form>
</div>
</div>
Unfortunately not avalaible everywhere, mix-blend-mode could be an hint using gradients to choose wich parts to blend
body {
height: 100%;
background: linear-gradient(110deg, white 45%, transparent 45%), url(http://lorempixel.com/800/600/city/3) right no-repeat;
background-size: 100% 100%, 75% auto ;
margin: 0;
}
html {
height: 100%;
min-width:800px;
margin: 0;
background: linear-gradient(110deg, transparent 45%, darkcyan 45%), url(http://lorempixel.com/800/600/city/2)top left no-repeat;
background-size: 100% 100%, 75% auto;
}
body {
mix-blend-mode: overlay;
}
/* demo purpose */
body>div {
padding:1px;
padding-left: 55%;
color: black;
}
body>p {
margin:0;
}
/* small snippet view purpose */
html, body {
background-attachment:fixed;
}
<p> nop, mix-blend-mode is not avalaible here :( </p>
<div>
<h2 name="Summary" id="Summary">Summary<a class="button section-edit only-icon" href="/en-US/docs/Web/CSS/mix-blend-mode$edit#Summary"><i aria-hidden="true" class="icon-pencil"></i><span>Edit</span></a></h2>
<p>The <strong><code>mix-blend-mode</code></strong> CSS property describes how an element's content should blend with the content of the element that is below it and the element's background.</p>
<p></p>
<table class="properties">
<tbody>
<tr>
<th scope="row">Initial value</th>
<td><code>normal</code></td>
</tr>
<tr>
<th scope="row">Applies to</th>
<td>all HTML elements</td>
</tr>
<tr>
<th scope="row">Inherited</th>
<td>no</td>
</tr>
<tr>
<th scope="row">Media</th>
<td>visual</td>
</tr>
<tr>
<th scope="row">Computed value</th>
<td>as specified</td>
</tr>
<tr>
<th scope="row">Animation type</th>
<td>discrete</td>
</tr>
<tr>
<th scope="row">Canonical order</th>
<td>the unique non-ambiguous order defined by the formal grammar</td>
</tr>
<tr>
<th scope="row">Creates stacking context</th>
<td>yes</td>
</tr>
</tbody>
</table>
</div>
Related
I would like to create table complex arrow-like shape with CSS like this image:
This is the current code:
<style>
.border-dark {
border-color: #212529 !important;
}
.table-gray {
background: rgb(97, 97, 97);
color: white;
}
.table-rowspan {
background-color:rgb(97, 97, 97) !important;
color: white;
}
table, th, td {
border-collapse: collapse;
border: 1px solid black;
}
table th:nth-child(1) {
width: 70px;
min-width: 70px;
}
table th:nth-child(2) {
width: 60px;
min-width: 60px;
height: 20px;
}
</style>
<table class="table-bordered border-dark">
<tr class="table-rowspan border-dark">
<th rowspan="10" class="table-rowspan border-dark"></th>
<th></th>
</tr>
<tr>
<td>1</td>
</tr>
<tr>
<td>2</td>
</tr>
.....
<tr>
<td>9</td>
</tr>
</table>
and the current result:
Please help me draw up and down arrows with any letter in the first column.
Thank you so much
Instead of treating the arrow section as the first column of the table, why don't you use a separate div for the arrow part with position: absolute;, top: 0; left: -100%;, and height: 100%;?
Ofcourse the main table div would be position: relative; and the arrow div would be its child.
This arrow div would further have 5 spans, each for the elements: alphabet on top, top pointing arrow, centre text, down pointing arrow, alphabet at the bottom.
Arrow div = display: flex; flex-direction: column;
Use a png for top/bottom arrow and flip if vertically for the reverse.
I was able to create a quick .svg file for the arrows you want.
I would recommend using this as a background image for the side area and add text on top of that.
The file was software-generated so its hard to read, but it is small enough to give it a shot.
I hope you will find this at least a bit helpful.
The logic is this:
Create a closed path for the arrows
Add a radial gradient on that shape with the desired colors
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="100%" height="100%" viewBox="0 0 175 800" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
<path d="M87.258,48l-52.258,152.277l30.112,0l-0,399.294l-30.112,-0l52.258,152.429l51.742,-152.429l-29.705,-0l-0,-399.294l29.705,0l-51.742,-152.277Z" style="fill:url(#_Radial1);"/>
<defs>
<radialGradient id="_Radial1" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="matrix(-0.257918,-199.723,1351.97,-1.7459,87.2579,400)">
<stop offset="0" style="stop-color:#585858;stop-opacity:1"/>
<stop offset="1" style="stop-color:#d5d5d5;stop-opacity:1"/></radialGradient>
</defs>
</svg>
As the arrow appears to be for decorative purposes there is no need to put it into the main HTML.
This snippet draws it with a polygon which clips a path on a before pseudo element on the first th element. This has a background which goes from light gray to transparent in the middle and back to light gray.
An after pseudo element puts in some text - but more is needed here in terms of positioning as it appears the text required would be in a vertical script (?).
The black splodge effect is made with a radial gradient on the th element.
.border-dark {
border-color: #212529 !important;
}
.table-gray {
background: rgb(97, 97, 97);
color: white;
}
.table-rowspan {
background-color: rgb(97, 97, 97) !important;
color: white;
}
table,
th,
td {
border-collapse: collapse;
border: 1px solid black;
}
table th:nth-child(1) {
width: 70px;
min-width: 70px;
}
table th:nth-child(2) {
width: 60px;
min-width: 60px;
height: 20px;
}
th:first-child {
position: relative;
backgroound-image: radial-gradient(black, white);
background-position: center center;
}
th:first-child::before {
content: '';
width: 70%;
height: 90%;
background-image: linear-gradient(#eeeeee, transparent, #eeeeee);
top: 5%;
left: 5%;
z-index: 1;
position: absolute;
--x: 30%;
--y: 15%;
clip-path: polygon(50% 0, 100% var(--y), calc(100% - var(--x)) var(--y), calc(100% - var(--x)) calc(100% - var(--y)), 100% calc(100% - var(--y)), 50% 100%, 0% calc(100% - var(--y)), var(--x) calc(100% - var(--y)), var(--x) var(--y), 0 var(--y));
}
th:first-child::after {
content: 'A';
color: white;
font-family: sans-serif;
z-index: 2;
position: absolute;
top: 50%;
left: 50%;
/* work needed on exact positioning and requirement for text eg. vertical?? */
}
<table class="table-bordered border-dark">
<tr class="table-rowspan border-dark">
<th rowspan="10" class="table-rowspan border-dark"></th>
<th></th>
</tr>
<tr>
<td>1</td>
</tr>
<tr>
<td>2</td>
</tr>
<tr>
<td>3</td>
</tr>
<tr>
<td>4</td>
</tr>
<tr>
<td>5</td>
</tr>
<tr>
<td>6</td>
</tr>
<tr>
<td>7</td>
</tr>
<tr>
<td>8</td>
</tr>
<tr>
<td>9</td>
</tr>
</table>
Note: CSS variables, --x and --y, are used to define the arrow head. Change these if you want a more (or a less) pointy one. And change the width of the before element if you would like it fatter (or thinner). %s are used so it should be responsive if you go down that route.
Both the gray background row and the white background row below are two separate tables. The white background table is the 'overflow-y' property set to scrollable is the number of elements within it exceeds 100px.
CSS for tables:
table {
border-collapse: collapse;
width: 100%;
}
HTML for gray table:
<div style="padding-bottom: 2px">
<table>
<thead>
<tr>
<th>Start Time</th>
<th>End Time</th>
<th>User1</th>
<th>User2</th>
<th></th>
</tr>
</thead>
</table>
</div>
CSS for gray table:
th {
background-color: #E0E0E0;
font-size: 20px;
font-weight: bold;
padding: 8px 0px 8px 0px;
text-align: left;
vertical-align: bottom;
width: 20%;
}
HTML for white table:
<div style="height:95%;overflow:auto">
<table id="modalTable" style="table-layout: fixed; width: 100%" >
<tbody>
<tr ng-repeat-start="value in MaintenanceModeEvents" class="event">
<td>{{'Start Time: MM-dd-yyyy HH:mm:ss'}}</td>
<td>{{'End Time: MM-dd-yyyy HH:mm:ss'}}</td>
<td>{{'User 1'}}</td>
<td>{{'User 2'}}</td>
<td><button type="button"</td>
</tr>
</tbody>
</table>
</div>
CSS for white table:
tr.event {
border-top: 1px solid #808080;
/*border-bottom: 1px solid #808080;*/
font-size: 14px;
padding: 8px 16px;
text-align: left;
}
The header of the gray background table is evenly spaced at 20% (there is a th with nothing in it above view comments) when the white background table's contents doesn't exceed 100px. The issue that I am running into is when the white background table's contents exceeds 100px, the scroll bar's width takes up space in the white background table and the headers from the gray background table no longer align with the white background table as seen above. How can I handle this issue? Any help would be great!
Sorry if this is a plainly obvious answer, I am a horrible web designer.
I am making a help page for my program, and I'm using a table to show the hotkeys. I used CSS to center it and remove the border.
The header of the table is Action, and Trigger, but they do not show up when I open the HTML with my broswer, only the table data. To the point, why does this happen and how can it be fixed?
A fiddle: http://jsfiddle.net/CaffeineToCode/rq9hc7hL/1/
<!DOCTYPE html>
<html>
<head>
<title>Help</title>
</head>
<style>
body {
background: -webkit-linear-gradient(left, #F99200, #FDE000);
background: -o-linear-gradient(left, #F99200, #FDE000);
background: -moz-linear-gradient(left, #F99200, #FDE000);
background: linear-gradient(to right, #F99200, #FDE000);
}
.center {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%)
}
table, td, th {
border: none;
}
td {
padding: 10%;
}
</style>
<body>
<div class="center">
<table>
<tr>
<th>Action</th> <!-- No header??? -->
<th>Trigger</th>
</tr>
<tr>
<td>Fullscreen</td>
<td>"f11" key</td>
</tr>
<tr>
<td>Turn page forward</td>
<td>"→" key or right page curl</td>
</tr>
<tr>
<td>Turn page backward</td>
<td>"←" key or left page curl</td>
</tr>
<tr>
<td>Set bookmark</td>
<td>Bookmark icon, <i>CTRL + B</i>, or Menu > Set bookmark</td>
</tr>
<tr>
<td>Go to bookmark</td>
<td>Menu > Go to bookmark</td>
</tr>
<tr>
<td>Go to page</td>
<td>Menu > Go to page</td>
</tr>
<tr>
<td>Go to page</td>
<td>Menu > Go to page</td>
</tr>
<tr>
<td>Go to book</td>
<td>Menu > Go to book</td>
</tr>
<tr>
<td>Go to verse</td>
<td>Menu > Go to book, then type "<book> <verse>"</td>
</tr>
</table>
</div>
</body>
</html>
Add: height:100%; to .center div.
http://jsfiddle.net/rq9hc7hL/5/
Also, as mentioned in answer above - no need for absolute positioning....
Change your .center class to this:
.center {
margin: auto;
width: 50%;
}
There is no need for absolute position. If you want it to be centered, juste use margin: auto;
Working Fiddle
You can resolve this thing by changing 3 style properties in .center as follow:
transform: translate(-50 %, -15%);
or
top: 150%;
or
height : 100%
You need to remove this CSS rule: td {padding: 10%;}
How can I display my image and the table on the same level? This is really depressing me because I can't get "inline-block" to work. :(
<p id="play">
hey
</p>
<div id="menu">
<table>
<tr>
<td>Models</td>
</tr>
<tr>
<td>Cars</td>
</tr>
<tr>
<td>Modern Houses</td>
</tr>
<tr>
<td>Vacation Spots</td>
</tr>
<tr>
<td>Sports and Outdoors</td>
</tr>
<tr>
<td>Books</td>
</tr>
<tr>
<td>Abandoned Houses</td>
</tr>
<tr>
<td>Summer Wear</td>
</tr>
<tr>
<td>Makeups</td>
</tr>
<tr>
<td id="site">Site Info</td>
</tr>
</table>
</div>
<img src="C:\Users\Elexie\Documents\Downloads\faki2.jpg"/>
body {
background: #181818;
margin: 0;
padding: 0;
}
/* set body display to inline-table*/
#play {
background: black;
color: white;
margin: 0;
padding: 0;
height: 35px;
}
table,td {
color: white;
border: 1px solid white;
border-collapse: collapse;
width: 160px;
padding: 10px;
font-family: ;
}
table {
}
#site {
height: 350px;
}
img {
float: right;
}
I changed the picture, but it's of similar size
http://jsfiddle.net/w6d5g/
In your css code:
table{
float:left;
}
Should do the trick.
Read more: http://www.w3schools.com/css/css_float.asp
Check this fiddle: http://jsfiddle.net/Mohamed_nabil/F8MKp/
/*******Added style******/
img
{
/*165px is your Menu width with borders*/
max-width: calc(100% - 165px);
/*For cross browser*/
-webkit-max-width: calc(100% - 165px);
-moz-max-width: calc(100% - 165px);
-o-max-width: calc(100% - 165px);
-ms-max-width: calc(100% - 165px);
display: inline-block;
vertical-align: top;/* Can be middle, bottom */
}
#menu{
display: inline-block;
}
Firstly, wrap your image tag with a div. Name this div anything you want. Let's name it: "image-test".
<div class="image-test">
<img src="(URL for IMAGE)">
</div>
Next, let's say you want your table to take up 50% of the width and your image to take up the other 50%. We are also going to float these div elements so they are not in the flow of the document.
#menu{
float:left;
width:50%;
}
.image-test{
float:left;
width:50%;
}
You'll notice your image is larger than the containing div, so let's set a max width on all images to avoid future problems.
img {
max-width:100%;
}
I need to style a table to have rounded corners.
I'm just looking at how best to go about it:
Normally when I style a div to have rounded corners, I use 2 divs with empty comments at the top and bottom, and apply sizing & background image CSS to them.
The table, however, has internal borders, so I'd have to carefully align the vertical lines in the corner bg images, to match with the true cell borders.
Is this clear so
far?
So I was wondering how others would approach this. I think the best thing I can do is to just use one complete fixed size background image, borders and all, and overlay a borderless table on top. The table will always be the same size after all.
Can anyone think of a better way?
25 ways to do it.... http://www.cssjuice.com/25-rounded-corners-techniques-with-css/
Actually, there are too many ways to do it.
You better make a background image with just the corners, and not the borders.
Apply a class to the top left, top right, bottom left and bottom right cell, to define that the corners-background image should be used.
And style the borders with css. Don't put them in the background image.
In your approach, you'll always gonna end up having the vertical lines in your background image not match the borders of the actual table cells.
Have you tried http://www.roundedcornr.com/?
Do something like this...
XHTML: (sorry had to remove first '<' as it wouldn't let me post it normally, FIX THIS JEFF!)
table id="pricing" border="0" cellpadding="0" cellspacing="0">
<thead>
<tr>
<th>Incoming calls</th>
<th>National calls</th>
<th>Calls to US & Canada</th>
<th>Calls to other Phones</th>
<th>Calls to other Countries</th>
<th>SMS text messages</th>
</tr>
</thead>
<tbody>
<tr>
<td>Select</td>
<td>country</td>
<td>from</td>
<td>dropdown</td>
<td>list</td>
<td>above</td>
</tr>
</tbody>
</table>
CSS:
#pricing
{
font-weight:bold;
text-align:center
}
#pricing thead
{
background-image:url("images/pricing_top.gif");
background-position:top;
background-repeat:no-repeat;
padding:10px 0 0 /* replace 10px with the height of pricing_top.gif */
}
#pricing th
{
background-image:url("images/pricing_header_bg.gif");
background-repeat:repeat-y;
border-bottom:1px solid #c3c2c2;
width:100px /* replace 100px with the width of pricing_header_bg.gif */
}
#pricing tbody
{
background-image:url("images/pricing_bottom.gif");
background-position:bottom;
background-repeat:no-repeat;
padding:0 0 10px /* replace 10px with the height of pricing_bottom.gif */
}
#pricing td
{
background-image:url("images/pricing_cell_bg.gif");
background-repeat:repeat-y;
width:100px /* replace 100px with the width of pricing_cell_bg.gif */
}
Only drawback is that you have to create 4 images, but that shouldn't take too long. You'll also need to add a class to the final cell in each row if you want to add that drop shadow on the right and just change it's background-image and width property accordingly.
Playing off of your original idea, you could add a class to each corner cell effectively turning off their respective offending borders. You could then use a full-width background image in the <thead> and <tfoot> elements to account for the rounded corners.
The rest of the cells can have their borders turned on, and the lines will line up correctly.
The only remaining issue is accounting for that blasted drop shadow. That's a different exercise.
A better way would be a 9-grid where you have the background corners, and top, bottom, left and right backgrounds repeating
Your table goes in cell 5
Edit
As some posted in the comments you can not achieve the effect with a 9-grid.
You have to do a 12-grid-system (made up by me right now :)
Live demo
.
Code:
Warning: it's not pretty, but works
<html>
<head>
<style>
.cell1 {background: #f8f8f8 url(images/cell1.gif) no-repeat left top; height: 10px; font-size: 1px;}
.cell2 {background: #f8f8f8 url(images/cell2.gif) repeat-x top; height: 10px; font-size: 1px; border-right: solid 1px #c3c2c2; font-weight:bold; }
.cell3 {background: #f8f8f8 url(images/cell3.gif) no-repeat right top; height: 10px; font-size: 1px;}
.cell4 {background: white url(images/cell4.gif) repeat-y left; border-bottom: solid 1px #c3c2c2; width: 13px; }
.cell5 {background-color: #f8f8f8; padding: 5px; border-right: solid 1px #c3c2c2; font-weight:bold; border-bottom: solid 1px #c3c2c2; }
.cell6 {background: white url(images/cell6.gif) repeat-y right; border-bottom: solid 1px #c3c2c2; width: 18px; }
.cell7 {background: white url(images/cell7.gif) repeat-y left; width: 13px;}
.cell8 {background-color: white; padding: 5px; border-right: solid 1px #c3c2c2; font-weight:normal; }
.cell9 {background: white url(images/cell9.gif) repeat-y right; width: 18px;}
.cell10 {background: white url(images/cell10.gif) no-repeat left bottom; height: 17px;font-size: 1px; }
.cell11 {background: white url(images/cell11.gif) repeat-x bottom; border-right: solid 1px #c3c2c2; height: 17px; font-size: 1px; }
.cell12 {background: white url(images/cell12.gif) no-repeat right bottom; height: 17px;font-size: 1px; }
.lastcolumn, th.lastcolumn, td.lastcolumn {border-right: solid 0px #c3c2c2; }
</style>
</head>
<body>
<table id="pricing" border="0" cellpadding="0" cellspacing="0">
<thead>
<tr>
<th class="cell1"></th>
<th class="cell2"> </th>
<th class="cell2"> </th>
<th class="cell2"> </th>
<th class="cell2"> </th>
<th class="cell2"> </th>
<th class="cell2 lastcolumn"> </th>
<th class="cell3"></th>
</tr>
<tr>
<th class="cell4"> </th>
<th class="cell5">Incoming calls</th>
<th class="cell5">National calls</th>
<th class="cell5">Calls to US & Canada</th>
<th class="cell5">Calls to other Phones</th>
<th class="cell5">Calls to other Countries</th>
<th class="cell5 lastcolumn">SMS text messages</th>
<th class="cell6"> </th>
</tr>
</thead>
<tbody>
<tr>
<td class="cell7"></td>
<td class="cell8">Select</td>
<td class="cell8">country</td>
<td class="cell8">from</td>
<td class="cell8">dropdown</td>
<td class="cell8">list</td>
<td class="cell8 lastcolumn">above</td>
<td class="cell9"></td>
</tr>
<tr>
<td class="cell10"></td>
<td class="cell11"> </td>
<td class="cell11"> </td>
<td class="cell11"> </td>
<td class="cell11"> </td>
<td class="cell11"> </td>
<td class="cell11 lastcolumn"> </td>
<td class="cell12"></td>
</tr>
</tbody>
</table>
</body>
</html>
Note: there are some non-breaking spaces that SO strips from the code. Check out the living demo for more info
Enjoy!