Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Creating this in CSS

Featured Replies

Hi Guys,

 

Just wondering if this box style is easy to create using css/css3, and if so how is the best way to go about it?

 

Thanks.

post-15701-0-94628700-1309971156_thumb.jpg

Edited by Aaron

Sure, just use background images for the gradients and text in CSS. In CSS3 you can do all sorts of cool things with gradients and text etc. but its not fully implemented and it will probably take a lot of experimenting to get it right, hence not "easy".

  • Author

Thanks mantis :)Well this is what I have so far (10 minutes of so of messing about), I think i've cracked it without messing around with images. Just wonder if there is a way to clean this CSS up a bit lol.

 

 

<html>

<head>

<style type="text/css">

body{

background-color:#0093b3;

}

 

p.one

{

background-color: rgba(255, 255, 255, 0.2);

border:1px solid rgba(255, 255, 255, 0.5);

height:90px;

width:190px;

margin:auto;

padding:5px;

 

font-family:Georgia, "Times New Roman", Times, serif;

font-size:20px;

color:#FFF;

}

#outer-border {

padding-top:1px;

width:204px;

height:103px;

border:1px solid rgba(255, 255, 255, 0.8 );

 

}

 

 

 

</style>

</head>

 

<body>

<div id="outer-border"><p class="one">Text will be in here...</p></div>

</body>

</html>

Edited by Aaron

How many areas are going to have the same style as this?

 

Your best bet is to define a 'block' area and use a list element inside.

 

The XHTML would look something like this:

 

<div class="block">
<ul>
<li>Text</li>
<li>Text</li>
<li>Text</li>
</ul>
</div>

 

You would then define the block properties - background colour/image, border etc.

.block {
height:90px;
width:190px;
background-color: rgba(255, 255, 255, 0.2);
border:1px solid rgba(255, 255, 255, 0.5);
padding:5px;
}

 

Then define the list properties:

 

.block ul li {
font-size:20px;
color:#fff;
}

 

Also, don't define the font face so specifically, rather apply it more generically.

 

The idea here is to create re-usable CSS.

 

The cool thing about CSS is ... the cascade.

 

This can cut down massively on the amount of CSS you need to create, so learn to use it.

 

A simple example, you want exactly the same block, but this time, with a red background.

 

<div class="block red">
...
</div>

 

.block.red {
background-color: red;
}

 

This will take all the properties of your block style and overide the background.

  • Author

Thanks bb_matt,

 

There will be a few of these style types so your advice is golden!

 

I have been building up to learning this for a while as I spotted some of this ul/li stuff recently and only really used it for navigation bars. I will use this project I'm on with for experimenting with your advice as this would seriously cut down some of the workload that I associate with coding at the minute lol.

 

The client is quite laid back so that helps :)

No problem!

 

The trick is to simplify the xhtml markup down to it's most basic level and then try to work the CSS into that.

 

Get your basic layout done first - your 'blocks' - using the div element.

Also, get your overall text styles done as very basic css entries:

h1 {
  font-size:200%;
  color: #000000;
}

p {
  font-size: 100%;
  color: #666666;
}

 

The idea is to find all the stuff that is the same in your design, define it, then use the cascade to modify it:

 

.block h1 {
  color: red;
}

.block p {
  line-height:150%;
}

 

Also, my example of .block is not incredibly semantic - try to use descriptive names (within reason) for your css classes.

 

Or, alternatively, use descriptive names to extend those classes:

 


.block.contact p {
}

.block.application h1 {
}

  • Author

Haha! this is good stuff :D

 

looking forward to messing about with this. Just a couple of things,

 

percentages on font sizes? How will they act compared to using the 'px' command?

 

With the block styles, as you said before with being able to change the background to red if I want it to, does this apply to everything else, for example heights, widths, etc. Will that overide the style aswell?

 

Thanks

Yes, it applies to all styles - it's part of the cascade.

 

Fonts - they can be in em,px or %

The general consensus seems to be that percentages are the way to go, however, you need to understand that percentages are inherited from the parent element.

 

Here's a fairly old 'A List Apart' article, that's still relevant:

 

http://www.alistapart.com/articles/howtosizetextincss/

  • 2 weeks later...
  • Author

Yes, it applies to all styles - it's part of the cascade.

 

Fonts - they can be in em,px or %

The general consensus seems to be that percentages are the way to go, however, you need to understand that percentages are inherited from the parent element.

 

Here's a fairly old 'A List Apart' article, that's still relevant:

 

http://www.alistapart.com/articles/howtosizetextincss/

 

 

Hey, just messing about with list styles etc.

 

here

 

Just a question, why is there such a huge gap between the edge of the div and the text? I have been looking into setting this to my own desired value but to no avail.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.