Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Jakz ⚡
Jakz ⚡

Posted on

     

How to create a dialog interface in CSS

End Result

We want to create a dialog interface with multiple list item. First of all, let's build the list item first and wrap it with a div with a classdialog.

HTML

<div>    <ul>        <li>          <a href="#">Dashboard</a>        </li>        <li>            <a href="#">Sign out</a>        </li>    </ul></div>
Enter fullscreen modeExit fullscreen mode

Let's style the element with the CSS. Change the background colour and text colour.

CSS

    .dialog {        background-color: #1c3d5a;        border-radius: .25rem;        box-shadow: 0 2px 4px 0 rgba(0, 0, 0, .1);        margin-left: .5rem;        margin-right: .5rem;        width: 300px;        margin: 0 auto;    }
Enter fullscreen modeExit fullscreen mode

Progress

We should add some style into the list item. So, we want to change the colour into white and remove the bullet.

.dialog ul {        list-style: none;    padding: 0;    width: 100%;}.dialog li {        padding-top: 1rem;    padding-bottom: 1rem;    padding-left: 1rem;}.topNav-dropdown li a {    color: #fff;}
Enter fullscreen modeExit fullscreen mode

Progress

Seems good. Now, we need to add a little triangle at the bottom to make it looks it comes out from the bottom. Let's add another div with the classarrow inside the.dialog element and add some CSS to style the new element.

<div>    <ul>        <li>          <a href="#">Dashboard</a>        </li>        <li>            <a href="#">Sign out</a>        </li>    </ul>    <div></div></div>
Enter fullscreen modeExit fullscreen mode
.arrow {    width: 0;    height: 0;    border-left: 10px solid transparent;    border-right: 10px solid transparent;    border-top: 10px solid #1c3d5a;    position: relative;    top: .6rem;}
Enter fullscreen modeExit fullscreen mode

Progress

Hmm. Now we can see the little triangle at the bottom. We need to centre the position. Since, it's wrapped in one div (.dialog), let's align with the power of the flexbox. Add new rules in the.dialog class.

    .dialog {        background-color: #1c3d5a;        border-radius: .25rem;        box-shadow: 0 2px 4px 0 rgba(0, 0, 0, .1);        margin-left: .5rem;        margin-right: .5rem;        width: 300px;        margin: 0 auto;        display: flex;        flex-direction: column;        align-items: center;        justify-content: center;    }
Enter fullscreen modeExit fullscreen mode

Progress

Seems good. Let's add some animation to make it pop up. Create a new animation property in the CSS and assign it into.dialog class.

@keyframes popout {  from {    transform: scale(0);  }  to {    transform: scale(1);  }}@-webkit-keyframes popout {  from {    -webkit-transform: scale(0);  }  to {    -webkit-transform: scale(1);  }}    .dialog {        background-color: #1c3d5a;        border-radius: .25rem;        box-shadow: 0 2px 4px 0 rgba(0, 0, 0, .1);        margin-left: .5rem;        margin-right: .5rem;        width: 300px;        margin: 0 auto;        display: flex;        flex-direction: column;        align-items: center;        justify-content: center;      animation: popout 0.7s ease;    }
Enter fullscreen modeExit fullscreen mode

End Result

Hopefully, you enjoyed this little tutorial. If you want to grab a code, feel free to grab it on my CodePen.

Original submitted frommy blog

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

  • Joined

Trending onDEV CommunityHot

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp